virtualbox 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. data/.yardopts +0 -1
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/virtualbox/abstract_model/attributable.rb +1 -0
  5. data/lib/virtualbox/abstract_model/validatable.rb +133 -10
  6. data/lib/virtualbox/abstract_model.rb +3 -3
  7. data/lib/virtualbox/appliance.rb +5 -2
  8. data/lib/virtualbox/audio_adapter.rb +11 -3
  9. data/lib/virtualbox/bios.rb +10 -4
  10. data/lib/virtualbox/com/abstract_enum.rb +6 -5
  11. data/lib/virtualbox/com/abstract_implementer.rb +4 -2
  12. data/lib/virtualbox/com/abstract_interface.rb +6 -4
  13. data/lib/virtualbox/com/base_interface.rb +38 -0
  14. data/lib/virtualbox/com/ffi/interface.rb +14 -5
  15. data/lib/virtualbox/com/ffi/interfaces.rb +36 -32
  16. data/lib/virtualbox/com/ffi/util.rb +22 -4
  17. data/lib/virtualbox/com/ffi_interface.rb +39 -8
  18. data/lib/virtualbox/com/implementer/base.rb +2 -2
  19. data/lib/virtualbox/com/implementer/ffi.rb +55 -44
  20. data/lib/virtualbox/com/implementer/mscom.rb +2 -4
  21. data/lib/virtualbox/com/interface/3.1.x/appliance.rb +22 -0
  22. data/lib/virtualbox/com/interface/3.1.x/audio_adapter.rb +15 -0
  23. data/lib/virtualbox/com/interface/3.1.x/audio_controller_type.rb +11 -0
  24. data/lib/virtualbox/com/interface/3.1.x/audio_driver_type.rb +11 -0
  25. data/lib/virtualbox/com/interface/3.1.x/bios_boot_menu_mode.rb +11 -0
  26. data/lib/virtualbox/com/interface/3.1.x/bios_settings.rb +21 -0
  27. data/lib/virtualbox/com/interface/3.1.x/clipboard_mode.rb +11 -0
  28. data/lib/virtualbox/com/interface/3.1.x/console.rb +50 -0
  29. data/lib/virtualbox/com/interface/3.1.x/cpu_property_type.rb +11 -0
  30. data/lib/virtualbox/com/interface/3.1.x/device_type.rb +11 -0
  31. data/lib/virtualbox/com/interface/3.1.x/dhcp_server.rb +22 -0
  32. data/lib/virtualbox/com/interface/3.1.x/firmware_type.rb +11 -0
  33. data/lib/virtualbox/com/interface/3.1.x/guest_os_type.rb +23 -0
  34. data/lib/virtualbox/com/interface/3.1.x/host.rb +42 -0
  35. data/lib/virtualbox/com/interface/3.1.x/host_network_interface.rb +30 -0
  36. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_medium_type.rb +11 -0
  37. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_status.rb +11 -0
  38. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_type.rb +11 -0
  39. data/lib/virtualbox/com/interface/3.1.x/host_usb_device.rb +13 -0
  40. data/lib/virtualbox/com/interface/3.1.x/host_usb_device_filter.rb +13 -0
  41. data/lib/virtualbox/com/interface/3.1.x/hw_virt_ex_property_type.rb +11 -0
  42. data/lib/virtualbox/com/interface/3.1.x/machine.rb +105 -0
  43. data/lib/virtualbox/com/interface/3.1.x/machine_state.rb +14 -0
  44. data/lib/virtualbox/com/interface/3.1.x/medium.rb +50 -0
  45. data/lib/virtualbox/com/interface/3.1.x/medium_attachment.rb +18 -0
  46. data/lib/virtualbox/com/interface/3.1.x/medium_format.rb +18 -0
  47. data/lib/virtualbox/com/interface/3.1.x/medium_state.rb +11 -0
  48. data/lib/virtualbox/com/interface/3.1.x/medium_type.rb +11 -0
  49. data/lib/virtualbox/com/interface/3.1.x/medium_variant.rb +11 -0
  50. data/lib/virtualbox/com/interface/3.1.x/network_adapter.rb +30 -0
  51. data/lib/virtualbox/com/interface/3.1.x/network_adapter_type.rb +11 -0
  52. data/lib/virtualbox/com/interface/3.1.x/network_attachment_type.rb +11 -0
  53. data/lib/virtualbox/com/interface/3.1.x/nsiexception.rb +23 -0
  54. data/lib/virtualbox/com/interface/3.1.x/nsisupports.rb +15 -0
  55. data/lib/virtualbox/com/interface/3.1.x/parallel_port.rb +17 -0
  56. data/lib/virtualbox/com/interface/3.1.x/port_mode.rb +11 -0
  57. data/lib/virtualbox/com/interface/3.1.x/progress.rb +63 -0
  58. data/lib/virtualbox/com/interface/3.1.x/serial_port.rb +19 -0
  59. data/lib/virtualbox/com/interface/3.1.x/session.rb +18 -0
  60. data/lib/virtualbox/com/interface/3.1.x/session_state.rb +11 -0
  61. data/lib/virtualbox/com/interface/3.1.x/session_type.rb +11 -0
  62. data/lib/virtualbox/com/interface/3.1.x/shared_folder.rb +17 -0
  63. data/lib/virtualbox/com/interface/3.1.x/snapshot.rb +20 -0
  64. data/lib/virtualbox/com/interface/3.1.x/storage_bus.rb +11 -0
  65. data/lib/virtualbox/com/interface/3.1.x/storage_controller.rb +23 -0
  66. data/lib/virtualbox/com/interface/3.1.x/storage_controller_type.rb +11 -0
  67. data/lib/virtualbox/com/interface/3.1.x/system_properties.rb +37 -0
  68. data/lib/virtualbox/com/interface/3.1.x/usb_controller.rb +20 -0
  69. data/lib/virtualbox/com/interface/3.1.x/usb_device.rb +24 -0
  70. data/lib/virtualbox/com/interface/3.1.x/usb_device_filter.rb +23 -0
  71. data/lib/virtualbox/com/interface/3.1.x/usb_device_filter_action.rb +11 -0
  72. data/lib/virtualbox/com/interface/3.1.x/usb_device_state.rb +11 -0
  73. data/lib/virtualbox/com/interface/3.1.x/virtual_box_error_info.rb +17 -0
  74. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description.rb +19 -0
  75. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_type.rb +14 -0
  76. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_value_type.rb +11 -0
  77. data/lib/virtualbox/com/interface/3.1.x/virtualbox.rb +67 -0
  78. data/lib/virtualbox/com/interface/3.1.x/vrdp_auth_type.rb +11 -0
  79. data/lib/virtualbox/com/interface/3.1.x/vrdp_server.rb +19 -0
  80. data/lib/virtualbox/com/interface/3.2.x/appliance.rb +22 -0
  81. data/lib/virtualbox/com/interface/3.2.x/audio_adapter.rb +15 -0
  82. data/lib/virtualbox/com/interface/3.2.x/audio_controller_type.rb +11 -0
  83. data/lib/virtualbox/com/interface/3.2.x/audio_driver_type.rb +11 -0
  84. data/lib/virtualbox/com/interface/3.2.x/bios_boot_menu_mode.rb +11 -0
  85. data/lib/virtualbox/com/interface/3.2.x/bios_settings.rb +21 -0
  86. data/lib/virtualbox/com/interface/3.2.x/clipboard_mode.rb +11 -0
  87. data/lib/virtualbox/com/interface/3.2.x/console.rb +50 -0
  88. data/lib/virtualbox/com/interface/3.2.x/cpu_property_type.rb +11 -0
  89. data/lib/virtualbox/com/interface/3.2.x/device_type.rb +11 -0
  90. data/lib/virtualbox/com/interface/3.2.x/dhcp_server.rb +22 -0
  91. data/lib/virtualbox/com/interface/3.2.x/firmware_type.rb +11 -0
  92. data/lib/virtualbox/com/interface/3.2.x/guest.rb +13 -0
  93. data/lib/virtualbox/com/interface/3.2.x/guest_os_type.rb +33 -0
  94. data/lib/virtualbox/com/interface/3.2.x/host.rb +43 -0
  95. data/lib/virtualbox/com/interface/3.2.x/host_network_interface.rb +30 -0
  96. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_medium_type.rb +11 -0
  97. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_status.rb +11 -0
  98. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_type.rb +11 -0
  99. data/lib/virtualbox/com/interface/3.2.x/host_usb_device.rb +13 -0
  100. data/lib/virtualbox/com/interface/3.2.x/host_usb_device_filter.rb +13 -0
  101. data/lib/virtualbox/com/interface/3.2.x/hw_virt_ex_property_type.rb +11 -0
  102. data/lib/virtualbox/com/interface/3.2.x/keyboard_hid_type.rb +11 -0
  103. data/lib/virtualbox/com/interface/3.2.x/machine.rb +118 -0
  104. data/lib/virtualbox/com/interface/3.2.x/machine_state.rb +14 -0
  105. data/lib/virtualbox/com/interface/3.2.x/medium.rb +51 -0
  106. data/lib/virtualbox/com/interface/3.2.x/medium_attachment.rb +18 -0
  107. data/lib/virtualbox/com/interface/3.2.x/medium_format.rb +18 -0
  108. data/lib/virtualbox/com/interface/3.2.x/medium_state.rb +11 -0
  109. data/lib/virtualbox/com/interface/3.2.x/medium_type.rb +11 -0
  110. data/lib/virtualbox/com/interface/3.2.x/medium_variant.rb +11 -0
  111. data/lib/virtualbox/com/interface/3.2.x/nat_alias_mode.rb +11 -0
  112. data/lib/virtualbox/com/interface/3.2.x/nat_engine.rb +27 -0
  113. data/lib/virtualbox/com/interface/3.2.x/nat_protocol.rb +11 -0
  114. data/lib/virtualbox/com/interface/3.2.x/network_adapter.rb +34 -0
  115. data/lib/virtualbox/com/interface/3.2.x/network_adapter_type.rb +11 -0
  116. data/lib/virtualbox/com/interface/3.2.x/network_attachment_type.rb +11 -0
  117. data/lib/virtualbox/com/interface/3.2.x/nsiexception.rb +23 -0
  118. data/lib/virtualbox/com/interface/3.2.x/nsisupports.rb +15 -0
  119. data/lib/virtualbox/com/interface/3.2.x/parallel_port.rb +17 -0
  120. data/lib/virtualbox/com/interface/3.2.x/pointing_hid_type.rb +11 -0
  121. data/lib/virtualbox/com/interface/3.2.x/port_mode.rb +11 -0
  122. data/lib/virtualbox/com/interface/3.2.x/progress.rb +63 -0
  123. data/lib/virtualbox/com/interface/3.2.x/serial_port.rb +19 -0
  124. data/lib/virtualbox/com/interface/3.2.x/session.rb +18 -0
  125. data/lib/virtualbox/com/interface/3.2.x/session_state.rb +11 -0
  126. data/lib/virtualbox/com/interface/3.2.x/session_type.rb +11 -0
  127. data/lib/virtualbox/com/interface/3.2.x/shared_folder.rb +17 -0
  128. data/lib/virtualbox/com/interface/3.2.x/snapshot.rb +20 -0
  129. data/lib/virtualbox/com/interface/3.2.x/storage_bus.rb +11 -0
  130. data/lib/virtualbox/com/interface/3.2.x/storage_controller.rb +24 -0
  131. data/lib/virtualbox/com/interface/3.2.x/storage_controller_type.rb +11 -0
  132. data/lib/virtualbox/com/interface/3.2.x/system_properties.rb +42 -0
  133. data/lib/virtualbox/com/interface/3.2.x/usb_controller.rb +21 -0
  134. data/lib/virtualbox/com/interface/3.2.x/usb_device.rb +24 -0
  135. data/lib/virtualbox/com/interface/3.2.x/usb_device_filter.rb +23 -0
  136. data/lib/virtualbox/com/interface/3.2.x/usb_device_filter_action.rb +11 -0
  137. data/lib/virtualbox/com/interface/3.2.x/usb_device_state.rb +11 -0
  138. data/lib/virtualbox/com/interface/3.2.x/virtual_box_error_info.rb +17 -0
  139. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description.rb +19 -0
  140. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_type.rb +14 -0
  141. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_value_type.rb +11 -0
  142. data/lib/virtualbox/com/interface/3.2.x/virtualbox.rb +67 -0
  143. data/lib/virtualbox/com/interface/3.2.x/vrdp_auth_type.rb +11 -0
  144. data/lib/virtualbox/com/interface/3.2.x/vrdp_server.rb +21 -0
  145. data/lib/virtualbox/com/mscom_interface.rb +9 -4
  146. data/lib/virtualbox/com/nil_interface.rb +7 -0
  147. data/lib/virtualbox/com/util.rb +16 -2
  148. data/lib/virtualbox/com.rb +1 -1
  149. data/lib/virtualbox/cpu.rb +61 -0
  150. data/lib/virtualbox/dhcp_server.rb +89 -0
  151. data/lib/virtualbox/dvd.rb +2 -2
  152. data/lib/virtualbox/exceptions.rb +4 -0
  153. data/lib/virtualbox/ext/platform.rb +2 -2
  154. data/lib/virtualbox/extra_data.rb +5 -6
  155. data/lib/virtualbox/forwarded_port.rb +11 -7
  156. data/lib/virtualbox/global.rb +17 -6
  157. data/lib/virtualbox/hard_drive.rb +129 -66
  158. data/lib/virtualbox/host.rb +71 -0
  159. data/lib/virtualbox/host_network_interface.rb +137 -0
  160. data/lib/virtualbox/hw_virtualization.rb +12 -6
  161. data/lib/virtualbox/lib.rb +2 -2
  162. data/lib/virtualbox/media.rb +2 -2
  163. data/lib/virtualbox/medium.rb +10 -3
  164. data/lib/virtualbox/medium_attachment.rb +2 -2
  165. data/lib/virtualbox/network_adapter.rb +12 -4
  166. data/lib/virtualbox/proxies/collection.rb +26 -6
  167. data/lib/virtualbox/shared_folder.rb +22 -15
  168. data/lib/virtualbox/snapshot.rb +185 -0
  169. data/lib/virtualbox/storage_controller.rb +3 -3
  170. data/lib/virtualbox/system_properties.rb +1 -1
  171. data/lib/virtualbox/usb_controller.rb +8 -4
  172. data/lib/virtualbox/usb_device_filter.rb +74 -0
  173. data/lib/virtualbox/version.rb +12 -1
  174. data/lib/virtualbox/virtual_system_description.rb +4 -4
  175. data/lib/virtualbox/vm.rb +273 -64
  176. data/lib/virtualbox/vrdp_server.rb +59 -0
  177. data/test/test_helper.rb +7 -1
  178. data/test/virtualbox/abstract_model/attributable_test.rb +8 -0
  179. data/test/virtualbox/abstract_model/relatable_test.rb +5 -5
  180. data/test/virtualbox/abstract_model/validatable_test.rb +186 -3
  181. data/test/virtualbox/abstract_model_test.rb +3 -3
  182. data/test/virtualbox/appliance_test.rb +8 -1
  183. data/test/virtualbox/com/abstract_enum_test.rb +1 -0
  184. data/test/virtualbox/com/abstract_implementer_test.rb +4 -3
  185. data/test/virtualbox/com/abstract_interface_test.rb +3 -2
  186. data/test/virtualbox/com/ffi/interface_test.rb +4 -4
  187. data/test/virtualbox/com/ffi/util_test.rb +23 -1
  188. data/test/virtualbox/com/implementer/base_test.rb +4 -3
  189. data/test/virtualbox/com/implementer/ffi_test.rb +18 -10
  190. data/test/virtualbox/cpu_test.rb +103 -0
  191. data/test/virtualbox/dhcp_server_test.rb +165 -0
  192. data/test/virtualbox/extra_data_test.rb +4 -3
  193. data/test/virtualbox/forwarded_port_test.rb +17 -4
  194. data/test/virtualbox/hard_drive_test.rb +54 -5
  195. data/test/virtualbox/host_network_interface_test.rb +254 -0
  196. data/test/virtualbox/host_test.rb +94 -0
  197. data/test/virtualbox/network_adapter_test.rb +30 -1
  198. data/test/virtualbox/proxies/collection_test.rb +63 -21
  199. data/test/virtualbox/shared_folder_test.rb +16 -13
  200. data/test/virtualbox/snapshot_test.rb +231 -0
  201. data/test/virtualbox/storage_controller_test.rb +1 -1
  202. data/test/virtualbox/usb_controller_test.rb +7 -0
  203. data/test/virtualbox/usb_device_filter_test.rb +93 -0
  204. data/test/virtualbox/version_test.rb +13 -1
  205. data/test/virtualbox/vm_test.rb +245 -11
  206. data/test/virtualbox/vrdp_server_test.rb +83 -0
  207. data/virtualbox.gemspec +183 -97
  208. metadata +182 -96
  209. data/TODO +0 -9
  210. data/lib/virtualbox/com/interface/appliance.rb +0 -20
  211. data/lib/virtualbox/com/interface/audio_adapter.rb +0 -13
  212. data/lib/virtualbox/com/interface/audio_controller_type.rb +0 -9
  213. data/lib/virtualbox/com/interface/audio_driver_type.rb +0 -9
  214. data/lib/virtualbox/com/interface/bios_boot_menu_mode.rb +0 -9
  215. data/lib/virtualbox/com/interface/bios_settings.rb +0 -19
  216. data/lib/virtualbox/com/interface/clipboard_mode.rb +0 -9
  217. data/lib/virtualbox/com/interface/console.rb +0 -48
  218. data/lib/virtualbox/com/interface/cpu_property_type.rb +0 -9
  219. data/lib/virtualbox/com/interface/device_type.rb +0 -9
  220. data/lib/virtualbox/com/interface/dhcp_server.rb +0 -20
  221. data/lib/virtualbox/com/interface/firmware_type.rb +0 -9
  222. data/lib/virtualbox/com/interface/guest_os_type.rb +0 -21
  223. data/lib/virtualbox/com/interface/host.rb +0 -40
  224. data/lib/virtualbox/com/interface/host_network_interface.rb +0 -28
  225. data/lib/virtualbox/com/interface/host_network_interface_medium_type.rb +0 -9
  226. data/lib/virtualbox/com/interface/host_network_interface_status.rb +0 -9
  227. data/lib/virtualbox/com/interface/host_network_interface_type.rb +0 -9
  228. data/lib/virtualbox/com/interface/host_usb_device.rb +0 -11
  229. data/lib/virtualbox/com/interface/host_usb_device_filter.rb +0 -11
  230. data/lib/virtualbox/com/interface/hw_virt_ex_property_type.rb +0 -9
  231. data/lib/virtualbox/com/interface/machine.rb +0 -103
  232. data/lib/virtualbox/com/interface/machine_state.rb +0 -12
  233. data/lib/virtualbox/com/interface/medium.rb +0 -48
  234. data/lib/virtualbox/com/interface/medium_attachment.rb +0 -16
  235. data/lib/virtualbox/com/interface/medium_format.rb +0 -16
  236. data/lib/virtualbox/com/interface/medium_state.rb +0 -9
  237. data/lib/virtualbox/com/interface/medium_type.rb +0 -9
  238. data/lib/virtualbox/com/interface/medium_variant.rb +0 -9
  239. data/lib/virtualbox/com/interface/network_adapter.rb +0 -28
  240. data/lib/virtualbox/com/interface/network_adapter_type.rb +0 -9
  241. data/lib/virtualbox/com/interface/network_attachment_type.rb +0 -9
  242. data/lib/virtualbox/com/interface/nsiexception.rb +0 -21
  243. data/lib/virtualbox/com/interface/nsisupports.rb +0 -13
  244. data/lib/virtualbox/com/interface/parallel_port.rb +0 -15
  245. data/lib/virtualbox/com/interface/port_mode.rb +0 -9
  246. data/lib/virtualbox/com/interface/progress.rb +0 -58
  247. data/lib/virtualbox/com/interface/serial_port.rb +0 -17
  248. data/lib/virtualbox/com/interface/session.rb +0 -16
  249. data/lib/virtualbox/com/interface/session_state.rb +0 -9
  250. data/lib/virtualbox/com/interface/session_type.rb +0 -9
  251. data/lib/virtualbox/com/interface/shared_folder.rb +0 -15
  252. data/lib/virtualbox/com/interface/snapshot.rb +0 -18
  253. data/lib/virtualbox/com/interface/storage_bus.rb +0 -9
  254. data/lib/virtualbox/com/interface/storage_controller.rb +0 -21
  255. data/lib/virtualbox/com/interface/storage_controller_type.rb +0 -9
  256. data/lib/virtualbox/com/interface/system_properties.rb +0 -35
  257. data/lib/virtualbox/com/interface/usb_controller.rb +0 -18
  258. data/lib/virtualbox/com/interface/usb_device.rb +0 -22
  259. data/lib/virtualbox/com/interface/usb_device_filter.rb +0 -21
  260. data/lib/virtualbox/com/interface/usb_device_filter_action.rb +0 -9
  261. data/lib/virtualbox/com/interface/usb_device_state.rb +0 -9
  262. data/lib/virtualbox/com/interface/virtual_box_error_info.rb +0 -15
  263. data/lib/virtualbox/com/interface/virtual_system_description.rb +0 -17
  264. data/lib/virtualbox/com/interface/virtual_system_description_type.rb +0 -12
  265. data/lib/virtualbox/com/interface/virtual_system_description_value_type.rb +0 -9
  266. data/lib/virtualbox/com/interface/virtualbox.rb +0 -54
  267. data/lib/virtualbox/com/interface/vrdp_auth_type.rb +0 -9
  268. data/lib/virtualbox/com/interface/vrdp_server.rb +0 -17
data/lib/virtualbox/vm.rb CHANGED
@@ -16,10 +16,49 @@ module VirtualBox
16
16
  # objects. This is best shown through example:
17
17
  #
18
18
  # vm = VirtualBox::VM.find("MyWindowsXP")
19
- # vm.memory = 256
19
+ # vm.memory_size = 256
20
20
  # vm.name = "WindowsXP"
21
21
  # vm.save
22
22
  #
23
+ # # Controlling Virtual Machines
24
+ #
25
+ # Virtual machines can be controlled using the basic {#start}, {#stop}, etc.
26
+ # methods. The current state of the VM can also be retrieved via the {#state}
27
+ # method. An example of this use is shown below:
28
+ #
29
+ # if vm.powered_off?
30
+ # vm.start
31
+ # end
32
+ #
33
+ # # Taking a Snapshot
34
+ #
35
+ # Snapshots allow virtual machine states to be saved at a given point in time
36
+ # without having to stop the machine. This state can then be restored later.
37
+ # VirtualBox handles this by creating a differencing image which allows the hard
38
+ # drive to even retain its exact state. Taking a snapshot is extremely simple:
39
+ #
40
+ # vm = VirtualBox::VM.find("MyWindowsXP")
41
+ # vm.take_snapshot("My Snapshot", "A description of my snapshot")
42
+ #
43
+ # # Traversing Snapshots
44
+ #
45
+ # Snapshots are represented by a tree-like structure. There is a root snapshot
46
+ # and that snapshot has many children which may in turn have their own children.
47
+ # The easiest way to traverse this structure is to use the {#root_snapshot}
48
+ # VM method and traverse the structure like any tree structure:
49
+ #
50
+ # vm = VirtualBox::VM.find("MyWindowsXP")
51
+ # p vm.root_snapshot.children.length
52
+ #
53
+ # # Finding Snapshots
54
+ #
55
+ # While traversing the entire snapshot tree can be useful, it is often more
56
+ # useful to be able to simply find a snapshot by name. For this, use the
57
+ # {#find_snapshot} method:
58
+ #
59
+ # vm = VirtualBox::VM.find("MyWindowsXP")
60
+ # p vm.find_snapshot("PreSP3")
61
+ #
23
62
  # # Attributes and Relationships
24
63
  #
25
64
  # Properties of the virtual machine are exposed using standard ruby instance
@@ -39,40 +78,36 @@ module VirtualBox
39
78
  # This is copied directly from the class header, but lists all available
40
79
  # attributes. If you don't understand what this means, read {Attributable}.
41
80
  #
42
- # attribute :uuid, :readonly => true
81
+ # attribute :uuid, :readonly => true, :property => :id
43
82
  # attribute :name
44
- # attribute :ostype
45
- # attribute :description, :readonly => true
46
- # attribute :memory
47
- # attribute :vram
48
- # attribute :acpi
49
- # attribute :ioapic
50
- # attribute :cpus
51
- # attribute :synthcpu
52
- # attribute :pae
53
- # attribute :hwvirtex
54
- # attribute :hwvirtexexcl
55
- # attribute :nestedpaging
56
- # attribute :vtxvpid
57
- # attribute :accelerate3d
58
- # attribute :accelerate2dvideo
59
- # attribute :biosbootmenu, :populate_key => :bootmenu
60
- # attribute :boot1
61
- # attribute :boot2
62
- # attribute :boot3
63
- # attribute :boot4
64
- # attribute :clipboard
65
- # attribute :monitorcount
66
- # attribute :usb
67
- # attribute :ehci
68
- # attribute :audio
69
- # attribute :audiocontroller
70
- # attribute :audiodriver
71
- # attribute :vrdp
72
- # attribute :vrdpport
73
- # attribute :vrdpauthtype
74
- # attribute :vrdpauthtimeout
75
- # attribute :state, :populate_key => :vmstate, :readonly => true
83
+ # attribute :os_type_id
84
+ # attribute :description
85
+ # attribute :memory_size
86
+ # attribute :memory_balloon_size
87
+ # attribute :vram_size
88
+ # attribute :cpu_count
89
+ # attribute :accelerate_3d_enabled, :boolean => true
90
+ # attribute :accelerate_2d_video_enabled, :boolean => true
91
+ # attribute :clipboard_mode
92
+ # attribute :monitor_count
93
+ # attribute :state, :readonly => true
94
+ # attribute :accessible, :readonly => true, :boolean => true
95
+ # attribute :hardware_version
96
+ # attribute :hardware_uuid
97
+ # attribute :firmware_type
98
+ # attribute :snapshot_folder
99
+ # attribute :settings_file_path, :readonly => true
100
+ # attribute :last_state_change, :readonly => true
101
+ # attribute :state_file_path, :readonly => true
102
+ # attribute :log_folder, :readonly => true
103
+ # attribute :snapshot_count, :readonly => true
104
+ # attribute :current_state_modified, :readonly => true
105
+ # attribute :guest_property_notification_patterns
106
+ # attribute :teleporter_enabled, :boolean => true
107
+ # attribute :teleporter_port
108
+ # attribute :teleporter_address
109
+ # attribute :teleporter_password
110
+ # attribute :interface, :readonly => true, :property => false
76
111
  #
77
112
  # ## Relationships
78
113
  #
@@ -80,31 +115,39 @@ module VirtualBox
80
115
  # to other things. The relationships are listed below. If you don't
81
116
  # understand this, read {Relatable}.
82
117
  #
83
- # relationship :nics, Nic
84
- # relationship :usbs, USB
85
- # relationship :storage_controllers, StorageController, :dependent => :destroy
86
- # relationship :shared_folders, SharedFolder
87
- # relationship :extra_data, ExtraData
88
- # relationship :forwarded_ports, ForwardedPort
118
+ # relationship :audio_adapter, :AudioAdapter
119
+ # relationship :bios, :BIOS
120
+ # relationship :hw_virt, :HWVirtualization
121
+ # relationship :cpu, :CPU
122
+ # relationship :vrdp_server, :VRDPServer
123
+ # relationship :storage_controllers, :StorageController, :dependent => :destroy
124
+ # relationship :medium_attachments, :MediumAttachment
125
+ # relationship :shared_folders, :SharedFolder
126
+ # relationship :extra_data, :ExtraData
127
+ # relationship :forwarded_ports, :ForwardedPort
128
+ # relationship :network_adapters, :NetworkAdapter
129
+ # relationship :usb_controller, :USBController
130
+ # relationship :current_snapshot, :Snapshot
89
131
  #
90
132
  class VM < AbstractModel
91
133
  attribute :uuid, :readonly => true, :property => :id
92
134
  attribute :name
93
135
  attribute :os_type_id
94
- attribute :description, :readonly => true
136
+ attribute :description
95
137
  attribute :memory_size
96
138
  attribute :memory_balloon_size
97
139
  attribute :vram_size
98
140
  attribute :cpu_count
99
- attribute :accelerate_3d_enabled
100
- attribute :accelerate_2d_video_enabled
141
+ attribute :accelerate_3d_enabled, :boolean => true
142
+ attribute :accelerate_2d_video_enabled, :boolean => true
101
143
  attribute :clipboard_mode
102
144
  attribute :monitor_count
103
145
  attribute :state, :readonly => true
104
- attribute :accessible, :readonly => true
146
+ attribute :accessible, :readonly => true, :boolean => true
105
147
  attribute :hardware_version
106
148
  attribute :hardware_uuid
107
- attribute :statistics_update_interval
149
+ # TODO: Removed in 3.2.x, how should we handle this?
150
+ # attribute :statistics_update_interval
108
151
  attribute :firmware_type
109
152
  attribute :snapshot_folder
110
153
  attribute :settings_file_path, :readonly => true
@@ -114,14 +157,19 @@ module VirtualBox
114
157
  attribute :snapshot_count, :readonly => true
115
158
  attribute :current_state_modified, :readonly => true
116
159
  attribute :guest_property_notification_patterns
117
- attribute :teleporter_enabled
160
+ attribute :teleporter_enabled, :boolean => true
118
161
  attribute :teleporter_port
119
162
  attribute :teleporter_address
120
163
  attribute :teleporter_password
164
+ attribute :boot_order,
165
+ :property_getter => Proc.new { |instance, *args| instance.get_boot_order(*args) },
166
+ :property_setter => Proc.new { |instance, *args| instance.set_boot_order(*args) }
121
167
  attribute :interface, :readonly => true, :property => false
122
168
  relationship :audio_adapter, :AudioAdapter
123
169
  relationship :bios, :BIOS
124
170
  relationship :hw_virt, :HWVirtualization
171
+ relationship :cpu, :CPU
172
+ relationship :vrdp_server, :VRDPServer
125
173
  relationship :storage_controllers, :StorageController, :dependent => :destroy
126
174
  relationship :medium_attachments, :MediumAttachment
127
175
  relationship :shared_folders, :SharedFolder
@@ -129,8 +177,9 @@ module VirtualBox
129
177
  relationship :forwarded_ports, :ForwardedPort
130
178
  relationship :network_adapters, :NetworkAdapter
131
179
  relationship :usb_controller, :USBController
180
+ relationship :current_snapshot, :Snapshot
132
181
 
133
- class <<self
182
+ class << self
134
183
  # Returns an array of all available VMs.
135
184
  #
136
185
  # @return [Array<VM>]
@@ -155,7 +204,7 @@ module VirtualBox
155
204
  # the first virtual machine will be returned, although all will
156
205
  # be imported.
157
206
  #
158
- # If a block is given, it will be yielded with the percent of the
207
+ # If a block is given, it will be yielded with the progress of the
159
208
  # import operation, so that the progress of the import can be
160
209
  # tracked.
161
210
  #
@@ -168,6 +217,14 @@ module VirtualBox
168
217
  end
169
218
 
170
219
  def populate_relationship(caller, machines)
220
+ machines.is_a?(Array) ? populate_array_relationship(caller, machines) : populate_single_relationship(caller, machines)
221
+ end
222
+
223
+ def populate_single_relationship(caller, machine)
224
+ new(machine)
225
+ end
226
+
227
+ def populate_array_relationship(caller, machines)
171
228
  result = Proxies::Collection.new(caller)
172
229
 
173
230
  machines.each do |machine|
@@ -206,6 +263,14 @@ module VirtualBox
206
263
  existing_record!
207
264
  end
208
265
 
266
+ # Reload the model so that all the attributes and relationships are
267
+ # up to date. This method will automatically discard any changes to
268
+ # the VM and any of its relationships.
269
+ def reload
270
+ initialize_attributes(interface)
271
+ self
272
+ end
273
+
209
274
  # State of the virtual machine. Returns the state of the virtual
210
275
  # machine. This state will represent the state that was assigned
211
276
  # when the VM was found unless `reload` is set to `true`.
@@ -213,30 +278,101 @@ module VirtualBox
213
278
  # @param [Boolean] reload If true, will reload the state to current
214
279
  # value.
215
280
  # @return [String] Virtual machine state.
216
- def state(reload=false)
217
- if reload
218
- load_interface_attribute(:state)
281
+ def state(suppress_state_reload=false)
282
+ if !suppress_state_reload
283
+ load_interface_attribute(:state, interface)
219
284
  clear_dirty!(:state)
220
285
  end
221
286
 
222
287
  read_attribute(:state)
223
288
  end
224
289
 
290
+ # Validates the virtual machine
291
+ def validate
292
+ super
293
+
294
+ validates_presence_of :name, :os_type_id, :memory_size, :vram_size, :cpu_count
295
+ validates_numericality_of :memory_balloon_size, :monitor_count
296
+ validates_inclusion_of :accelerate_3d_enabled, :accelerate_2d_video_enabled, :teleporter_enabled, :in => [true, false]
297
+
298
+ validates_format_of :name, :with => /^[\w\d\s-]+$/, :message => 'must only contain letters, numbers, spaces, underscores, and dashes.'
299
+
300
+ if !errors_on(:name)
301
+ # Only validate the name if the name has no errors already
302
+ vms_of_same_name = self.class.find(name)
303
+ add_error(:name, 'must not be used by another virtual machine.') if vms_of_same_name && vms_of_same_name.uuid != uuid
304
+ end
305
+
306
+ validates_inclusion_of :os_type_id, :in => VirtualBox::Global.global.lib.virtualbox.guest_os_types.collect { |os| os.id }
307
+
308
+ min_guest_ram, max_guest_ram = Global.global.system_properties.min_guest_ram, Global.global.system_properties.max_guest_ram
309
+ validates_inclusion_of :memory_size, :in => (min_guest_ram..max_guest_ram), :message => "must be between #{min_guest_ram} and #{max_guest_ram}."
310
+ validates_inclusion_of :memory_balloon_size, :in => (0..max_guest_ram), :message => "must be between 0 and #{max_guest_ram}."
311
+
312
+ min_guest_vram, max_guest_vram = Global.global.system_properties.min_guest_vram, Global.global.system_properties.max_guest_vram
313
+ validates_inclusion_of :vram_size, :in => (min_guest_vram..max_guest_vram), :message => "must be between #{min_guest_vram} and #{max_guest_vram}."
314
+
315
+ min_guest_cpu_count, max_guest_cpu_count = Global.global.system_properties.min_guest_cpu_count, Global.global.system_properties.max_guest_cpu_count
316
+ validates_inclusion_of :cpu_count, :in => (min_guest_cpu_count..max_guest_cpu_count), :message => "must be between #{min_guest_cpu_count} and #{max_guest_cpu_count}."
317
+
318
+ validates_inclusion_of :clipboard_mode, :in => COM::Util.versioned_interface(:ClipboardMode).map
319
+ validates_inclusion_of :firmware_type, :in => COM::Util.versioned_interface(:FirmwareType).map
320
+ end
321
+
225
322
  # Saves the virtual machine if modified. This method saves any modified
226
323
  # attributes of the virtual machine. If any related attributes were saved
227
324
  # as well (such as storage controllers), those will be saved, too.
228
325
  def save
326
+ return false unless valid?
327
+ raise Exceptions::ReadonlyVMStateException.new("VM must not be in saved state to modify.") if saved?
328
+
229
329
  with_open_session do |session|
230
330
  # Use setters to save the attributes on the locked machine and persist
231
331
  # the settings
232
332
  machine = session.machine
233
333
 
334
+ # Save the boot order
335
+ save_interface_attribute(:boot_order, machine)
336
+
234
337
  # Save all the attributes and relationships
235
338
  save_changed_interface_attributes(machine)
236
339
 
237
340
  # Save relationships, which may open their own sessions if necessary
238
341
  save_relationships
239
342
  end
343
+
344
+ true
345
+ end
346
+
347
+ # Returns the root snapshot of this virtual machine. This root snapshot
348
+ # can be used to traverse the tree of snapshots.
349
+ #
350
+ # @return [Snapshot]
351
+ def root_snapshot
352
+ return nil if current_snapshot.nil?
353
+
354
+ current = current_snapshot
355
+ current = current.parent while current.parent != nil
356
+ current
357
+ end
358
+
359
+ # Find a snapshot by name or UUID. This allows you to find a snapshot by a given
360
+ # name, rather than having to resort to traversing the entire tree structure
361
+ # manually.
362
+ def find_snapshot(name)
363
+ find_helper = lambda do |name, root|
364
+ return nil if root.nil?
365
+ return root if root.name == name || root.uuid == name
366
+
367
+ root.children.each do |child|
368
+ result = find_helper.call(name, child)
369
+ return result unless result.nil?
370
+ end
371
+
372
+ nil
373
+ end
374
+
375
+ find_helper.call(name, root_snapshot)
240
376
  end
241
377
 
242
378
  # Opens a direct session with the machine this VM represents and yields
@@ -263,12 +399,23 @@ module VirtualBox
263
399
 
264
400
  # Close the session
265
401
  if close_session
266
- # Save these settings only if we're closing
267
- session.machine.save_settings
402
+ # Save these settings only if we're closing and only if the state
403
+ # is not saved, since that doesn't allow the machine to be saved.
404
+ session.machine.save_settings if session.machine.state != :saved
268
405
 
269
406
  # Close the session
270
407
  session.close
271
408
  end
409
+ rescue Exception
410
+ # Close the session so we don't get locked out. We use a rescue block
411
+ # here instead of an "ensure" since we ONLY want this to occur if an
412
+ # exception is raised. Otherwise, we may or may not close the session,
413
+ # depending how deeply nested this call to `with_open_session` is.
414
+ # (see close_session boolean above)
415
+ session.close if session.state == :open
416
+
417
+ # Reraise the exception, we're not actually catching it to handle it
418
+ raise
272
419
  end
273
420
 
274
421
  # Exports a virtual machine. The virtual machine will be exported
@@ -284,18 +431,33 @@ module VirtualBox
284
431
  # 60 to 90 seconds on my 2.2 GHz 2009 model MacBook Pro.
285
432
  #
286
433
  # If a block is given to the method, then it will be yielded with the
287
- # percent progress of the operation (in intervals of 1 percent).
434
+ # progress of the operation.
288
435
  #
289
436
  # @param [String] filename The file (not directory) to save the exported
290
437
  # OVF file. This directory will also receive the checksum file and
291
438
  # virtual disks.
292
- def export(filename, &block)
439
+ def export(filename, options = {}, &block)
293
440
  app = Appliance.new
294
441
  app.path = filename
295
- app.add_machine(self)
442
+ app.add_machine(self, options)
296
443
  app.export(&block)
297
444
  end
298
445
 
446
+ # Take a snapshot of the current state of the machine. This method can be
447
+ # called while the VM is running and also while it is powered off. This
448
+ # method will block while the snapshot is being taken.
449
+ #
450
+ # If a block is given to this method, it will yield with a progress
451
+ # object which can be used to get the progress of the operation.
452
+ #
453
+ # @param [String] name Name of the snapshot.
454
+ # @param [String] description Description of the snapshot.
455
+ def take_snapshot(name, description="", &block)
456
+ with_open_session do |session|
457
+ session.console.take_snapshot(name, description).wait(&block)
458
+ end
459
+ end
460
+
299
461
  # Starts the virtual machine. The virtual machine can be started in a
300
462
  # variety of modes:
301
463
  #
@@ -314,11 +476,10 @@ module VirtualBox
314
476
  # as well
315
477
  session = Lib.lib.session
316
478
  interface.parent.open_remote_session(session, uuid, mode.to_s, "").wait_for_completion(-1)
317
-
318
- # Close our session to release our lock from the machine
319
- session.close
320
-
321
479
  true
480
+ ensure
481
+ # Be sure to close that session!
482
+ session.close if session && session.state == :open
322
483
  end
323
484
 
324
485
  # Shuts down the VM by directly calling "acpipowerbutton". Depending on the
@@ -385,10 +546,10 @@ module VirtualBox
385
546
 
386
547
  # Send the proper command, waiting if we have to
387
548
  result = session.console.send(command, *args)
388
- result.wait_for_completion(-1) if result.is_a?(COM::Interface::Progress)
389
-
549
+ result.wait_for_completion(-1) if result.is_a?(COM::Util.versioned_interface(:Progress))
550
+ ensure
390
551
  # Close the session
391
- session.close
552
+ session.close if session && session.state == :open
392
553
  end
393
554
 
394
555
  # Destroys the virtual machine. This method also removes all attached
@@ -403,6 +564,23 @@ module VirtualBox
403
564
  # not only unregister attached media, but will also physically
404
565
  # remove their respective data.
405
566
  def destroy(*args)
567
+ # Destroy all snapshots first (by destroying the root, all children
568
+ # are automatically destroyed)
569
+ if root_snapshot
570
+ destroy_snapshot = lambda do |snapshot|
571
+ return if snapshot.nil?
572
+
573
+ snapshot.children.each { |c| destroy_snapshot.call(c) }
574
+ snapshot.destroy
575
+ end
576
+
577
+ destroy_snapshot.call(root_snapshot)
578
+
579
+ # Reload ourselves before continuing since snapshots do some
580
+ # crazy things.
581
+ reload
582
+ end
583
+
406
584
  # Call super first so destroy is propogated through to relationships
407
585
  # first
408
586
  super
@@ -412,6 +590,13 @@ module VirtualBox
412
590
  interface.delete_settings
413
591
  end
414
592
 
593
+ # Returns true if the virtual machine state is starting
594
+ #
595
+ # @return [Boolean] True if virtual machine state is starting
596
+ def starting?
597
+ state == :starting
598
+ end
599
+
415
600
  # Returns true if the virtual machine state is running
416
601
  #
417
602
  # @return [Boolean] True if virtual machine state is running
@@ -446,5 +631,29 @@ module VirtualBox
446
631
  def aborted?
447
632
  state == :aborted
448
633
  end
634
+
635
+ # Loads the boot order for this virtual machine. This method should
636
+ # never be called directly. Instead, use the `boot_order` attribute
637
+ # to read and modify the boot order.
638
+ def get_boot_order(interface, key)
639
+ max_boot = Global.global.system_properties.max_boot_position
640
+
641
+ (1..max_boot).inject([]) do |order, position|
642
+ order << interface.get_boot_order(position)
643
+ order
644
+ end
645
+ end
646
+
647
+ # Sets the boot order for this virtual machine. This method should
648
+ # never be called directly. Instead, modify the `boot_order` array.
649
+ def set_boot_order(interface, key, value)
650
+ max_boot = Global.global.system_properties.max_boot_position
651
+ value = value.dup
652
+ value.concat(Array.new(max_boot - value.size)) if value.size < max_boot
653
+
654
+ (1..max_boot).each do |position|
655
+ interface.set_boot_order(position, value[position - 1])
656
+ end
657
+ end
449
658
  end
450
- end
659
+ end
@@ -0,0 +1,59 @@
1
+ module VirtualBox
2
+ # Represents the VRDP Server settings of a {VM}.
3
+ class VRDPServer < AbstractModel
4
+ attribute :parent, :readonly => true, :property => false
5
+ attribute :enabled, :boolean => true
6
+ attribute :ports
7
+ attribute :net_address
8
+ attribute :auth_type
9
+ attribute :auth_timeout
10
+ attribute :allow_multi_connection, :boolean => true
11
+ attribute :reuse_single_connection, :boolean => true
12
+
13
+ class << self
14
+ # Populates a relationship with another model.
15
+ #
16
+ # **This method typically won't be used except internally.**
17
+ #
18
+ # @return [VRDPServer]
19
+ def populate_relationship(caller, imachine)
20
+ data = new(caller, imachine.vrdp_server)
21
+ end
22
+
23
+ # Saves the relationship.
24
+ #
25
+ # **This method typically won't be used except internally.**
26
+ def save_relationship(caller, instance)
27
+ instance.save
28
+ end
29
+ end
30
+
31
+ def initialize(parent, vrdp_settings)
32
+ write_attribute(:parent, parent)
33
+
34
+ # Load the attributes and mark the whole thing as existing
35
+ load_interface_attributes(vrdp_settings)
36
+ clear_dirty!
37
+ existing_record!
38
+ end
39
+
40
+ def validate
41
+ super
42
+
43
+ validates_inclusion_of :enabled, :allow_multi_connection, :reuse_single_connection, :in => [true, false]
44
+ validates_format_of :ports, :with => /^[\d\s\-\.]+$/, :message => "must only contain numbers, spaces, dashes or periods."
45
+ validates_format_of :net_address, :with => /^[\w\d\-\.]+$/, :message => "must only contain latters, numbers, dashes or periods."
46
+ validates_inclusion_of :auth_type, :in => COM::Util.versioned_interface(:VRDPAuthType).map
47
+ validates_numericality_of :auth_timeout
48
+ end
49
+
50
+ def save
51
+ parent.with_open_session do |session|
52
+ machine = session.machine
53
+
54
+ # Save them
55
+ save_changed_interface_attributes(machine.vrdp_server)
56
+ end
57
+ end
58
+ end
59
+ end
data/test/test_helper.rb CHANGED
@@ -18,4 +18,10 @@ require File.join(File.dirname(__FILE__), '..', 'lib', 'virtualbox')
18
18
 
19
19
  # Data
20
20
  class Test::Unit::TestCase
21
- end
21
+ end
22
+
23
+ # Initialize the FFI stuff. This is typically done dynamically when
24
+ # FFI is initialized (on non-windows machines). Since the tests test
25
+ # the FFI classes, we force initialize a specific version here. It
26
+ # doesn't matter what version, since no actual FFI calls are made.
27
+ VirtualBox::COM::FFI.setup("3.1.x") unless defined?(VirtualBox::COM::FFI::Version_3_1_X)
@@ -8,6 +8,7 @@ class AttributableTest < Test::Unit::TestCase
8
8
  class AttributeModel < EmptyAttributeModel
9
9
  attribute :foo
10
10
  attribute :bar
11
+ attribute :boolean_bar, :boolean => true
11
12
 
12
13
  def initialize
13
14
  super
@@ -211,6 +212,13 @@ class AttributableTest < Test::Unit::TestCase
211
212
  assert atts.has_key?(:bar)
212
213
  end
213
214
 
215
+ should "be able to access boolean values with a '?'" do
216
+ @model.boolean_bar = true
217
+ assert @model.boolean_bar?
218
+ @model.boolean_bar = false
219
+ assert !@model.boolean_bar?
220
+ end
221
+
214
222
  should "be able to write defined attributes" do
215
223
  assert_nothing_raised {
216
224
  @model.foo = @check_string
@@ -17,8 +17,8 @@ class RelatableTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  class RelatableModel < EmptyRelatableModel
20
- relationship :foos, Relatee
21
- relationship :bars, BarRelatee
20
+ relationship :foos, RelatableTest::Relatee
21
+ relationship :bars, RelatableTest::BarRelatee
22
22
  end
23
23
 
24
24
  setup do
@@ -246,8 +246,8 @@ class RelatableTest < Test::Unit::TestCase
246
246
 
247
247
  context "determining the class of relationships" do
248
248
  class ClassRelatableModel < EmptyRelatableModel
249
- relationship :foo, Relatee
250
- relationship :bar, "RelatableTest::Relatee"
249
+ relationship :foo, RelatableTest::Relatee
250
+ relationship :bar, "RelatableTest::BarRelatee"
251
251
  end
252
252
 
253
253
  setup do
@@ -259,7 +259,7 @@ class RelatableTest < Test::Unit::TestCase
259
259
  end
260
260
 
261
261
  should "turn string into class" do
262
- assert_equal Relatee, @model.relationship_class(:bar)
262
+ assert_equal BarRelatee, @model.relationship_class(:bar)
263
263
  end
264
264
  end
265
265