velir_virtualbox 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (350) 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 +37 -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 +63 -0
  56. data/lib/virtualbox/com/ffi/util.rb +121 -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 +381 -0
  61. data/lib/virtualbox/com/implementer/mscom.rb +189 -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/interface/4.0.x/access_mode.rb +11 -0
  190. data/lib/virtualbox/com/interface/4.0.x/appliance.rb +23 -0
  191. data/lib/virtualbox/com/interface/4.0.x/audio_adapter.rb +15 -0
  192. data/lib/virtualbox/com/interface/4.0.x/audio_controller_type.rb +11 -0
  193. data/lib/virtualbox/com/interface/4.0.x/audio_driver_type.rb +11 -0
  194. data/lib/virtualbox/com/interface/4.0.x/auth_type.rb +11 -0
  195. data/lib/virtualbox/com/interface/4.0.x/bios_boot_menu_mode.rb +11 -0
  196. data/lib/virtualbox/com/interface/4.0.x/bios_settings.rb +21 -0
  197. data/lib/virtualbox/com/interface/4.0.x/cleanup_mode.rb +12 -0
  198. data/lib/virtualbox/com/interface/4.0.x/clipboard_mode.rb +11 -0
  199. data/lib/virtualbox/com/interface/4.0.x/console.rb +50 -0
  200. data/lib/virtualbox/com/interface/4.0.x/cpu_property_type.rb +11 -0
  201. data/lib/virtualbox/com/interface/4.0.x/device_type.rb +11 -0
  202. data/lib/virtualbox/com/interface/4.0.x/dhcp_server.rb +22 -0
  203. data/lib/virtualbox/com/interface/4.0.x/event_source.rb +13 -0
  204. data/lib/virtualbox/com/interface/4.0.x/fault_tolerance_state.rb +11 -0
  205. data/lib/virtualbox/com/interface/4.0.x/firmware_type.rb +11 -0
  206. data/lib/virtualbox/com/interface/4.0.x/guest.rb +13 -0
  207. data/lib/virtualbox/com/interface/4.0.x/guest_os_type.rb +33 -0
  208. data/lib/virtualbox/com/interface/4.0.x/host.rb +43 -0
  209. data/lib/virtualbox/com/interface/4.0.x/host_network_interface.rb +30 -0
  210. data/lib/virtualbox/com/interface/4.0.x/host_network_interface_medium_type.rb +11 -0
  211. data/lib/virtualbox/com/interface/4.0.x/host_network_interface_status.rb +11 -0
  212. data/lib/virtualbox/com/interface/4.0.x/host_network_interface_type.rb +11 -0
  213. data/lib/virtualbox/com/interface/4.0.x/host_usb_device.rb +13 -0
  214. data/lib/virtualbox/com/interface/4.0.x/host_usb_device_filter.rb +13 -0
  215. data/lib/virtualbox/com/interface/4.0.x/hw_virt_ex_property_type.rb +12 -0
  216. data/lib/virtualbox/com/interface/4.0.x/keyboard_hid_type.rb +11 -0
  217. data/lib/virtualbox/com/interface/4.0.x/lock_type.rb +11 -0
  218. data/lib/virtualbox/com/interface/4.0.x/machine.rb +132 -0
  219. data/lib/virtualbox/com/interface/4.0.x/machine_state.rb +14 -0
  220. data/lib/virtualbox/com/interface/4.0.x/medium.rb +53 -0
  221. data/lib/virtualbox/com/interface/4.0.x/medium_attachment.rb +18 -0
  222. data/lib/virtualbox/com/interface/4.0.x/medium_format.rb +18 -0
  223. data/lib/virtualbox/com/interface/4.0.x/medium_state.rb +11 -0
  224. data/lib/virtualbox/com/interface/4.0.x/medium_type.rb +11 -0
  225. data/lib/virtualbox/com/interface/4.0.x/medium_variant.rb +11 -0
  226. data/lib/virtualbox/com/interface/4.0.x/nat_alias_mode.rb +11 -0
  227. data/lib/virtualbox/com/interface/4.0.x/nat_engine.rb +27 -0
  228. data/lib/virtualbox/com/interface/4.0.x/nat_protocol.rb +11 -0
  229. data/lib/virtualbox/com/interface/4.0.x/network_adapter.rb +35 -0
  230. data/lib/virtualbox/com/interface/4.0.x/network_adapter_type.rb +11 -0
  231. data/lib/virtualbox/com/interface/4.0.x/network_attachment_type.rb +11 -0
  232. data/lib/virtualbox/com/interface/4.0.x/nsiexception.rb +23 -0
  233. data/lib/virtualbox/com/interface/4.0.x/nsisupports.rb +15 -0
  234. data/lib/virtualbox/com/interface/4.0.x/parallel_port.rb +17 -0
  235. data/lib/virtualbox/com/interface/4.0.x/pointing_hid_type.rb +11 -0
  236. data/lib/virtualbox/com/interface/4.0.x/port_mode.rb +11 -0
  237. data/lib/virtualbox/com/interface/4.0.x/progress.rb +64 -0
  238. data/lib/virtualbox/com/interface/4.0.x/serial_port.rb +19 -0
  239. data/lib/virtualbox/com/interface/4.0.x/session.rb +18 -0
  240. data/lib/virtualbox/com/interface/4.0.x/session_state.rb +11 -0
  241. data/lib/virtualbox/com/interface/4.0.x/session_type.rb +11 -0
  242. data/lib/virtualbox/com/interface/4.0.x/shared_folder.rb +17 -0
  243. data/lib/virtualbox/com/interface/4.0.x/snapshot.rb +20 -0
  244. data/lib/virtualbox/com/interface/4.0.x/storage_bus.rb +11 -0
  245. data/lib/virtualbox/com/interface/4.0.x/storage_controller.rb +24 -0
  246. data/lib/virtualbox/com/interface/4.0.x/storage_controller_type.rb +11 -0
  247. data/lib/virtualbox/com/interface/4.0.x/system_properties.rb +42 -0
  248. data/lib/virtualbox/com/interface/4.0.x/usb_controller.rb +21 -0
  249. data/lib/virtualbox/com/interface/4.0.x/usb_device.rb +24 -0
  250. data/lib/virtualbox/com/interface/4.0.x/usb_device_filter.rb +23 -0
  251. data/lib/virtualbox/com/interface/4.0.x/usb_device_filter_action.rb +11 -0
  252. data/lib/virtualbox/com/interface/4.0.x/usb_device_state.rb +11 -0
  253. data/lib/virtualbox/com/interface/4.0.x/virtual_box_error_info.rb +17 -0
  254. data/lib/virtualbox/com/interface/4.0.x/virtual_system_description.rb +19 -0
  255. data/lib/virtualbox/com/interface/4.0.x/virtual_system_description_type.rb +14 -0
  256. data/lib/virtualbox/com/interface/4.0.x/virtual_system_description_value_type.rb +11 -0
  257. data/lib/virtualbox/com/interface/4.0.x/virtualbox.rb +50 -0
  258. data/lib/virtualbox/com/interface/4.0.x/vrde_server.rb +23 -0
  259. data/lib/virtualbox/com/mscom_interface.rb +44 -0
  260. data/lib/virtualbox/com/nil_interface.rb +7 -0
  261. data/lib/virtualbox/com/util.rb +32 -0
  262. data/lib/virtualbox/cpu.rb +61 -0
  263. data/lib/virtualbox/dhcp_server.rb +89 -0
  264. data/lib/virtualbox/dvd.rb +27 -0
  265. data/lib/virtualbox/exceptions.rb +39 -0
  266. data/lib/virtualbox/ext/byte_normalizer.rb +17 -0
  267. data/lib/virtualbox/ext/glob_loader.rb +35 -0
  268. data/lib/virtualbox/ext/logger.rb +38 -0
  269. data/lib/virtualbox/ext/platform.rb +31 -0
  270. data/lib/virtualbox/ext/subclass_listing.rb +24 -0
  271. data/lib/virtualbox/extra_data.rb +127 -0
  272. data/lib/virtualbox/forwarded_port.rb +222 -0
  273. data/lib/virtualbox/global.rb +96 -0
  274. data/lib/virtualbox/hard_drive.rb +246 -0
  275. data/lib/virtualbox/host.rb +71 -0
  276. data/lib/virtualbox/host_network_interface.rb +137 -0
  277. data/lib/virtualbox/hw_virtualization.rb +64 -0
  278. data/lib/virtualbox/lib.rb +84 -0
  279. data/lib/virtualbox/media.rb +20 -0
  280. data/lib/virtualbox/medium.rb +145 -0
  281. data/lib/virtualbox/medium_attachment.rb +61 -0
  282. data/lib/virtualbox/nat_engine.rb +71 -0
  283. data/lib/virtualbox/nat_forwarded_port.rb +171 -0
  284. data/lib/virtualbox/network_adapter.rb +166 -0
  285. data/lib/virtualbox/proxies/collection.rb +57 -0
  286. data/lib/virtualbox/shared_folder.rb +220 -0
  287. data/lib/virtualbox/snapshot.rb +185 -0
  288. data/lib/virtualbox/storage_controller.rb +160 -0
  289. data/lib/virtualbox/system_properties.rb +73 -0
  290. data/lib/virtualbox/usb_controller.rb +59 -0
  291. data/lib/virtualbox/usb_device_filter.rb +74 -0
  292. data/lib/virtualbox/version.rb +36 -0
  293. data/lib/virtualbox/virtual_system_description.rb +47 -0
  294. data/lib/virtualbox/vm.rb +649 -0
  295. data/lib/virtualbox/vrde_server.rb +57 -0
  296. data/test/test_helper.rb +18 -0
  297. data/test/virtualbox/abstract_model/attributable_test.rb +269 -0
  298. data/test/virtualbox/abstract_model/dirty_test.rb +83 -0
  299. data/test/virtualbox/abstract_model/interface_attributes_test.rb +194 -0
  300. data/test/virtualbox/abstract_model/relatable_test.rb +348 -0
  301. data/test/virtualbox/abstract_model/validatable_test.rb +308 -0
  302. data/test/virtualbox/abstract_model/version_matcher_test.rb +41 -0
  303. data/test/virtualbox/abstract_model_test.rb +462 -0
  304. data/test/virtualbox/appliance_test.rb +159 -0
  305. data/test/virtualbox/audio_adapter_test.rb +83 -0
  306. data/test/virtualbox/bios_test.rb +83 -0
  307. data/test/virtualbox/com/abstract_enum_test.rb +49 -0
  308. data/test/virtualbox/com/abstract_implementer_test.rb +40 -0
  309. data/test/virtualbox/com/abstract_interface_test.rb +140 -0
  310. data/test/virtualbox/com/ffi/interface_test.rb +249 -0
  311. data/test/virtualbox/com/ffi/util_test.rb +108 -0
  312. data/test/virtualbox/com/ffi_interface_test.rb +42 -0
  313. data/test/virtualbox/com/implementer/base_test.rb +38 -0
  314. data/test/virtualbox/com/implementer/ffi_test.rb +527 -0
  315. data/test/virtualbox/com/implementer/mscom_test.rb +247 -0
  316. data/test/virtualbox/com/mscom_interface_test.rb +17 -0
  317. data/test/virtualbox/com/util_test.rb +17 -0
  318. data/test/virtualbox/cpu_test.rb +103 -0
  319. data/test/virtualbox/dhcp_server_test.rb +165 -0
  320. data/test/virtualbox/dvd_test.rb +28 -0
  321. data/test/virtualbox/ext/byte_normalizer_test.rb +34 -0
  322. data/test/virtualbox/ext/platform_test.rb +50 -0
  323. data/test/virtualbox/ext/subclass_listing_test.rb +25 -0
  324. data/test/virtualbox/extra_data_test.rb +155 -0
  325. data/test/virtualbox/forwarded_port_test.rb +286 -0
  326. data/test/virtualbox/global_test.rb +46 -0
  327. data/test/virtualbox/hard_drive_test.rb +141 -0
  328. data/test/virtualbox/host_network_interface_test.rb +255 -0
  329. data/test/virtualbox/host_test.rb +94 -0
  330. data/test/virtualbox/hw_virtualization_test.rb +103 -0
  331. data/test/virtualbox/lib_test.rb +93 -0
  332. data/test/virtualbox/medium_attachment_test.rb +147 -0
  333. data/test/virtualbox/medium_test.rb +192 -0
  334. data/test/virtualbox/nat_engine_test.rb +106 -0
  335. data/test/virtualbox/nat_forwarded_port_test.rb +222 -0
  336. data/test/virtualbox/network_adapter_test.rb +191 -0
  337. data/test/virtualbox/proxies/collection_test.rb +102 -0
  338. data/test/virtualbox/shared_folder_test.rb +219 -0
  339. data/test/virtualbox/snapshot_test.rb +231 -0
  340. data/test/virtualbox/storage_controller_test.rb +197 -0
  341. data/test/virtualbox/system_properties_test.rb +87 -0
  342. data/test/virtualbox/usb_controller_test.rb +112 -0
  343. data/test/virtualbox/usb_device_filter_test.rb +93 -0
  344. data/test/virtualbox/version_test.rb +59 -0
  345. data/test/virtualbox/virtual_system_description_test.rb +61 -0
  346. data/test/virtualbox/vm_test.rb +633 -0
  347. data/test/virtualbox/vrde_server_test.rb +83 -0
  348. data/test/virtualbox_test.rb +11 -0
  349. data/virtualbox.gemspec +24 -0
  350. metadata +464 -0
@@ -0,0 +1,171 @@
1
+ module VirtualBox
2
+ # When a VM uses NAT as its NIC type, VirtualBox acts like its
3
+ # own private router for all virtual machines. Because of this,
4
+ # the host machine can't access services within the guest machine.
5
+ # To get around this, NAT supports port forwarding, which allows the
6
+ # guest machine services to be forwarded to some port on the host
7
+ # machine. Port forwarding is done completely through {ExtraData}, but
8
+ # is a complicated enough procedure that this class was made to
9
+ # faciliate it.
10
+ #
11
+ # **Note:** After changing any forwarded ports, the entire VirtualBox
12
+ # process must be restarted completely for them to take effect. When
13
+ # working with the ruby library, this isn't so much of an issue, but
14
+ # if you have any VMs running, they must all be shut down and restarted.
15
+ #
16
+ # # Adding a new Forwarded Port
17
+ #
18
+ # Since forwarded ports rely on being part of a {VM}, we're going to
19
+ # assume that `vm` points to a {VM} which has already been found.
20
+ #
21
+ # port = VirtualBox::NATForwardedPort.new
22
+ # port.name = "apache" # This can be anything
23
+ # port.guestport = 80
24
+ # port.hostport = 8080
25
+ # vm.network_adapters[0].nat_driver.forwarded_ports << port
26
+ # port.save # Or vm.save
27
+ #
28
+ # # Modifying an Existing Forwarded Port
29
+ #
30
+ # This is assuming that `vm` is a local variable storing a {VM} object
31
+ # which has already been found.
32
+ #
33
+ # ports = vm.network_adapters[0].nat_driver.forwarded_ports
34
+ # ports.first.hostport = 1919
35
+ # vm.save
36
+ #
37
+ # # Deleting a Forwarded Port
38
+ #
39
+ # To delete a forwarded port, you simply destroy it like any other model:
40
+ #
41
+ # ports = vm.network_adapters[0].nat_driver.forwarded_ports
42
+ # ports.first.destroy
43
+ #
44
+ # # Attributes and Relationships
45
+ #
46
+ # Properties of the model are exposed using standard ruby instance
47
+ # methods which are generated on the fly. Because of this, they are not listed
48
+ # below as available instance methods.
49
+ #
50
+ # These attributes can be accessed and modified via standard ruby-style
51
+ # `instance.attribute` and `instance.attribute=` methods. The attributes are
52
+ # listed below.
53
+ #
54
+ # Relationships are also accessed like attributes but can't be set. Instead,
55
+ # they are typically references to other objects such as an {AttachedDevice} which
56
+ # in turn have their own attributes which can be modified.
57
+ #
58
+ # ## Attributes
59
+ #
60
+ # This is copied directly from the class header, but lists all available
61
+ # attributes. If you don't understand what this means, read {Attributable}.
62
+ #
63
+ # attribute :parent, :readonly => true
64
+ # attribute :name
65
+ # attribute :protocol, :default => "TCP"
66
+ # attribute :guestport
67
+ # attribute :hostport
68
+ #
69
+ class NATForwardedPort < AbstractModel
70
+ attribute :parent, :readonly => true, :property => false
71
+ attribute :parent_collection, :readonly => true, :property => false
72
+ attribute :name
73
+ attribute :protocol, :default => :tcp
74
+ attribute :guestport
75
+ attribute :hostport
76
+
77
+ class << self
78
+ # Populates a relationship with another model.
79
+ #
80
+ # **This method typically won't be used except internally.**
81
+ #
82
+ # @return [Array<NATForwardedPort>]
83
+ def populate_relationship(caller, interface)
84
+ relation = Proxies::Collection.new(caller)
85
+
86
+ interface.redirects.each do |key, value|
87
+ parts = key.split(",")
88
+
89
+ port = new({
90
+ :parent => caller,
91
+ :parent_collection => relation,
92
+ :name => parts[0],
93
+ :protocol => COM::Util.versioned_interface(:NATProtocol).index(parts[1]),
94
+ :guestport => parts[5].to_i,
95
+ :hostport => parts[3].to_i
96
+ })
97
+
98
+ port.existing_record!
99
+
100
+ relation.push(port)
101
+ end
102
+
103
+ relation
104
+ end
105
+
106
+ # Saves the relationship. This simply calls {#save} on every
107
+ # member of the relationship.
108
+ #
109
+ # **This method typically won't be used except internally.**
110
+ def save_relationship(caller, data)
111
+ data.dup.each do |fp|
112
+ fp.save
113
+ end
114
+ end
115
+ end
116
+
117
+ # @param [Hash] data The initial attributes to populate.
118
+ def initialize(data={})
119
+ super()
120
+ populate_attributes(data) if !data.empty?
121
+ end
122
+
123
+ # Validates a forwarded port.
124
+ def validate
125
+ super
126
+
127
+ validates_presence_of :parent
128
+ validates_presence_of :name
129
+ validates_presence_of :guestport
130
+ validates_presence_of :hostport
131
+ end
132
+
133
+ # Saves the forwarded port.
134
+ #
135
+ # @return [Boolean] True if command was successful, false otherwise.
136
+ def save
137
+ return true if !new_record? && !changed?
138
+ raise Exceptions::ValidationFailedException.new(errors) if !valid?
139
+ destroy(false) if !new_record?
140
+
141
+ parent.modify_engine do |nat|
142
+ nat.add_redirect(name, protocol, "", hostport, "", guestport)
143
+ end
144
+
145
+ clear_dirty!
146
+ existing_record!
147
+ true
148
+ end
149
+
150
+ # Destroys the port forwarding mapping.
151
+ #
152
+ # @return [Boolean] True if command was successful, false otherwise.
153
+ def destroy(update_collection=true)
154
+ return if new_record?
155
+ previous_name = name_changed? ? name_was : name
156
+ parent.modify_engine do |nat|
157
+ nat.remove_redirect(previous_name)
158
+ end
159
+ parent_collection.delete(self, true) if parent_collection && update_collection
160
+ new_record!
161
+ true
162
+ end
163
+
164
+ # Relationship callback when added to a collection. This is automatically
165
+ # called by any relationship collection when this object is added.
166
+ def added_to_relationship(proxy)
167
+ write_attribute(:parent, proxy.parent)
168
+ write_attribute(:parent_collection, proxy)
169
+ end
170
+ end
171
+ end
@@ -0,0 +1,166 @@
1
+ module VirtualBox
2
+ # Represents a single NIC (Network Interface Card) of a virtual machine.
3
+ #
4
+ # # Create a Network Adapter
5
+ #
6
+ # There is no need to have the ability to create a network adapter,
7
+ # since when creating a VM from scratch, all eight network adapter
8
+ # slots are created, but set to `attachment_type` `nil`. Simply
9
+ # modify the adapter you're interested in and save.
10
+ #
11
+ #
12
+ # # Editing a Network Adapter
13
+ #
14
+ # Network adapters can be modified directly in their relationship to other
15
+ # virtual machines. When {VM#save} is called, it will also save any
16
+ # changes to its relationships. Additionally, you may call {#save}
17
+ # on the relationship itself.
18
+ #
19
+ # vm = VirtualBox::VM.find("foo")
20
+ # vm.network_adapters[0].macaddress = @new_mac_address
21
+ # vm.save
22
+ #
23
+ # # Destroying a Network Adapter
24
+ #
25
+ # Network adapters can not actually be "destroyed" but can be
26
+ # removed by setting the `attachment_type` to `nil` and saving.
27
+ #
28
+ # # Attributes
29
+ #
30
+ # Properties of the model are exposed using standard ruby instance
31
+ # methods which are generated on the fly. Because of this, they are not listed
32
+ # below as available instance methods.
33
+ #
34
+ # These attributes can be accessed and modified via standard ruby-style
35
+ # `instance.attribute` and `instance.attribute=` methods. The attributes are
36
+ # listed below. If you aren't sure what this means or you can't understand
37
+ # why the below is listed, please read {Attributable}.
38
+ #
39
+ # attribute :slot, :readonly => true
40
+ # attribute :enabled, :boolean => true
41
+ # attribute :attachment_type
42
+ # attribute :adapter_type
43
+ # attribute :mac_address
44
+ # attribute :cable_connected, :boolean => true
45
+ # attribute :nat_network
46
+ # attribute :internal_network
47
+ # attribute :host_interface
48
+ # attribute :interface, :readonly => true, :property => false
49
+ #
50
+ class NetworkAdapter < AbstractModel
51
+ attribute :parent, :readonly => true, :property => false
52
+ attribute :slot, :readonly => true
53
+ attribute :enabled, :boolean => true
54
+ attribute :attachment_type
55
+ attribute :adapter_type
56
+ attribute :mac_address
57
+ attribute :cable_connected, :boolean => true
58
+ attribute :nat_network
59
+ attribute :internal_network
60
+ attribute :host_interface
61
+ attribute :interface, :readonly => true, :property => false
62
+ relationship :nat_driver, :NATEngine, :lazy => true
63
+
64
+ class << self
65
+ # Populates the nic relationship for anything which is related to it.
66
+ #
67
+ # **This method typically won't be used except internally.**
68
+ #
69
+ # @return [Array<Nic>]
70
+ def populate_relationship(caller, imachine)
71
+ relation = Proxies::Collection.new(caller)
72
+
73
+ # Get the count of network adapters
74
+ count = imachine.parent.system_properties.network_adapter_count
75
+
76
+ count.times do |i|
77
+ relation << new(caller, imachine.get_network_adapter(i))
78
+ end
79
+
80
+ relation
81
+ end
82
+
83
+ # Saves the relationship. This simply calls {#save} on every
84
+ # member of the relationship.
85
+ #
86
+ # **This method typically won't be used except internally.**
87
+ def save_relationship(caller, items)
88
+ items.each do |item|
89
+ item.save
90
+ end
91
+ end
92
+ end
93
+
94
+ def initialize(caller, inetwork)
95
+ super()
96
+
97
+ initialize_attributes(caller, inetwork)
98
+ end
99
+
100
+ # Initializes the attributes of an existing shared folder.
101
+ def initialize_attributes(parent, inetwork)
102
+ # Set the parent and interface
103
+ write_attribute(:parent, parent)
104
+ write_attribute(:interface, inetwork)
105
+
106
+ # Load the interface attributes
107
+ load_interface_attributes(inetwork)
108
+
109
+ # Clear dirtiness, since this should only be called initially and
110
+ # therefore shouldn't affect dirtiness
111
+ clear_dirty!
112
+
113
+ # But this is an existing record
114
+ existing_record!
115
+ end
116
+
117
+ def load_relationship(name)
118
+ # Lazy load the NAT driver. This is only supported by VirtualBox
119
+ # 3.2 and higher. This restriction is checked when the
120
+ # relationship attribute is accessed.
121
+ populate_relationship(:nat_driver, interface.nat_driver)
122
+ end
123
+
124
+ # Gets the host interface object associated with the class if it
125
+ # exists.
126
+ def host_interface_object
127
+ VirtualBox::Global.global.host.network_interfaces.find do |ni|
128
+ ni.name == host_interface
129
+ end
130
+ end
131
+
132
+ # Save a network adapter.
133
+ def save
134
+ modify_adapter do |adapter|
135
+ save_attachment_type(adapter)
136
+ save_changed_interface_attributes(adapter)
137
+ save_relationships
138
+ end
139
+ end
140
+
141
+ # Saves the attachment type. This should never be called directly. Instead,
142
+ # {save} should be called, which will call this method if appropriate.
143
+ def save_attachment_type(adapter)
144
+ return unless attachment_type_changed?
145
+
146
+ mapping = {
147
+ :nat => :attach_to_nat,
148
+ :bridged => :attach_to_bridged_interface,
149
+ :internal => :attach_to_internal_network,
150
+ :host_only => :attach_to_host_only_interface
151
+ }
152
+
153
+ adapter.send(mapping[attachment_type])
154
+ clear_dirty!(:attachment_type)
155
+ end
156
+
157
+ # Opens a session, yields the adapter and then saves the machine at
158
+ # the end
159
+ def modify_adapter
160
+ parent_machine.with_open_session do |session|
161
+ machine = session.machine
162
+ yield machine.get_network_adapter(slot)
163
+ end
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,57 @@
1
+ module VirtualBox
2
+ module Proxies
3
+ # A relationship which can be described as a collection, which
4
+ # is a set of items.
5
+ class Collection < Array
6
+ attr_reader :parent
7
+
8
+ def initialize(parent, item_klass=nil, *args)
9
+ super()
10
+
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
30
+ end
31
+
32
+ # Returns the errors associated with all the items in this
33
+ # collection
34
+ def errors
35
+ collect do |item|
36
+ item.respond_to?(:errors) ? item.errors : {}
37
+ end
38
+ end
39
+
40
+ def <<(item)
41
+ item.added_to_relationship(self) if item.respond_to?(:added_to_relationship)
42
+ push(item)
43
+ end
44
+
45
+ def clear
46
+ each do |item|
47
+ delete(item)
48
+ end
49
+ end
50
+
51
+ def delete(item, no_callback=false)
52
+ return unless super(item)
53
+ item.removed_from_relationship(self) if !no_callback && item.respond_to?(:removed_from_relationship)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,220 @@
1
+ module VirtualBox
2
+ # Represents a shared folder in VirtualBox. In VirtualBox, shared folders are a
3
+ # method for basically "symlinking" a folder on the guest system to a folder which
4
+ # exists on the host system. This allows for sharing of files across the virtual
5
+ # machine.
6
+ #
7
+ # **Note:** Whenever modifying shared folders on a VM, the changes won't take
8
+ # effect until a _cold reboot_ occurs. This means actually closing the virtual
9
+ # machine _completely_, then restarting it. You can't just hit "Start > Restart"
10
+ # or do a `sudo reboot`. It doesn't work that way!
11
+ #
12
+ # # Getting Shared Folders
13
+ #
14
+ # All shared folders are attached to a {VM} object, by definition. Therefore, to
15
+ # get a list of the shared folders, first {VM.find find} the VM you need, then
16
+ # use the `shared_folders` relationship to access an array of the shared folders.
17
+ # With this array, you can create, modify, update, and delete the shared folders
18
+ # for that virtual machine.
19
+ #
20
+ # # Creating a Shared Folder
21
+ #
22
+ # **This whole section will assume you already looked up a {VM} and assigned it to
23
+ # a local variable named `vm`.**
24
+ #
25
+ # With a VM found, creating a shared folder is just a few lines of code:
26
+ #
27
+ # folder = VirtualBox::SharedFolder.new
28
+ # folder.name = "desktop-images"
29
+ # folder.hostpath = File.expand_path("~/Desktop/images")
30
+ # vm.shared_folders << folder
31
+ # folder.save # Or you can call vm.save, which works too!
32
+ #
33
+ # # Modifying an Existing Shared Folder
34
+ #
35
+ # **This whole section will assume you already looked up a {VM} and assigned it to
36
+ # a local variable named `vm`.**
37
+ #
38
+ # Nothing tricky here: You treat existing shared folder objects just as if they
39
+ # were new ones. Assign a new name and/or a new path, then save.
40
+ #
41
+ # folder = vm.shared_folders.first
42
+ # folder.name = "rufus"
43
+ # folder.save # Or vm.save
44
+ #
45
+ # **Note**: The VirtualBox-saavy will know that VirtualBox doesn't actually
46
+ # expose a way to edit shared folders. Under the hood, the virtualbox ruby
47
+ # library is actually deleting the old shared folder, then creating a new
48
+ # one with the new details. This shouldn't affect the way anything works for
49
+ # the VM itself.
50
+ #
51
+ # # Deleting a Shared Folder
52
+ #
53
+ # **This whole section will assume you already looked up a {VM} and assigned it to
54
+ # a local variable named `vm`.**
55
+ #
56
+ # folder = vm.shared_folder.first
57
+ # folder.destroy
58
+ #
59
+ # Poof! It'll be gone. This is usually the place where I warn you about this
60
+ # being non-reversable, but since no _data_ was actually destroyed, this is
61
+ # not too risky. You could always just recreate the shared folder with the
62
+ # same name and path and it'll be like nothing happened.
63
+ #
64
+ # # Attributes and Relationships
65
+ #
66
+ # Properties of the model are exposed using standard ruby instance
67
+ # methods which are generated on the fly. Because of this, they are not listed
68
+ # below as available instance methods.
69
+ #
70
+ # These attributes can be accessed and modified via standard ruby-style
71
+ # `instance.attribute` and `instance.attribute=` methods. The attributes are
72
+ # listed below.
73
+ #
74
+ # Relationships are also accessed like attributes but can't be set. Instead,
75
+ # they are typically references to other objects such as an {AttachedDevice} which
76
+ # in turn have their own attributes which can be modified.
77
+ #
78
+ # ## Attributes
79
+ #
80
+ # This is copied directly from the class header, but lists all available
81
+ # attributes. If you don't understand what this means, read {Attributable}.
82
+ #
83
+ # attribute :parent, :readonly => :readonly
84
+ # attribute :name
85
+ # attribute :hostpath
86
+ #
87
+ class SharedFolder < AbstractModel
88
+ attribute :parent, :readonly => true, :property => false
89
+ attribute :parent_collection, :readonly => true, :property => false
90
+ attribute :name
91
+ attribute :host_path
92
+ attribute :writable, :default => true, :boolean => true
93
+ attribute :accessible, :readonly => true, :boolean => true
94
+
95
+ class << self
96
+ # Populates the shared folder relationship for anything which is related to it.
97
+ #
98
+ # **This method typically won't be used except internally.**
99
+ #
100
+ # @return [Array<SharedFolder>]
101
+ def populate_relationship(caller, imachine)
102
+ relation = Proxies::Collection.new(caller)
103
+
104
+ imachine.shared_folders.each do |ishared|
105
+ relation << new(ishared)
106
+ end
107
+
108
+ relation
109
+ end
110
+
111
+ # Saves the relationship. This simply calls {#save} on every
112
+ # member of the relationship.
113
+ #
114
+ # **This method typically won't be used except internally.**
115
+ def save_relationship(caller, items)
116
+ items.dup.each do |item|
117
+ item.save
118
+ end
119
+ end
120
+ end
121
+
122
+ # @overload initialize(data={})
123
+ # Creates a new SharedFolder which is a new record. This
124
+ # should be attached to a VM and saved.
125
+ # @param [Hash] data (optional) A hash which contains initial attribute
126
+ # values for the SharedFolder.
127
+ # @overload initialize(interface)
128
+ # Creates an SharedFolder for a relationship. **This should
129
+ # never be called except internally.**
130
+ # @param [Object] caller The parent
131
+ # @param [Hash] data A hash of data which must be used
132
+ # to extract the relationship data.
133
+ def initialize(data=nil)
134
+ super()
135
+
136
+ if data
137
+ initialize_attributes(data)
138
+ end
139
+ end
140
+
141
+ # Initializes the attributes of an existing shared folder.
142
+ def initialize_attributes(ishared)
143
+ # Load the interface attributes
144
+ load_interface_attributes(ishared)
145
+
146
+ # Clear dirtiness, since this should only be called initially and
147
+ # therefore shouldn't affect dirtiness
148
+ clear_dirty!
149
+
150
+ # But this is an existing record
151
+ existing_record!
152
+ end
153
+
154
+ # Validates a shared folder.
155
+ def validate
156
+ super
157
+
158
+ validates_presence_of :parent
159
+ validates_presence_of :name
160
+ validates_presence_of :host_path
161
+ end
162
+
163
+ # Saves or creates a shared folder.
164
+ def save
165
+ return true if !new_record? && !changed?
166
+ raise Exceptions::ValidationFailedException.new(errors) if !valid?
167
+
168
+ if !new_record?
169
+ # If its not a new record, any changes will require a new shared
170
+ # folder to be created, so we first destroy it then recreate it.
171
+ destroy(false)
172
+ end
173
+
174
+ create
175
+ end
176
+
177
+ # Creates a new shared folder. This method should not be called directly.
178
+ # Instead, {save} should always be called, which will do the right thing.
179
+ def create
180
+ return unless new_record?
181
+
182
+ parent_machine.with_open_session do |session|
183
+ machine = session.machine
184
+ machine.create_shared_folder(name, host_path, writable)
185
+ end
186
+
187
+ existing_record!
188
+ clear_dirty!
189
+ end
190
+
191
+ # Relationship callback when added to a collection. This is automatically
192
+ # called by any relationship collection when this object is added.
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
201
+ end
202
+
203
+ # Destroys the shared folder. This doesn't actually delete the folder
204
+ # from the host system. Instead, it simply removes the mapping to the
205
+ # virtual machine, meaning it will no longer be possible to mount it
206
+ # from within the virtual machine.
207
+ def destroy(update_collection=true)
208
+ parent.with_open_session do |session|
209
+ machine = session.machine
210
+ machine.remove_shared_folder(name)
211
+ end
212
+
213
+ # Remove it from it's parent collection
214
+ parent_collection.delete(self, true) if parent_collection && update_collection
215
+
216
+ # Mark as a new record so if it is saved again, it will create it
217
+ new_record!
218
+ end
219
+ end
220
+ end