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
@@ -5,13 +5,15 @@ module VirtualBox
5
5
  class Medium < AbstractModel
6
6
  include SubclassListing
7
7
 
8
- attribute :uuid, :readonly => :true, :property => :id
8
+ attribute :uuid, :readonly => true, :property => :id
9
+ attribute :type, :readonly => true
9
10
  attribute :description, :readonly => true
10
11
  attribute :location, :readonly => true
11
12
  attribute :state, :readonly => true, :property => :refresh_state
12
13
  attribute :interface, :readonly => true, :property => false
14
+ relationship :children, :Medium, :lazy => true
13
15
 
14
- class <<self
16
+ class << self
15
17
  # Populates a relationship with another model. Depending on the data sent
16
18
  # through as the `media` parameter, this can either return a single value
17
19
  # or an array of values. {Global}, for example, has a relationship of media,
@@ -106,6 +108,11 @@ module VirtualBox
106
108
  existing_record!
107
109
  end
108
110
 
111
+ def load_relationship(name)
112
+ # Populate children
113
+ populate_relationship(name, interface.children)
114
+ end
115
+
109
116
  # Returns the basename of the images location (the file name +extension)
110
117
  #
111
118
  # @return [String]
@@ -135,4 +142,4 @@ module VirtualBox
135
142
  interface.delete_storage.wait_for_completion(-1)
136
143
  end
137
144
  end
138
- end
145
+ end
@@ -11,7 +11,7 @@ module VirtualBox
11
11
  relationship :medium, :Medium
12
12
  relationship :storage_controller, :StorageController
13
13
 
14
- class <<self
14
+ class << self
15
15
  # Populates a relationship with another model.
16
16
  #
17
17
  # **This method typically won't be used except internally.**
@@ -58,4 +58,4 @@ module VirtualBox
58
58
  medium.destroy(opts[:destroy_medium] == :delete) if opts[:destroy_medium] && medium
59
59
  end
60
60
  end
61
- end
61
+ end
@@ -35,17 +35,17 @@ module VirtualBox
35
35
  class NetworkAdapter < AbstractModel
36
36
  attribute :parent, :readonly => true, :property => false
37
37
  attribute :slot, :readonly => true
38
- attribute :enabled
38
+ attribute :enabled, :boolean => true
39
39
  attribute :attachment_type
40
40
  attribute :adapter_type
41
41
  attribute :mac_address
42
- attribute :cable_connected
42
+ attribute :cable_connected, :boolean => true
43
43
  attribute :nat_network
44
44
  attribute :internal_network
45
45
  attribute :host_interface
46
46
  attribute :interface, :readonly => true, :property => false
47
47
 
48
- class <<self
48
+ class << self
49
49
  # Populates the nic relationship for anything which is related to it.
50
50
  #
51
51
  # **This method typically won't be used except internally.**
@@ -98,6 +98,14 @@ module VirtualBox
98
98
  existing_record!
99
99
  end
100
100
 
101
+ # Gets the host interface object associated with the class if it
102
+ # exists.
103
+ def host_interface_object
104
+ VirtualBox::Global.global.host.network_interfaces.find do |ni|
105
+ ni.name == host_interface
106
+ end
107
+ end
108
+
101
109
  # Save a network adapter.
102
110
  def save
103
111
  modify_adapter do |adapter|
@@ -131,4 +139,4 @@ module VirtualBox
131
139
  end
132
140
  end
133
141
  end
134
- end
142
+ end
@@ -3,14 +3,34 @@ module VirtualBox
3
3
  # A relationship which can be described as a collection, which
4
4
  # is a set of items.
5
5
  class Collection < Array
6
- def initialize(parent)
6
+ attr_reader :parent
7
+
8
+ def initialize(parent, item_klass=nil, *args)
7
9
  super()
8
10
 
9
11
  @parent = parent
12
+ @item_klass = item_klass
13
+ @other = args
14
+ end
15
+
16
+ # Creates a new item for this collection and returns the
17
+ # instance. The item is automatically put into this
18
+ # collection. `create` happens immediately, meaning that even
19
+ # without a `save`, the item will already exist.
20
+ def create(*args)
21
+ item = nil
22
+
23
+ if @item_klass.respond_to?(:create)
24
+ args = @other + args
25
+ item = @item_klass.create(self, *args)
26
+ self << item
27
+ end
28
+
29
+ item
10
30
  end
11
31
 
12
32
  def <<(item)
13
- item.added_to_relationship(@parent) if item.respond_to?(:added_to_relationship)
33
+ item.added_to_relationship(self) if item.respond_to?(:added_to_relationship)
14
34
  push(item)
15
35
  end
16
36
 
@@ -20,10 +40,10 @@ module VirtualBox
20
40
  end
21
41
  end
22
42
 
23
- def delete(item)
24
- return unless super
25
- item.removed_from_relationship(@parent) if item.respond_to?(:removed_from_relationship)
43
+ def delete(item, no_callback=false)
44
+ return unless super(item)
45
+ item.removed_from_relationship(self) if !no_callback && item.respond_to?(:removed_from_relationship)
26
46
  end
27
47
  end
28
48
  end
29
- end
49
+ end
@@ -86,12 +86,13 @@ module VirtualBox
86
86
  #
87
87
  class SharedFolder < AbstractModel
88
88
  attribute :parent, :readonly => true, :property => false
89
+ attribute :parent_collection, :readonly => true, :property => false
89
90
  attribute :name
90
91
  attribute :host_path
91
- attribute :writable, :default => true
92
- attribute :accessible, :readonly => true
92
+ attribute :writable, :default => true, :boolean => true
93
+ attribute :accessible, :readonly => true, :boolean => true
93
94
 
94
- class <<self
95
+ class << self
95
96
  # Populates the shared folder relationship for anything which is related to it.
96
97
  #
97
98
  # **This method typically won't be used except internally.**
@@ -101,7 +102,7 @@ module VirtualBox
101
102
  relation = Proxies::Collection.new(caller)
102
103
 
103
104
  imachine.shared_folders.each do |ishared|
104
- relation << new(caller, ishared)
105
+ relation << new(ishared)
105
106
  end
106
107
 
107
108
  relation
@@ -123,25 +124,22 @@ module VirtualBox
123
124
  # should be attached to a VM and saved.
124
125
  # @param [Hash] data (optional) A hash which contains initial attribute
125
126
  # values for the SharedFolder.
126
- # @overload initialize(index, caller, data)
127
+ # @overload initialize(interface)
127
128
  # Creates an SharedFolder for a relationship. **This should
128
129
  # never be called except internally.**
129
130
  # @param [Object] caller The parent
130
131
  # @param [Hash] data A hash of data which must be used
131
132
  # to extract the relationship data.
132
- def initialize(*args)
133
+ def initialize(data=nil)
133
134
  super()
134
135
 
135
- if args.length == 2
136
- initialize_attributes(*args)
136
+ if data
137
+ initialize_attributes(data)
137
138
  end
138
139
  end
139
140
 
140
141
  # Initializes the attributes of an existing shared folder.
141
- def initialize_attributes(parent, ishared)
142
- # Set the parent
143
- write_attribute(:parent, parent)
144
-
142
+ def initialize_attributes(ishared)
145
143
  # Load the interface attributes
146
144
  load_interface_attributes(ishared)
147
145
 
@@ -192,8 +190,14 @@ module VirtualBox
192
190
 
193
191
  # Relationship callback when added to a collection. This is automatically
194
192
  # called by any relationship collection when this object is added.
195
- def added_to_relationship(parent)
196
- write_attribute(:parent, parent)
193
+ def added_to_relationship(proxy)
194
+ was_clean = parent.nil? && !changed?
195
+
196
+ write_attribute(:parent, proxy.parent)
197
+ write_attribute(:parent_collection, proxy)
198
+
199
+ # This keeps existing records not dirty when added to collection
200
+ clear_dirty! if !new_record? && was_clean
197
201
  end
198
202
 
199
203
  # Destroys the shared folder. This doesn't actually delete the folder
@@ -206,8 +210,11 @@ module VirtualBox
206
210
  machine.remove_shared_folder(name)
207
211
  end
208
212
 
213
+ # Remove it from it's parent collection
214
+ parent_collection.delete(self, true) if parent_collection
215
+
209
216
  # Mark as a new record so if it is saved again, it will create it
210
217
  new_record!
211
218
  end
212
219
  end
213
- end
220
+ end
@@ -0,0 +1,185 @@
1
+ module VirtualBox
2
+ # Represents a virtual machine snapshot. Snapshots allow users of virtual
3
+ # machines to make a lightweight "snapshot" of a virtual machine at any
4
+ # moment. This snapshot can be taken while the virtual machine is running
5
+ # or while its powered off. Snapshotting creates a differencing image for
6
+ # the hard drive which allows a virtual machine to restore itself to the
7
+ # exact state of where it was snapshotted.
8
+ #
9
+ # # Getting Snapshots
10
+ #
11
+ # Snapshots are accessed from the `current_snapshot` relationship on {VM}.
12
+ # There is no other way to access snapshots. After getting the current
13
+ # snapshot, you can easily traverse the tree of snapshots by accessing
14
+ # `parent` or `children` on the snapshot. An example follows:
15
+ #
16
+ # vm = VirtualBox::VM.find("MyWindowsXP")
17
+ # p vm.current_snapshot # the current snapshot
18
+ # p vm.current_snapshot.children # The children of the current snapshot
19
+ # p vm.current_snapshot.parent # The current snapshot's parent
20
+ # p vm.current_snapshot.parent.parent.children # You get the idea.
21
+ #
22
+ # # Taking a Snapshot
23
+ #
24
+ # To take a snapshot, call the {VM#take_snapshot} method. Please view
25
+ # the documentation on that method for more information.
26
+ #
27
+ # # Restoring a Snapshot
28
+ #
29
+ # To restore a snapshot, call the {#restore} method. A simple example
30
+ # is shown below:
31
+ #
32
+ # vm = VirtualBox::VM.find("MyWindowsXP")
33
+ # snapshot = vm.current_snapshot.parent
34
+ # snapshot.restore
35
+ #
36
+ # **Note:** The VM object will not immediately update to reflect any settings
37
+ # changes or current snapshot changes from the restore. To grab the updates,
38
+ # either load a new VM object or call {VM#reload}.
39
+ #
40
+ # # Deleting a Snapshot
41
+ #
42
+ # To delete a snapshot, simply find the snapshot of interest and call
43
+ # it's {#destroy} method. A quick example is shown below:
44
+ #
45
+ # vm = VirtualBox::VM.find("MyWindowsXP")
46
+ # snapshot = vm.current_snapshot # Grab the current snapshot
47
+ # snapshot.destroy # Destroy it
48
+ #
49
+ # Note that this doesn't actually affect the `current_snapshot`
50
+ # relationship on the VM. To update all the proper values, you have to call
51
+ # {VM#reload}.
52
+ #
53
+ class Snapshot < AbstractModel
54
+ attribute :uuid, :readonly => true, :property => :id
55
+ attribute :name
56
+ attribute :description
57
+ attribute :time_stamp, :readonly => true
58
+ attribute :online, :readonly => true, :boolean => true
59
+ attribute :interface, :readonly => true, :property => false
60
+ relationship :parent, :Snapshot, :lazy => true
61
+ relationship :machine, :VM, :lazy => true
62
+ relationship :children, :Snapshot, :lazy => true
63
+
64
+ class << self
65
+ # Populates a relationship with another model. Since a snapshot
66
+ # can be in a relationship with multiple items, this method forwards
67
+ # to other methods such as {populate_vm_relationship}.
68
+ #
69
+ # **This method typically won't be used except internally.**
70
+ def populate_relationship(caller, data)
71
+ if data.is_a?(COM::Util.versioned_interface(:Machine))
72
+ populate_machine_relationship(caller, data)
73
+ elsif data.is_a?(Array)
74
+ populate_children_relationship(caller, data)
75
+ elsif data.is_a?(COM::Util.versioned_interface(:Snapshot)) || data.nil?
76
+ populate_parent_relationship(caller, data)
77
+ else
78
+ raise Exceptions::Exception.new("Invalid relationship data for Snapshot: #{data}")
79
+ end
80
+ end
81
+
82
+ # Populates the VM relationship as the "current snapshot."
83
+ #
84
+ # **This method typically won't be used except internally.**
85
+ #
86
+ # @return [Snapshot]
87
+ def populate_machine_relationship(caller, machine)
88
+ # The current snapshot can and will be nil if there are no snapshots
89
+ # taken. In that case, we just return nil.
90
+ snapshot = machine.current_snapshot
91
+ snapshot ? new(machine.current_snapshot) : nil
92
+ end
93
+
94
+ # Populates the VM relationship as the "current snapshot."
95
+ #
96
+ # **This method typically won't be used except internally.**
97
+ #
98
+ # @return [Snapshot]
99
+ def populate_parent_relationship(caller, parent)
100
+ # If the parent is nil then that means the child is the root
101
+ # snapshot
102
+ parent ? new(parent) : nil
103
+ end
104
+
105
+ # Populates the snapshot child tree relationship.
106
+ #
107
+ # **This method typically won't be used except internally.**
108
+ #
109
+ # @return [Array<Snapshot>]
110
+ def populate_children_relationship(caller, snapshots)
111
+ result = Proxies::Collection.new(caller)
112
+
113
+ snapshots.each do |snapshot|
114
+ result << new(snapshot)
115
+ end
116
+
117
+ result
118
+ end
119
+ end
120
+
121
+ # Initializes a new snapshot. This should never be called on its own.
122
+ # Snapshots should be accessed beginning with the `current_snapshot` on
123
+ # a VM, and can be further accessed by traversing the parent/child tree
124
+ # of the snapshot.
125
+ def initialize(snapshot)
126
+ write_attribute(:interface, snapshot)
127
+ initialize_attributes(snapshot)
128
+ end
129
+
130
+ def initialize_attributes(snapshot)
131
+ # Load the interface attributes
132
+ load_interface_attributes(snapshot)
133
+
134
+ # Clear dirtiness, since this should only be called initially and
135
+ # therefore shouldn't affect dirtiness
136
+ clear_dirty!
137
+
138
+ # But this is an existing record
139
+ existing_record!
140
+ end
141
+
142
+ # Loads the lazy relationships.
143
+ #
144
+ # **This method should only be called internally.**
145
+ def load_relationship(name)
146
+ populate_relationship(:parent, interface.parent)
147
+ populate_relationship(:machine, interface.machine)
148
+ populate_relationship(:children, interface.children)
149
+ end
150
+
151
+ # Timestamp that the snapshot was taken. This method overwrites the
152
+ # typical attribute so it can return a Time object.
153
+ def time_stamp
154
+ # Seconds, microseconds, since the time stamp is in milliseconds
155
+ value = read_attribute(:time_stamp)
156
+ Time.at(value / 1000, (value % 1000) * 1000)
157
+ end
158
+
159
+ # Restore a snapshot. This will restore this snapshot's virtual machine
160
+ # to the state that this snapshot represents. This method will block while
161
+ # the restore occurs.
162
+ #
163
+ # If a block is given to the function, it will be yielded with a progress
164
+ # object which can be used to track the progress of the operation.
165
+ def restore(&block)
166
+ machine.with_open_session do |session|
167
+ session.console.restore_snapshot(interface).wait(&block)
168
+ end
169
+ end
170
+
171
+ # Destroy a snapshot. This will physically remove the snapshot. Once this
172
+ # method is called, there is no undo. If this snapshot is a parent of other
173
+ # snapshots, the differencing image of this snapshot will be merged with
174
+ # the child snapshots so no data is lost. This process can sometimes take
175
+ # some time. This method will block while this process occurs.
176
+ #
177
+ # If a block is given to the function, it will be yielded with a progress
178
+ # object which can be used to track the progress of the operation.
179
+ def destroy(&block)
180
+ machine.with_open_session do |session|
181
+ session.console.delete_snapshot(uuid).wait(&block)
182
+ end
183
+ end
184
+ end
185
+ end
@@ -47,14 +47,14 @@ module VirtualBox
47
47
  attribute :bus, :readonly => true
48
48
  attribute :controller_type
49
49
 
50
- class <<self
50
+ class << self
51
51
  # Populates a relationship with another model.
52
52
  #
53
53
  # **This method typically won't be used except internally.**
54
54
  #
55
55
  # @return [Array<StorageController>]
56
56
  def populate_relationship(caller, data)
57
- if data.is_a?(COM::Interface::Machine)
57
+ if data.is_a?(COM::Util.versioned_interface(:Machine))
58
58
  populate_array_relationship(caller, data)
59
59
  elsif data.is_a?(MediumAttachment)
60
60
  populate_attachment_relationship(caller, data)
@@ -157,4 +157,4 @@ module VirtualBox
157
157
  end
158
158
  end
159
159
  end
160
- end
160
+ end
@@ -26,7 +26,7 @@ module VirtualBox
26
26
  attribute :log_history_count
27
27
  attribute :default_audio_driver, :readonly => true
28
28
 
29
- class <<self
29
+ class << self
30
30
  # Populates the system properties relationship for anything
31
31
  # which is related to it.
32
32
  #
@@ -4,11 +4,12 @@ module VirtualBox
4
4
  class USBController < AbstractModel
5
5
  attribute :parent, :readonly => true, :property => false
6
6
  attribute :interface, :readonly => true, :property => false
7
- attribute :enabled
8
- attribute :enabled_ehci
7
+ attribute :enabled, :boolean => true
8
+ attribute :enabled_ehci, :boolean => true
9
9
  attribute :usb_standard, :readonly => true
10
+ relationship :device_filters, :USBDeviceFilter
10
11
 
11
- class <<self
12
+ class << self
12
13
  # Populates the USB controller relationship for anything
13
14
  # which is related to it.
14
15
  #
@@ -40,6 +41,9 @@ module VirtualBox
40
41
  # Load the interface attributes
41
42
  load_interface_attributes(interface)
42
43
 
44
+ # Setup the relationships
45
+ populate_relationships(interface)
46
+
43
47
  # Clear dirty and mark as existing
44
48
  clear_dirty!
45
49
  existing_record!
@@ -52,4 +56,4 @@ module VirtualBox
52
56
  end
53
57
  end
54
58
  end
55
- end
59
+ end
@@ -0,0 +1,74 @@
1
+ module VirtualBox
2
+ # Represents a USB device filter within VirtualBox. This class
3
+ # is a relationship to {USBController} objects.
4
+ class USBDeviceFilter < AbstractModel
5
+ attribute :parent, :readonly => true, :property => false
6
+ attribute :parent_collection, :readonly => true, :property => false
7
+ attribute :interface, :readonly => true, :property => false
8
+ attribute :name
9
+ attribute :active, :boolean => true
10
+ attribute :vendor_id
11
+ attribute :product_id
12
+ attribute :revision
13
+ attribute :manufacturer
14
+ attribute :product
15
+ attribute :serial_number
16
+ attribute :port
17
+ attribute :remote
18
+ attribute :masked_interfaces
19
+
20
+ class << self
21
+ # Populates the USB controller relationship for anything
22
+ # which is related to it.
23
+ #
24
+ # **This method typically won't be used except internally.**
25
+ #
26
+ # @return [USBDeviceFilter]
27
+ def populate_relationship(caller, usbcontroller)
28
+ result = Proxies::Collection.new(caller)
29
+
30
+ usbcontroller.device_filters.each do |filter|
31
+ result << new(filter)
32
+ end
33
+
34
+ result
35
+ end
36
+
37
+ # Saves the relationship. This simply calls {#save} on the
38
+ # relationship object.
39
+ #
40
+ # **This method typically won't be used except internally.**
41
+ def save_relationship(caller, item)
42
+ item.save
43
+ end
44
+ end
45
+
46
+ def initialize(iusb)
47
+ initialize_attributes(iusb)
48
+ end
49
+
50
+ def initialize_attributes(iusb)
51
+ # Write the parent and interface attributes
52
+ write_attribute(:interface, iusb)
53
+
54
+ # Load the interface attributes
55
+ load_interface_attributes(interface)
56
+
57
+ # Clear dirty and mark as existing
58
+ clear_dirty!
59
+ existing_record!
60
+ end
61
+
62
+ def added_to_relationship(proxy)
63
+ write_attribute(:parent, proxy.parent)
64
+ write_attribute(:parent_collection, proxy)
65
+ end
66
+
67
+ # Saves the USB device.
68
+ def save
69
+ parent.with_open_session do |session|
70
+ # TODO: save_changed_interface_attributes(session.machine.usb_controller)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,5 +1,16 @@
1
1
  module VirtualBox
2
2
  module Version
3
+ # Returns a boolean denoting whether the current VirtualBox
4
+ # version is supported or not. This will return `false` if the
5
+ # version is invalid, the version is not detected, etc. That means
6
+ # that even if VirtualBox is not installed, this will simply
7
+ # return `false`.
8
+ #
9
+ # @return [Boolean]
10
+ def supported?
11
+ !version.nil?
12
+ end
13
+
3
14
  # Returns the version string of the VirtualBox installed, ex. "3.1.6"
4
15
  def version
5
16
  Lib.lib.virtualbox.version
@@ -12,4 +23,4 @@ module VirtualBox
12
23
  Lib.lib.virtualbox.revision
13
24
  end
14
25
  end
15
- end
26
+ end
@@ -5,7 +5,7 @@ module VirtualBox
5
5
  attribute :interface, :readonly => true
6
6
  attribute :descriptions, :readonly => true, :default => {}
7
7
 
8
- class <<self
8
+ class << self
9
9
  def populate_relationship(caller, data)
10
10
  result = Proxies::Collection.new(caller)
11
11
 
@@ -26,8 +26,8 @@ module VirtualBox
26
26
  # Grab all the descriptions, iterate over each, and add to the hash of
27
27
  # descriptions. This multiple loop method is used instead of `get_description` since
28
28
  # that method doesn't work well with MSCOM.
29
- COM::Interface::VirtualSystemDescriptionType.each_with_index do |type, index|
30
- COM::Interface::VirtualSystemDescriptionValueType.each_with_index do |value_type, value_index|
29
+ COM::Util.versioned_interface(:VirtualSystemDescriptionType).each_with_index do |type, index|
30
+ COM::Util.versioned_interface(:VirtualSystemDescriptionValueType).each_with_index do |value_type, value_index|
31
31
  value = ivsd.get_values_by_type(type, value_type)
32
32
  if value && value != [] && value != [nil]
33
33
  descriptions[type] ||= {}
@@ -44,4 +44,4 @@ module VirtualBox
44
44
  existing_record!
45
45
  end
46
46
  end
47
- end
47
+ end