bbrowning-virtualbox 0.7.6.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. data/.gitignore +8 -0
  2. data/.yardopts +3 -0
  3. data/Gemfile +16 -0
  4. data/LICENSE +19 -0
  5. data/Rakefile +33 -0
  6. data/Readme.md +70 -0
  7. data/docs/GettingStarted.md +196 -0
  8. data/docs/WhatsNew.md +12 -0
  9. data/features/README.md +33 -0
  10. data/features/global.feature +19 -0
  11. data/features/global_extra_data.feature +27 -0
  12. data/features/step_definitions/abstract_model_steps.rb +39 -0
  13. data/features/step_definitions/extra_data_steps.rb +36 -0
  14. data/features/step_definitions/global_steps.rb +29 -0
  15. data/features/step_definitions/nat_engine_steps.rb +76 -0
  16. data/features/step_definitions/network_adapter_steps.rb +38 -0
  17. data/features/step_definitions/shared_folder_steps.rb +76 -0
  18. data/features/step_definitions/snapshot_steps.rb +74 -0
  19. data/features/step_definitions/storage_controller_steps.rb +16 -0
  20. data/features/step_definitions/virtualbox_steps.rb +17 -0
  21. data/features/step_definitions/vm_steps.rb +50 -0
  22. data/features/support/env.rb +61 -0
  23. data/features/support/helpers.rb +38 -0
  24. data/features/support/hooks.rb +30 -0
  25. data/features/support/ordered_hash.rb +49 -0
  26. data/features/support/vboxmanage.rb +191 -0
  27. data/features/version.feature +16 -0
  28. data/features/vm.feature +13 -0
  29. data/features/vm_bios.feature +29 -0
  30. data/features/vm_cpu.feature +29 -0
  31. data/features/vm_extra_data.feature +35 -0
  32. data/features/vm_hw_virt.feature +29 -0
  33. data/features/vm_nat_engine.feature +57 -0
  34. data/features/vm_network_adapters.feature +27 -0
  35. data/features/vm_shared_folders.feature +42 -0
  36. data/features/vm_snapshots.feature +29 -0
  37. data/features/vm_storage_controllers.feature +11 -0
  38. data/lib/virtualbox.rb +11 -0
  39. data/lib/virtualbox/abstract_model.rb +281 -0
  40. data/lib/virtualbox/abstract_model/attributable.rb +290 -0
  41. data/lib/virtualbox/abstract_model/dirty.rb +177 -0
  42. data/lib/virtualbox/abstract_model/interface_attributes.rb +98 -0
  43. data/lib/virtualbox/abstract_model/relatable.rb +332 -0
  44. data/lib/virtualbox/abstract_model/validatable.rb +167 -0
  45. data/lib/virtualbox/abstract_model/version_matcher.rb +35 -0
  46. data/lib/virtualbox/appliance.rb +62 -0
  47. data/lib/virtualbox/audio_adapter.rb +52 -0
  48. data/lib/virtualbox/bios.rb +50 -0
  49. data/lib/virtualbox/com.rb +23 -0
  50. data/lib/virtualbox/com/abstract_enum.rb +43 -0
  51. data/lib/virtualbox/com/abstract_implementer.rb +45 -0
  52. data/lib/virtualbox/com/abstract_interface.rb +167 -0
  53. data/lib/virtualbox/com/base_interface.rb +38 -0
  54. data/lib/virtualbox/com/ffi/interface.rb +150 -0
  55. data/lib/virtualbox/com/ffi/interfaces.rb +54 -0
  56. data/lib/virtualbox/com/ffi/util.rb +119 -0
  57. data/lib/virtualbox/com/ffi/vboxxpcomc.rb +31 -0
  58. data/lib/virtualbox/com/ffi_interface.rb +96 -0
  59. data/lib/virtualbox/com/implementer/base.rb +59 -0
  60. data/lib/virtualbox/com/implementer/ffi.rb +361 -0
  61. data/lib/virtualbox/com/implementer/mscom.rb +175 -0
  62. data/lib/virtualbox/com/implementer/nil.rb +10 -0
  63. data/lib/virtualbox/com/interface/3.1.x/access_mode.rb +11 -0
  64. data/lib/virtualbox/com/interface/3.1.x/appliance.rb +22 -0
  65. data/lib/virtualbox/com/interface/3.1.x/audio_adapter.rb +15 -0
  66. data/lib/virtualbox/com/interface/3.1.x/audio_controller_type.rb +11 -0
  67. data/lib/virtualbox/com/interface/3.1.x/audio_driver_type.rb +11 -0
  68. data/lib/virtualbox/com/interface/3.1.x/bios_boot_menu_mode.rb +11 -0
  69. data/lib/virtualbox/com/interface/3.1.x/bios_settings.rb +21 -0
  70. data/lib/virtualbox/com/interface/3.1.x/clipboard_mode.rb +11 -0
  71. data/lib/virtualbox/com/interface/3.1.x/console.rb +50 -0
  72. data/lib/virtualbox/com/interface/3.1.x/cpu_property_type.rb +11 -0
  73. data/lib/virtualbox/com/interface/3.1.x/device_type.rb +11 -0
  74. data/lib/virtualbox/com/interface/3.1.x/dhcp_server.rb +22 -0
  75. data/lib/virtualbox/com/interface/3.1.x/firmware_type.rb +11 -0
  76. data/lib/virtualbox/com/interface/3.1.x/guest_os_type.rb +23 -0
  77. data/lib/virtualbox/com/interface/3.1.x/host.rb +42 -0
  78. data/lib/virtualbox/com/interface/3.1.x/host_network_interface.rb +30 -0
  79. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_medium_type.rb +11 -0
  80. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_status.rb +11 -0
  81. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_type.rb +11 -0
  82. data/lib/virtualbox/com/interface/3.1.x/host_usb_device.rb +13 -0
  83. data/lib/virtualbox/com/interface/3.1.x/host_usb_device_filter.rb +13 -0
  84. data/lib/virtualbox/com/interface/3.1.x/hw_virt_ex_property_type.rb +11 -0
  85. data/lib/virtualbox/com/interface/3.1.x/machine.rb +105 -0
  86. data/lib/virtualbox/com/interface/3.1.x/machine_state.rb +14 -0
  87. data/lib/virtualbox/com/interface/3.1.x/medium.rb +50 -0
  88. data/lib/virtualbox/com/interface/3.1.x/medium_attachment.rb +18 -0
  89. data/lib/virtualbox/com/interface/3.1.x/medium_format.rb +18 -0
  90. data/lib/virtualbox/com/interface/3.1.x/medium_state.rb +11 -0
  91. data/lib/virtualbox/com/interface/3.1.x/medium_type.rb +11 -0
  92. data/lib/virtualbox/com/interface/3.1.x/medium_variant.rb +11 -0
  93. data/lib/virtualbox/com/interface/3.1.x/network_adapter.rb +30 -0
  94. data/lib/virtualbox/com/interface/3.1.x/network_adapter_type.rb +11 -0
  95. data/lib/virtualbox/com/interface/3.1.x/network_attachment_type.rb +11 -0
  96. data/lib/virtualbox/com/interface/3.1.x/nsiexception.rb +23 -0
  97. data/lib/virtualbox/com/interface/3.1.x/nsisupports.rb +15 -0
  98. data/lib/virtualbox/com/interface/3.1.x/parallel_port.rb +17 -0
  99. data/lib/virtualbox/com/interface/3.1.x/port_mode.rb +11 -0
  100. data/lib/virtualbox/com/interface/3.1.x/progress.rb +63 -0
  101. data/lib/virtualbox/com/interface/3.1.x/serial_port.rb +19 -0
  102. data/lib/virtualbox/com/interface/3.1.x/session.rb +18 -0
  103. data/lib/virtualbox/com/interface/3.1.x/session_state.rb +11 -0
  104. data/lib/virtualbox/com/interface/3.1.x/session_type.rb +11 -0
  105. data/lib/virtualbox/com/interface/3.1.x/shared_folder.rb +17 -0
  106. data/lib/virtualbox/com/interface/3.1.x/snapshot.rb +20 -0
  107. data/lib/virtualbox/com/interface/3.1.x/storage_bus.rb +11 -0
  108. data/lib/virtualbox/com/interface/3.1.x/storage_controller.rb +23 -0
  109. data/lib/virtualbox/com/interface/3.1.x/storage_controller_type.rb +11 -0
  110. data/lib/virtualbox/com/interface/3.1.x/system_properties.rb +37 -0
  111. data/lib/virtualbox/com/interface/3.1.x/usb_controller.rb +20 -0
  112. data/lib/virtualbox/com/interface/3.1.x/usb_device.rb +24 -0
  113. data/lib/virtualbox/com/interface/3.1.x/usb_device_filter.rb +23 -0
  114. data/lib/virtualbox/com/interface/3.1.x/usb_device_filter_action.rb +11 -0
  115. data/lib/virtualbox/com/interface/3.1.x/usb_device_state.rb +11 -0
  116. data/lib/virtualbox/com/interface/3.1.x/virtual_box_error_info.rb +17 -0
  117. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description.rb +19 -0
  118. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_type.rb +14 -0
  119. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_value_type.rb +11 -0
  120. data/lib/virtualbox/com/interface/3.1.x/virtualbox.rb +67 -0
  121. data/lib/virtualbox/com/interface/3.1.x/vrdp_auth_type.rb +11 -0
  122. data/lib/virtualbox/com/interface/3.1.x/vrdp_server.rb +19 -0
  123. data/lib/virtualbox/com/interface/3.2.x/access_mode.rb +11 -0
  124. data/lib/virtualbox/com/interface/3.2.x/appliance.rb +22 -0
  125. data/lib/virtualbox/com/interface/3.2.x/audio_adapter.rb +15 -0
  126. data/lib/virtualbox/com/interface/3.2.x/audio_controller_type.rb +11 -0
  127. data/lib/virtualbox/com/interface/3.2.x/audio_driver_type.rb +11 -0
  128. data/lib/virtualbox/com/interface/3.2.x/bios_boot_menu_mode.rb +11 -0
  129. data/lib/virtualbox/com/interface/3.2.x/bios_settings.rb +21 -0
  130. data/lib/virtualbox/com/interface/3.2.x/clipboard_mode.rb +11 -0
  131. data/lib/virtualbox/com/interface/3.2.x/console.rb +50 -0
  132. data/lib/virtualbox/com/interface/3.2.x/cpu_property_type.rb +11 -0
  133. data/lib/virtualbox/com/interface/3.2.x/device_type.rb +11 -0
  134. data/lib/virtualbox/com/interface/3.2.x/dhcp_server.rb +22 -0
  135. data/lib/virtualbox/com/interface/3.2.x/firmware_type.rb +11 -0
  136. data/lib/virtualbox/com/interface/3.2.x/guest.rb +13 -0
  137. data/lib/virtualbox/com/interface/3.2.x/guest_os_type.rb +33 -0
  138. data/lib/virtualbox/com/interface/3.2.x/host.rb +43 -0
  139. data/lib/virtualbox/com/interface/3.2.x/host_network_interface.rb +30 -0
  140. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_medium_type.rb +11 -0
  141. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_status.rb +11 -0
  142. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_type.rb +11 -0
  143. data/lib/virtualbox/com/interface/3.2.x/host_usb_device.rb +13 -0
  144. data/lib/virtualbox/com/interface/3.2.x/host_usb_device_filter.rb +13 -0
  145. data/lib/virtualbox/com/interface/3.2.x/hw_virt_ex_property_type.rb +11 -0
  146. data/lib/virtualbox/com/interface/3.2.x/keyboard_hid_type.rb +11 -0
  147. data/lib/virtualbox/com/interface/3.2.x/machine.rb +118 -0
  148. data/lib/virtualbox/com/interface/3.2.x/machine_state.rb +14 -0
  149. data/lib/virtualbox/com/interface/3.2.x/medium.rb +51 -0
  150. data/lib/virtualbox/com/interface/3.2.x/medium_attachment.rb +18 -0
  151. data/lib/virtualbox/com/interface/3.2.x/medium_format.rb +18 -0
  152. data/lib/virtualbox/com/interface/3.2.x/medium_state.rb +11 -0
  153. data/lib/virtualbox/com/interface/3.2.x/medium_type.rb +11 -0
  154. data/lib/virtualbox/com/interface/3.2.x/medium_variant.rb +11 -0
  155. data/lib/virtualbox/com/interface/3.2.x/nat_alias_mode.rb +11 -0
  156. data/lib/virtualbox/com/interface/3.2.x/nat_engine.rb +27 -0
  157. data/lib/virtualbox/com/interface/3.2.x/nat_protocol.rb +11 -0
  158. data/lib/virtualbox/com/interface/3.2.x/network_adapter.rb +34 -0
  159. data/lib/virtualbox/com/interface/3.2.x/network_adapter_type.rb +11 -0
  160. data/lib/virtualbox/com/interface/3.2.x/network_attachment_type.rb +11 -0
  161. data/lib/virtualbox/com/interface/3.2.x/nsiexception.rb +23 -0
  162. data/lib/virtualbox/com/interface/3.2.x/nsisupports.rb +15 -0
  163. data/lib/virtualbox/com/interface/3.2.x/parallel_port.rb +17 -0
  164. data/lib/virtualbox/com/interface/3.2.x/pointing_hid_type.rb +11 -0
  165. data/lib/virtualbox/com/interface/3.2.x/port_mode.rb +11 -0
  166. data/lib/virtualbox/com/interface/3.2.x/progress.rb +63 -0
  167. data/lib/virtualbox/com/interface/3.2.x/serial_port.rb +19 -0
  168. data/lib/virtualbox/com/interface/3.2.x/session.rb +18 -0
  169. data/lib/virtualbox/com/interface/3.2.x/session_state.rb +11 -0
  170. data/lib/virtualbox/com/interface/3.2.x/session_type.rb +11 -0
  171. data/lib/virtualbox/com/interface/3.2.x/shared_folder.rb +17 -0
  172. data/lib/virtualbox/com/interface/3.2.x/snapshot.rb +20 -0
  173. data/lib/virtualbox/com/interface/3.2.x/storage_bus.rb +11 -0
  174. data/lib/virtualbox/com/interface/3.2.x/storage_controller.rb +24 -0
  175. data/lib/virtualbox/com/interface/3.2.x/storage_controller_type.rb +11 -0
  176. data/lib/virtualbox/com/interface/3.2.x/system_properties.rb +42 -0
  177. data/lib/virtualbox/com/interface/3.2.x/usb_controller.rb +21 -0
  178. data/lib/virtualbox/com/interface/3.2.x/usb_device.rb +24 -0
  179. data/lib/virtualbox/com/interface/3.2.x/usb_device_filter.rb +23 -0
  180. data/lib/virtualbox/com/interface/3.2.x/usb_device_filter_action.rb +11 -0
  181. data/lib/virtualbox/com/interface/3.2.x/usb_device_state.rb +11 -0
  182. data/lib/virtualbox/com/interface/3.2.x/virtual_box_error_info.rb +17 -0
  183. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description.rb +19 -0
  184. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_type.rb +14 -0
  185. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_value_type.rb +11 -0
  186. data/lib/virtualbox/com/interface/3.2.x/virtualbox.rb +67 -0
  187. data/lib/virtualbox/com/interface/3.2.x/vrdp_auth_type.rb +11 -0
  188. data/lib/virtualbox/com/interface/3.2.x/vrdp_server.rb +21 -0
  189. data/lib/virtualbox/com/mscom_interface.rb +44 -0
  190. data/lib/virtualbox/com/nil_interface.rb +7 -0
  191. data/lib/virtualbox/com/util.rb +32 -0
  192. data/lib/virtualbox/cpu.rb +61 -0
  193. data/lib/virtualbox/dhcp_server.rb +89 -0
  194. data/lib/virtualbox/dvd.rb +27 -0
  195. data/lib/virtualbox/exceptions.rb +39 -0
  196. data/lib/virtualbox/ext/byte_normalizer.rb +17 -0
  197. data/lib/virtualbox/ext/glob_loader.rb +22 -0
  198. data/lib/virtualbox/ext/logger.rb +38 -0
  199. data/lib/virtualbox/ext/platform.rb +27 -0
  200. data/lib/virtualbox/ext/subclass_listing.rb +24 -0
  201. data/lib/virtualbox/extra_data.rb +127 -0
  202. data/lib/virtualbox/forwarded_port.rb +222 -0
  203. data/lib/virtualbox/global.rb +102 -0
  204. data/lib/virtualbox/guest_property.rb +116 -0
  205. data/lib/virtualbox/hard_drive.rb +246 -0
  206. data/lib/virtualbox/host.rb +71 -0
  207. data/lib/virtualbox/host_network_interface.rb +137 -0
  208. data/lib/virtualbox/hw_virtualization.rb +63 -0
  209. data/lib/virtualbox/lib.rb +84 -0
  210. data/lib/virtualbox/media.rb +20 -0
  211. data/lib/virtualbox/medium.rb +145 -0
  212. data/lib/virtualbox/medium_attachment.rb +61 -0
  213. data/lib/virtualbox/nat_engine.rb +71 -0
  214. data/lib/virtualbox/nat_forwarded_port.rb +171 -0
  215. data/lib/virtualbox/network_adapter.rb +166 -0
  216. data/lib/virtualbox/proxies/collection.rb +57 -0
  217. data/lib/virtualbox/shared_folder.rb +220 -0
  218. data/lib/virtualbox/snapshot.rb +185 -0
  219. data/lib/virtualbox/storage_controller.rb +160 -0
  220. data/lib/virtualbox/system_properties.rb +74 -0
  221. data/lib/virtualbox/usb_controller.rb +59 -0
  222. data/lib/virtualbox/usb_device_filter.rb +74 -0
  223. data/lib/virtualbox/version.rb +36 -0
  224. data/lib/virtualbox/virtual_system_description.rb +47 -0
  225. data/lib/virtualbox/vm.rb +684 -0
  226. data/lib/virtualbox/vrdp_server.rb +59 -0
  227. data/test/test_helper.rb +18 -0
  228. data/test/virtualbox/abstract_model/attributable_test.rb +269 -0
  229. data/test/virtualbox/abstract_model/dirty_test.rb +83 -0
  230. data/test/virtualbox/abstract_model/interface_attributes_test.rb +194 -0
  231. data/test/virtualbox/abstract_model/relatable_test.rb +348 -0
  232. data/test/virtualbox/abstract_model/validatable_test.rb +308 -0
  233. data/test/virtualbox/abstract_model/version_matcher_test.rb +41 -0
  234. data/test/virtualbox/abstract_model_test.rb +462 -0
  235. data/test/virtualbox/appliance_test.rb +159 -0
  236. data/test/virtualbox/audio_adapter_test.rb +83 -0
  237. data/test/virtualbox/bios_test.rb +83 -0
  238. data/test/virtualbox/com/abstract_enum_test.rb +49 -0
  239. data/test/virtualbox/com/abstract_implementer_test.rb +40 -0
  240. data/test/virtualbox/com/abstract_interface_test.rb +140 -0
  241. data/test/virtualbox/com/ffi/interface_test.rb +249 -0
  242. data/test/virtualbox/com/ffi/util_test.rb +108 -0
  243. data/test/virtualbox/com/ffi_interface_test.rb +42 -0
  244. data/test/virtualbox/com/implementer/base_test.rb +38 -0
  245. data/test/virtualbox/com/implementer/ffi_test.rb +527 -0
  246. data/test/virtualbox/com/implementer/mscom_test.rb +247 -0
  247. data/test/virtualbox/com/mscom_interface_test.rb +17 -0
  248. data/test/virtualbox/com/util_test.rb +17 -0
  249. data/test/virtualbox/cpu_test.rb +103 -0
  250. data/test/virtualbox/dhcp_server_test.rb +165 -0
  251. data/test/virtualbox/dvd_test.rb +28 -0
  252. data/test/virtualbox/ext/byte_normalizer_test.rb +34 -0
  253. data/test/virtualbox/ext/platform_test.rb +50 -0
  254. data/test/virtualbox/ext/subclass_listing_test.rb +25 -0
  255. data/test/virtualbox/extra_data_test.rb +155 -0
  256. data/test/virtualbox/forwarded_port_test.rb +286 -0
  257. data/test/virtualbox/global_test.rb +46 -0
  258. data/test/virtualbox/hard_drive_test.rb +141 -0
  259. data/test/virtualbox/host_network_interface_test.rb +254 -0
  260. data/test/virtualbox/host_test.rb +94 -0
  261. data/test/virtualbox/hw_virtualization_test.rb +103 -0
  262. data/test/virtualbox/lib_test.rb +93 -0
  263. data/test/virtualbox/medium_attachment_test.rb +147 -0
  264. data/test/virtualbox/medium_test.rb +192 -0
  265. data/test/virtualbox/nat_engine_test.rb +106 -0
  266. data/test/virtualbox/nat_forwarded_port_test.rb +222 -0
  267. data/test/virtualbox/network_adapter_test.rb +191 -0
  268. data/test/virtualbox/proxies/collection_test.rb +102 -0
  269. data/test/virtualbox/shared_folder_test.rb +219 -0
  270. data/test/virtualbox/snapshot_test.rb +231 -0
  271. data/test/virtualbox/storage_controller_test.rb +197 -0
  272. data/test/virtualbox/system_properties_test.rb +87 -0
  273. data/test/virtualbox/usb_controller_test.rb +112 -0
  274. data/test/virtualbox/usb_device_filter_test.rb +93 -0
  275. data/test/virtualbox/version_test.rb +59 -0
  276. data/test/virtualbox/virtual_system_description_test.rb +61 -0
  277. data/test/virtualbox/vm_test.rb +637 -0
  278. data/test/virtualbox/vrdp_server_test.rb +83 -0
  279. data/test/virtualbox_test.rb +11 -0
  280. data/virtualbox.gemspec +25 -0
  281. metadata +397 -0
@@ -0,0 +1,71 @@
1
+ module VirtualBox
2
+ # Represents information about the host machine. This includes
3
+ # information such as memory available, processors, dvds, network
4
+ # interfaces, etc.
5
+ #
6
+ # This information is different from system properties in that some
7
+ # parts represent data which is stored in the VirtualBox "registry"
8
+ # (such as the dvd drives, host only network interfaces, etc.)
9
+ class Host < AbstractModel
10
+ attribute :parent, :readonly => true, :property => false
11
+ attribute :interface, :readonly => true, :property => false
12
+ attribute :processor_count, :readonly => true
13
+ attribute :processor_online_count, :readonly => true
14
+ attribute :memory_size, :readonly => true
15
+ attribute :memory_available, :readonly => true
16
+ attribute :operating_system, :readonly => true
17
+ attribute :os_version, :readonly => true
18
+ attribute :utc_time, :readonly => true
19
+ attribute :acceleration_3d_available, :readonly => true
20
+ relationship :network_interfaces, :HostNetworkInterface
21
+
22
+ class << self
23
+ # Populates the system properties relationship for anything
24
+ # which is related to it.
25
+ #
26
+ # **This method typically won't be used except internally.**
27
+ #
28
+ # @return [SystemProperties]
29
+ def populate_relationship(caller, data)
30
+ new(caller, data)
31
+ end
32
+
33
+ # Saves the relationship. This simply calls {#save} on the
34
+ # relationship object.
35
+ #
36
+ # **This method typically won't be used except internally.**
37
+ def save_relationship(caller, item)
38
+ item.save
39
+ end
40
+ end
41
+
42
+ # Initializes the system properties object. This shouldn't be called
43
+ # directly. Instead `Global#system_properties` should be used to
44
+ # retrieve this object.
45
+ def initialize(caller, raw)
46
+ initialize_attributes(caller, raw)
47
+ end
48
+
49
+ # Initializes the attributes of an existing shared folder.
50
+ def initialize_attributes(caller, raw)
51
+ # Save the interface and parent
52
+ write_attribute(:parent, caller)
53
+ write_attribute(:interface, raw)
54
+
55
+ # Load the attributes from the interface
56
+ load_interface_attributes(interface)
57
+
58
+ # Get the relationships setup
59
+ populate_relationship(:network_interfaces, interface)
60
+
61
+ # Clear dirty and mark as existing
62
+ clear_dirty!
63
+ existing_record!
64
+ end
65
+
66
+ # Saves the system properties.
67
+ def save
68
+ save_changed_interface_attributes(interface)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,137 @@
1
+ module VirtualBox
2
+ # Represents a network interface on the host. There are generally
3
+ # two types of network interfaces wihch exist on the host: bridged
4
+ # and host-only. This class represents both.
5
+ class HostNetworkInterface < AbstractModel
6
+ attribute :parent, :readonly => true, :property => false
7
+ attribute :parent_collection, :readonly => true, :property => false
8
+ attribute :interface, :readonly => true, :property => false
9
+ attribute :name, :readonly => true
10
+ attribute :uuid, :readonly => true, :property => :id
11
+ attribute :network_name, :readonly => true
12
+ attribute :dhcp_enabled, :readonly => true
13
+ attribute :ip_address, :readonly => true
14
+ attribute :network_mask, :readonly => true
15
+ attribute :ip_v6_supported, :readonly => true
16
+ attribute :ip_v6_address, :readonly => true
17
+ attribute :ip_v6_network_mask_prefix_length, :readonly => true
18
+ attribute :hardware_address, :readonly => true
19
+ attribute :medium_type, :readonly => true
20
+ attribute :status, :readonly => true
21
+ attribute :interface_type, :readonly => true
22
+
23
+ class << self
24
+ # Populates a relationship with another model.
25
+ #
26
+ # **This method typically won't be used except internally.**
27
+ #
28
+ # @return [Array<HostNetworkInterface>]
29
+ def populate_relationship(caller, ihost)
30
+ relation = Proxies::Collection.new(caller, self, ihost)
31
+
32
+ ihost.network_interfaces.each do |inet|
33
+ relation << new(inet)
34
+ end
35
+
36
+ relation
37
+ end
38
+
39
+ # Creates a host only network interface. This method should not
40
+ # be called directly. Instead, the `create` method on the
41
+ # `Global#host` relationship should be called instead. Example:
42
+ #
43
+ # VirtualBox::Global.global.host.network_interfaces.create
44
+ #
45
+ # The above will create a host only network interface, add it to
46
+ # the collection, and will return the instance of the new
47
+ # interface.
48
+ def create(proxy, interface)
49
+ inet, progress = interface.create_host_only_network_interface
50
+ progress.wait
51
+
52
+ new(inet)
53
+ end
54
+ end
55
+
56
+ def initialize(inet)
57
+ initialize_attributes(inet)
58
+ end
59
+
60
+ def initialize_attributes(inet)
61
+ write_attribute(:interface, inet)
62
+
63
+ load_interface_attributes(inet)
64
+ existing_record!
65
+ end
66
+
67
+ def added_to_relationship(proxy)
68
+ write_attribute(:parent, proxy.parent)
69
+ write_attribute(:parent_collection, proxy)
70
+ end
71
+
72
+ # Gets the DHCP server associated with the network interface. Only
73
+ # host only network interfaces have dhcp servers. If a DHCP server
74
+ # doesn't exist for this network interface, one will be created.
75
+ def dhcp_server(create_if_not_found=true)
76
+ return nil if interface_type != :host_only
77
+
78
+ # Try to find the dhcp server in the list of DHCP servers.
79
+ dhcp_name = "HostInterfaceNetworking-#{name}"
80
+ result = parent.parent.dhcp_servers.find do |dhcp|
81
+ dhcp.network_name == dhcp_name
82
+ end
83
+
84
+ # If no DHCP server is found, create one
85
+ result = parent.parent.dhcp_servers.create(dhcp_name) if result.nil? && create_if_not_found
86
+ result
87
+ end
88
+
89
+ # Gets the VMs which have an adapter which is attached to this
90
+ # network interface.
91
+ def attached_vms
92
+ parent.parent.vms.find_all do |vm|
93
+ result = vm.network_adapters.find do |adapter|
94
+ adapter.host_interface == name
95
+ end
96
+
97
+ !result.nil?
98
+ end
99
+ end
100
+
101
+ # Sets up the static IPV4 configuration for the host only network
102
+ # interface. This allows the caller to set the IPV4 address of the
103
+ # interface as well as the netmask.
104
+ def enable_static(ip, netmask=nil)
105
+ netmask ||= network_mask
106
+
107
+ interface.enable_static_ip_config(ip, netmask)
108
+ reload
109
+ end
110
+
111
+ # Reloads the information regarding this host only network
112
+ # interface.
113
+ def reload
114
+ # Find the interface again and reload the data
115
+ inet = parent.interface.find_host_network_interface_by_id(uuid)
116
+ initialize_attributes(inet)
117
+ self
118
+ end
119
+
120
+ # Destroy the host only network interface. Warning: If any VMs are
121
+ # currently attached to this network interface, their networks
122
+ # will fail to work after removing this. Therefore, one should be
123
+ # careful to make sure to remove all VMs from this network prior
124
+ # to destroying it.
125
+ def destroy
126
+ return false if interface_type == :bridged
127
+
128
+ parent.interface.remove_host_only_network_interface(uuid).wait
129
+ dhcp_server.destroy if dhcp_server(false)
130
+
131
+ # Remove from collection
132
+ parent_collection.delete(self, true) if parent_collection
133
+
134
+ true
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,63 @@
1
+ module VirtualBox
2
+ # Represents the HW virtualization properties on a VM.
3
+ class HWVirtualization < AbstractModel
4
+ attribute :parent, :readonly => true, :property => false
5
+ attribute_scope(:property_getter => Proc.new { |instance, *args| instance.get_property(*args) },
6
+ :property_setter => Proc.new { |instance, *args| instance.set_property(*args) }) do
7
+ attribute :enabled, :boolean => true
8
+ attribute :exclusive, :boolean => true
9
+ attribute :vpid, :boolean => true
10
+ attribute :nested_paging, :boolean => true
11
+ end
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 [HWVirtualization]
19
+ def populate_relationship(caller, imachine)
20
+ data = new(caller, imachine)
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, imachine)
32
+ write_attribute(:parent, parent)
33
+
34
+ # Load the attributes and mark the whole thing as existing
35
+ load_interface_attributes(imachine)
36
+ clear_dirty!
37
+ existing_record!
38
+ end
39
+
40
+ def get_property(interface, key)
41
+ interface.get_hw_virt_ex_property(key)
42
+ end
43
+
44
+ def set_property(interface, key, value)
45
+ interface.set_hw_virt_ex_property(key, value)
46
+ end
47
+
48
+ def validate
49
+ super
50
+
51
+ validates_inclusion_of :enabled, :exclusive, :vpid, :nested_paging, :in => [true, false]
52
+ end
53
+
54
+ def save
55
+ parent.with_open_session do |session|
56
+ machine = session.machine
57
+
58
+ # Save them
59
+ save_changed_interface_attributes(machine)
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,84 @@
1
+ module VirtualBox
2
+ # Used by the rest of the VirtualBox library to interface with
3
+ # the VirtualBox XPCOM library (VBoxXPCOMC). Most users will never need
4
+ # to interface with this class directly, except other to set the path to
5
+ # the `VBoxXPCOMC` lib.
6
+ #
7
+ # # Setting the Path to the VBoxXPCOMC Library
8
+ #
9
+ # This won't be necessary for 95% of users, and won't be necessary at all
10
+ # for windows users. But for unix users, the VirtualBox gem uses a dynamic
11
+ # library named `VBoxXPCOMC` to interface with VirtualBox. The gem does its
12
+ # best to guess the path to this gem based on the operating system ruby is
13
+ # running on, but in the case you get an error about it missing, you can
14
+ # easily set it:
15
+ #
16
+ # VirtualBox::Lib.lib_path = "/path/to/VBoxXPCOMC.so"
17
+ #
18
+ # **Windows users will never need to do this.**
19
+ #
20
+ class Lib
21
+ @@lib_path = nil
22
+ @@lib = nil
23
+
24
+ attr_reader :interface
25
+ attr_reader :virtualbox
26
+ attr_reader :session
27
+
28
+ class << self
29
+ # Resets the initialized library (if there is any). This is primarily only
30
+ # used for testing.
31
+ def reset!
32
+ @@lib = nil
33
+ end
34
+
35
+ # The singleton instance of Lib.
36
+ #
37
+ # @return [Lib]
38
+ def lib
39
+ @@lib ||= new(lib_path)
40
+ end
41
+
42
+ # Sets the path to the VBoxXPCOMC library which is created with any
43
+ # VirtualBox install. 90% of the time, this won't have to be set manually,
44
+ # and instead the gem will try to find it for you.
45
+ #
46
+ # @param [String] Full path to the VBoxXPCOMC library
47
+ def lib_path=(value)
48
+ @@lib_path = value.nil? ? value : File.expand_path(value)
49
+ end
50
+
51
+ # Returns the path to the virtual box library. If the path
52
+ # has not yet been set, it attempts to infer it based on the
53
+ # platform ruby is running on.
54
+ def lib_path
55
+ if @@lib_path.nil?
56
+ if Platform.mac?
57
+ @@lib_path = ["/Applications/VirtualBox.app/Contents/MacOS/VBoxXPCOMC.dylib"]
58
+ elsif Platform.linux?
59
+ @@lib_path = ["/opt/VirtualBox/VBoxXPCOMC.so", "/usr/lib/virtualbox/VBoxXPCOMC.so"]
60
+ elsif Platform.solaris?
61
+ @@lib_path = ["/opt/VirtualBox/amd64/VBoxXPCOMC.so", "/opt/VirtualBox/i386/VBoxXPCOMC.so"]
62
+ elsif Platform.windows?
63
+ @@lib_path = "Unknown"
64
+ else
65
+ @@lib_path = "Unknown"
66
+ end
67
+ end
68
+
69
+ @@lib_path
70
+ end
71
+ end
72
+
73
+ def initialize(lib_path)
74
+ if Platform.windows?
75
+ @interface = COM::MSCOMInterface.new
76
+ else
77
+ @interface = COM::FFIInterface.create(lib_path)
78
+ end
79
+
80
+ @virtualbox = @interface.virtualbox
81
+ @session = @interface.session
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,20 @@
1
+ module VirtualBox
2
+ # Represents the media registry within the global VirtualBox configuration.
3
+ class Media < AbstractModel
4
+ attribute :parent, :readonly => true
5
+ relationship :hard_drives, :HardDrive
6
+ relationship :dvds, :DVD
7
+
8
+ class << self
9
+ def populate_relationship(caller, lib)
10
+ new(caller, lib)
11
+ end
12
+ end
13
+
14
+ def initialize(parent, lib)
15
+ populate_attributes({ :parent => parent }, :ignore_relationships => true)
16
+ populate_relationship(:hard_drives, lib.virtualbox.hard_disks)
17
+ populate_relationship(:dvds, lib.virtualbox.dvd_images)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,145 @@
1
+ module VirtualBox
2
+ # Represents a medium object part of VirtualBox. A medium is a
3
+ # hard drive, DVD, floppy disk, etc. Each of these share common
4
+ # properties represented here.
5
+ class Medium < AbstractModel
6
+ include SubclassListing
7
+
8
+ attribute :uuid, :readonly => true, :property => :id
9
+ attribute :type, :readonly => true
10
+ attribute :description, :readonly => true
11
+ attribute :location, :readonly => true
12
+ attribute :state, :readonly => true, :property => :refresh_state
13
+ attribute :interface, :readonly => true, :property => false
14
+ relationship :children, :Medium, :lazy => true
15
+
16
+ class << self
17
+ # Populates a relationship with another model. Depending on the data sent
18
+ # through as the `media` parameter, this can either return a single value
19
+ # or an array of values. {Global}, for example, has a relationship of media,
20
+ # while a {MediumAttachment} has a relationship with a single medium.
21
+ #
22
+ # **This method typically won't be used except internally.**
23
+ def populate_relationship(caller, media)
24
+ if media.is_a?(Array)
25
+ # has many relationship
26
+ populate_array_relationship(caller, media)
27
+ else
28
+ # has one relationship
29
+ populate_single_relationship(caller, media)
30
+ end
31
+ end
32
+
33
+ # Populates a relationship which has many media.
34
+ #
35
+ # **This method typically won't be used except internally.**
36
+ #
37
+ # @return [Array<Medium>]
38
+ def populate_array_relationship(caller, media)
39
+ relation = Proxies::Collection.new(caller)
40
+
41
+ media.each do |medium|
42
+ # Skip media this class isn't interested in
43
+ next if device_type != :all && medium.device_type != device_type
44
+
45
+ # Wrap it up and add to the relationship
46
+ relation << new(medium)
47
+ end
48
+
49
+ relation
50
+ end
51
+
52
+ # Populates a relationship which has one medium. This method goes one step
53
+ # further and instantiates the proper class for the type of medium given.
54
+ # For example, given a `device_type` of `:hard_drive`, it would return a
55
+ # {HardDrive} object.
56
+ #
57
+ # **This method typically won't be used except internally.**
58
+ #
59
+ # @return [Medium]
60
+ def populate_single_relationship(caller, medium)
61
+ return nil if medium.nil?
62
+
63
+ subclasses.each do |subclass|
64
+ # Skip this class unless the device type matches
65
+ next unless subclass.device_type == medium.device_type
66
+
67
+ # Wrap it up and return it
68
+ return subclass.new(medium)
69
+ end
70
+
71
+ # If all else fails, just wrap it in a Medium
72
+ new(medium)
73
+ end
74
+
75
+ # Specifies the device type that a {Medium} class is interested in. This
76
+ # is `:all` on {Medium}, but is expected to be overridden by child classes.
77
+ # The value returned should be one of {COM::Interface::DeviceType}.
78
+ #
79
+ # @return [Symbol]
80
+ def device_type
81
+ :all
82
+ end
83
+ end
84
+
85
+ # Initializes a medium object, retrieving the attributes and information
86
+ # from the {COM::Interface::Medium} object given as the parameter. This initialization
87
+ # is done automatically by virtualbox when populating a relationship. Mediums should
88
+ # never be initialized manually.
89
+ #
90
+ # @param [COM::Interface::Medium] imedium
91
+ def initialize(imedium)
92
+ write_attribute(:interface, imedium)
93
+ initialize_attributes(imedium)
94
+ end
95
+
96
+ def initialize_attributes(imedium)
97
+ # First refresh the state (required for many attributes)
98
+ imedium.refresh_state
99
+
100
+ # Load interface attributes
101
+ load_interface_attributes(imedium)
102
+
103
+ # Clear dirtiness, since this should only be called initially and
104
+ # therefore shouldn't affect dirtiness
105
+ clear_dirty!
106
+
107
+ # But this is an existing record
108
+ existing_record!
109
+ end
110
+
111
+ def load_relationship(name)
112
+ # Populate children
113
+ populate_relationship(name, interface.children)
114
+ end
115
+
116
+ # Returns the basename of the images location (the file name +extension)
117
+ #
118
+ # @return [String]
119
+ def filename
120
+ File.basename(location.to_s)
121
+ end
122
+
123
+ # Destroys the medium, optionally also phsyically destroying the backing
124
+ # storage. This removes this medium from the VirtualBox media registry.
125
+ # In order to remove the medium, it must not be attached to any virtual
126
+ # machine. If it is, an exception of some sort will be raised.
127
+ # This action happens *immediately* when the method is called, and is not
128
+ # deferred to a save.
129
+ def destroy(destroy_backing=false)
130
+ if destroy_backing
131
+ destroy_storage
132
+ else
133
+ interface.close
134
+ end
135
+ end
136
+
137
+ # Destroys the backing store of the medium and the media registry. This is
138
+ # analagous to calling {#destroy} with the first parameter set to true. This
139
+ # method requires that the medium not be attached to any virtual machine
140
+ # (running or not).
141
+ def destroy_storage
142
+ interface.delete_storage.wait_for_completion(-1)
143
+ end
144
+ end
145
+ end