virtualbox 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (268) hide show
  1. data/.yardopts +0 -1
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/virtualbox/abstract_model/attributable.rb +1 -0
  5. data/lib/virtualbox/abstract_model/validatable.rb +133 -10
  6. data/lib/virtualbox/abstract_model.rb +3 -3
  7. data/lib/virtualbox/appliance.rb +5 -2
  8. data/lib/virtualbox/audio_adapter.rb +11 -3
  9. data/lib/virtualbox/bios.rb +10 -4
  10. data/lib/virtualbox/com/abstract_enum.rb +6 -5
  11. data/lib/virtualbox/com/abstract_implementer.rb +4 -2
  12. data/lib/virtualbox/com/abstract_interface.rb +6 -4
  13. data/lib/virtualbox/com/base_interface.rb +38 -0
  14. data/lib/virtualbox/com/ffi/interface.rb +14 -5
  15. data/lib/virtualbox/com/ffi/interfaces.rb +36 -32
  16. data/lib/virtualbox/com/ffi/util.rb +22 -4
  17. data/lib/virtualbox/com/ffi_interface.rb +39 -8
  18. data/lib/virtualbox/com/implementer/base.rb +2 -2
  19. data/lib/virtualbox/com/implementer/ffi.rb +55 -44
  20. data/lib/virtualbox/com/implementer/mscom.rb +2 -4
  21. data/lib/virtualbox/com/interface/3.1.x/appliance.rb +22 -0
  22. data/lib/virtualbox/com/interface/3.1.x/audio_adapter.rb +15 -0
  23. data/lib/virtualbox/com/interface/3.1.x/audio_controller_type.rb +11 -0
  24. data/lib/virtualbox/com/interface/3.1.x/audio_driver_type.rb +11 -0
  25. data/lib/virtualbox/com/interface/3.1.x/bios_boot_menu_mode.rb +11 -0
  26. data/lib/virtualbox/com/interface/3.1.x/bios_settings.rb +21 -0
  27. data/lib/virtualbox/com/interface/3.1.x/clipboard_mode.rb +11 -0
  28. data/lib/virtualbox/com/interface/3.1.x/console.rb +50 -0
  29. data/lib/virtualbox/com/interface/3.1.x/cpu_property_type.rb +11 -0
  30. data/lib/virtualbox/com/interface/3.1.x/device_type.rb +11 -0
  31. data/lib/virtualbox/com/interface/3.1.x/dhcp_server.rb +22 -0
  32. data/lib/virtualbox/com/interface/3.1.x/firmware_type.rb +11 -0
  33. data/lib/virtualbox/com/interface/3.1.x/guest_os_type.rb +23 -0
  34. data/lib/virtualbox/com/interface/3.1.x/host.rb +42 -0
  35. data/lib/virtualbox/com/interface/3.1.x/host_network_interface.rb +30 -0
  36. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_medium_type.rb +11 -0
  37. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_status.rb +11 -0
  38. data/lib/virtualbox/com/interface/3.1.x/host_network_interface_type.rb +11 -0
  39. data/lib/virtualbox/com/interface/3.1.x/host_usb_device.rb +13 -0
  40. data/lib/virtualbox/com/interface/3.1.x/host_usb_device_filter.rb +13 -0
  41. data/lib/virtualbox/com/interface/3.1.x/hw_virt_ex_property_type.rb +11 -0
  42. data/lib/virtualbox/com/interface/3.1.x/machine.rb +105 -0
  43. data/lib/virtualbox/com/interface/3.1.x/machine_state.rb +14 -0
  44. data/lib/virtualbox/com/interface/3.1.x/medium.rb +50 -0
  45. data/lib/virtualbox/com/interface/3.1.x/medium_attachment.rb +18 -0
  46. data/lib/virtualbox/com/interface/3.1.x/medium_format.rb +18 -0
  47. data/lib/virtualbox/com/interface/3.1.x/medium_state.rb +11 -0
  48. data/lib/virtualbox/com/interface/3.1.x/medium_type.rb +11 -0
  49. data/lib/virtualbox/com/interface/3.1.x/medium_variant.rb +11 -0
  50. data/lib/virtualbox/com/interface/3.1.x/network_adapter.rb +30 -0
  51. data/lib/virtualbox/com/interface/3.1.x/network_adapter_type.rb +11 -0
  52. data/lib/virtualbox/com/interface/3.1.x/network_attachment_type.rb +11 -0
  53. data/lib/virtualbox/com/interface/3.1.x/nsiexception.rb +23 -0
  54. data/lib/virtualbox/com/interface/3.1.x/nsisupports.rb +15 -0
  55. data/lib/virtualbox/com/interface/3.1.x/parallel_port.rb +17 -0
  56. data/lib/virtualbox/com/interface/3.1.x/port_mode.rb +11 -0
  57. data/lib/virtualbox/com/interface/3.1.x/progress.rb +63 -0
  58. data/lib/virtualbox/com/interface/3.1.x/serial_port.rb +19 -0
  59. data/lib/virtualbox/com/interface/3.1.x/session.rb +18 -0
  60. data/lib/virtualbox/com/interface/3.1.x/session_state.rb +11 -0
  61. data/lib/virtualbox/com/interface/3.1.x/session_type.rb +11 -0
  62. data/lib/virtualbox/com/interface/3.1.x/shared_folder.rb +17 -0
  63. data/lib/virtualbox/com/interface/3.1.x/snapshot.rb +20 -0
  64. data/lib/virtualbox/com/interface/3.1.x/storage_bus.rb +11 -0
  65. data/lib/virtualbox/com/interface/3.1.x/storage_controller.rb +23 -0
  66. data/lib/virtualbox/com/interface/3.1.x/storage_controller_type.rb +11 -0
  67. data/lib/virtualbox/com/interface/3.1.x/system_properties.rb +37 -0
  68. data/lib/virtualbox/com/interface/3.1.x/usb_controller.rb +20 -0
  69. data/lib/virtualbox/com/interface/3.1.x/usb_device.rb +24 -0
  70. data/lib/virtualbox/com/interface/3.1.x/usb_device_filter.rb +23 -0
  71. data/lib/virtualbox/com/interface/3.1.x/usb_device_filter_action.rb +11 -0
  72. data/lib/virtualbox/com/interface/3.1.x/usb_device_state.rb +11 -0
  73. data/lib/virtualbox/com/interface/3.1.x/virtual_box_error_info.rb +17 -0
  74. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description.rb +19 -0
  75. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_type.rb +14 -0
  76. data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_value_type.rb +11 -0
  77. data/lib/virtualbox/com/interface/3.1.x/virtualbox.rb +67 -0
  78. data/lib/virtualbox/com/interface/3.1.x/vrdp_auth_type.rb +11 -0
  79. data/lib/virtualbox/com/interface/3.1.x/vrdp_server.rb +19 -0
  80. data/lib/virtualbox/com/interface/3.2.x/appliance.rb +22 -0
  81. data/lib/virtualbox/com/interface/3.2.x/audio_adapter.rb +15 -0
  82. data/lib/virtualbox/com/interface/3.2.x/audio_controller_type.rb +11 -0
  83. data/lib/virtualbox/com/interface/3.2.x/audio_driver_type.rb +11 -0
  84. data/lib/virtualbox/com/interface/3.2.x/bios_boot_menu_mode.rb +11 -0
  85. data/lib/virtualbox/com/interface/3.2.x/bios_settings.rb +21 -0
  86. data/lib/virtualbox/com/interface/3.2.x/clipboard_mode.rb +11 -0
  87. data/lib/virtualbox/com/interface/3.2.x/console.rb +50 -0
  88. data/lib/virtualbox/com/interface/3.2.x/cpu_property_type.rb +11 -0
  89. data/lib/virtualbox/com/interface/3.2.x/device_type.rb +11 -0
  90. data/lib/virtualbox/com/interface/3.2.x/dhcp_server.rb +22 -0
  91. data/lib/virtualbox/com/interface/3.2.x/firmware_type.rb +11 -0
  92. data/lib/virtualbox/com/interface/3.2.x/guest.rb +13 -0
  93. data/lib/virtualbox/com/interface/3.2.x/guest_os_type.rb +33 -0
  94. data/lib/virtualbox/com/interface/3.2.x/host.rb +43 -0
  95. data/lib/virtualbox/com/interface/3.2.x/host_network_interface.rb +30 -0
  96. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_medium_type.rb +11 -0
  97. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_status.rb +11 -0
  98. data/lib/virtualbox/com/interface/3.2.x/host_network_interface_type.rb +11 -0
  99. data/lib/virtualbox/com/interface/3.2.x/host_usb_device.rb +13 -0
  100. data/lib/virtualbox/com/interface/3.2.x/host_usb_device_filter.rb +13 -0
  101. data/lib/virtualbox/com/interface/3.2.x/hw_virt_ex_property_type.rb +11 -0
  102. data/lib/virtualbox/com/interface/3.2.x/keyboard_hid_type.rb +11 -0
  103. data/lib/virtualbox/com/interface/3.2.x/machine.rb +118 -0
  104. data/lib/virtualbox/com/interface/3.2.x/machine_state.rb +14 -0
  105. data/lib/virtualbox/com/interface/3.2.x/medium.rb +51 -0
  106. data/lib/virtualbox/com/interface/3.2.x/medium_attachment.rb +18 -0
  107. data/lib/virtualbox/com/interface/3.2.x/medium_format.rb +18 -0
  108. data/lib/virtualbox/com/interface/3.2.x/medium_state.rb +11 -0
  109. data/lib/virtualbox/com/interface/3.2.x/medium_type.rb +11 -0
  110. data/lib/virtualbox/com/interface/3.2.x/medium_variant.rb +11 -0
  111. data/lib/virtualbox/com/interface/3.2.x/nat_alias_mode.rb +11 -0
  112. data/lib/virtualbox/com/interface/3.2.x/nat_engine.rb +27 -0
  113. data/lib/virtualbox/com/interface/3.2.x/nat_protocol.rb +11 -0
  114. data/lib/virtualbox/com/interface/3.2.x/network_adapter.rb +34 -0
  115. data/lib/virtualbox/com/interface/3.2.x/network_adapter_type.rb +11 -0
  116. data/lib/virtualbox/com/interface/3.2.x/network_attachment_type.rb +11 -0
  117. data/lib/virtualbox/com/interface/3.2.x/nsiexception.rb +23 -0
  118. data/lib/virtualbox/com/interface/3.2.x/nsisupports.rb +15 -0
  119. data/lib/virtualbox/com/interface/3.2.x/parallel_port.rb +17 -0
  120. data/lib/virtualbox/com/interface/3.2.x/pointing_hid_type.rb +11 -0
  121. data/lib/virtualbox/com/interface/3.2.x/port_mode.rb +11 -0
  122. data/lib/virtualbox/com/interface/3.2.x/progress.rb +63 -0
  123. data/lib/virtualbox/com/interface/3.2.x/serial_port.rb +19 -0
  124. data/lib/virtualbox/com/interface/3.2.x/session.rb +18 -0
  125. data/lib/virtualbox/com/interface/3.2.x/session_state.rb +11 -0
  126. data/lib/virtualbox/com/interface/3.2.x/session_type.rb +11 -0
  127. data/lib/virtualbox/com/interface/3.2.x/shared_folder.rb +17 -0
  128. data/lib/virtualbox/com/interface/3.2.x/snapshot.rb +20 -0
  129. data/lib/virtualbox/com/interface/3.2.x/storage_bus.rb +11 -0
  130. data/lib/virtualbox/com/interface/3.2.x/storage_controller.rb +24 -0
  131. data/lib/virtualbox/com/interface/3.2.x/storage_controller_type.rb +11 -0
  132. data/lib/virtualbox/com/interface/3.2.x/system_properties.rb +42 -0
  133. data/lib/virtualbox/com/interface/3.2.x/usb_controller.rb +21 -0
  134. data/lib/virtualbox/com/interface/3.2.x/usb_device.rb +24 -0
  135. data/lib/virtualbox/com/interface/3.2.x/usb_device_filter.rb +23 -0
  136. data/lib/virtualbox/com/interface/3.2.x/usb_device_filter_action.rb +11 -0
  137. data/lib/virtualbox/com/interface/3.2.x/usb_device_state.rb +11 -0
  138. data/lib/virtualbox/com/interface/3.2.x/virtual_box_error_info.rb +17 -0
  139. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description.rb +19 -0
  140. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_type.rb +14 -0
  141. data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_value_type.rb +11 -0
  142. data/lib/virtualbox/com/interface/3.2.x/virtualbox.rb +67 -0
  143. data/lib/virtualbox/com/interface/3.2.x/vrdp_auth_type.rb +11 -0
  144. data/lib/virtualbox/com/interface/3.2.x/vrdp_server.rb +21 -0
  145. data/lib/virtualbox/com/mscom_interface.rb +9 -4
  146. data/lib/virtualbox/com/nil_interface.rb +7 -0
  147. data/lib/virtualbox/com/util.rb +16 -2
  148. data/lib/virtualbox/com.rb +1 -1
  149. data/lib/virtualbox/cpu.rb +61 -0
  150. data/lib/virtualbox/dhcp_server.rb +89 -0
  151. data/lib/virtualbox/dvd.rb +2 -2
  152. data/lib/virtualbox/exceptions.rb +4 -0
  153. data/lib/virtualbox/ext/platform.rb +2 -2
  154. data/lib/virtualbox/extra_data.rb +5 -6
  155. data/lib/virtualbox/forwarded_port.rb +11 -7
  156. data/lib/virtualbox/global.rb +17 -6
  157. data/lib/virtualbox/hard_drive.rb +129 -66
  158. data/lib/virtualbox/host.rb +71 -0
  159. data/lib/virtualbox/host_network_interface.rb +137 -0
  160. data/lib/virtualbox/hw_virtualization.rb +12 -6
  161. data/lib/virtualbox/lib.rb +2 -2
  162. data/lib/virtualbox/media.rb +2 -2
  163. data/lib/virtualbox/medium.rb +10 -3
  164. data/lib/virtualbox/medium_attachment.rb +2 -2
  165. data/lib/virtualbox/network_adapter.rb +12 -4
  166. data/lib/virtualbox/proxies/collection.rb +26 -6
  167. data/lib/virtualbox/shared_folder.rb +22 -15
  168. data/lib/virtualbox/snapshot.rb +185 -0
  169. data/lib/virtualbox/storage_controller.rb +3 -3
  170. data/lib/virtualbox/system_properties.rb +1 -1
  171. data/lib/virtualbox/usb_controller.rb +8 -4
  172. data/lib/virtualbox/usb_device_filter.rb +74 -0
  173. data/lib/virtualbox/version.rb +12 -1
  174. data/lib/virtualbox/virtual_system_description.rb +4 -4
  175. data/lib/virtualbox/vm.rb +273 -64
  176. data/lib/virtualbox/vrdp_server.rb +59 -0
  177. data/test/test_helper.rb +7 -1
  178. data/test/virtualbox/abstract_model/attributable_test.rb +8 -0
  179. data/test/virtualbox/abstract_model/relatable_test.rb +5 -5
  180. data/test/virtualbox/abstract_model/validatable_test.rb +186 -3
  181. data/test/virtualbox/abstract_model_test.rb +3 -3
  182. data/test/virtualbox/appliance_test.rb +8 -1
  183. data/test/virtualbox/com/abstract_enum_test.rb +1 -0
  184. data/test/virtualbox/com/abstract_implementer_test.rb +4 -3
  185. data/test/virtualbox/com/abstract_interface_test.rb +3 -2
  186. data/test/virtualbox/com/ffi/interface_test.rb +4 -4
  187. data/test/virtualbox/com/ffi/util_test.rb +23 -1
  188. data/test/virtualbox/com/implementer/base_test.rb +4 -3
  189. data/test/virtualbox/com/implementer/ffi_test.rb +18 -10
  190. data/test/virtualbox/cpu_test.rb +103 -0
  191. data/test/virtualbox/dhcp_server_test.rb +165 -0
  192. data/test/virtualbox/extra_data_test.rb +4 -3
  193. data/test/virtualbox/forwarded_port_test.rb +17 -4
  194. data/test/virtualbox/hard_drive_test.rb +54 -5
  195. data/test/virtualbox/host_network_interface_test.rb +254 -0
  196. data/test/virtualbox/host_test.rb +94 -0
  197. data/test/virtualbox/network_adapter_test.rb +30 -1
  198. data/test/virtualbox/proxies/collection_test.rb +63 -21
  199. data/test/virtualbox/shared_folder_test.rb +16 -13
  200. data/test/virtualbox/snapshot_test.rb +231 -0
  201. data/test/virtualbox/storage_controller_test.rb +1 -1
  202. data/test/virtualbox/usb_controller_test.rb +7 -0
  203. data/test/virtualbox/usb_device_filter_test.rb +93 -0
  204. data/test/virtualbox/version_test.rb +13 -1
  205. data/test/virtualbox/vm_test.rb +245 -11
  206. data/test/virtualbox/vrdp_server_test.rb +83 -0
  207. data/virtualbox.gemspec +183 -97
  208. metadata +182 -96
  209. data/TODO +0 -9
  210. data/lib/virtualbox/com/interface/appliance.rb +0 -20
  211. data/lib/virtualbox/com/interface/audio_adapter.rb +0 -13
  212. data/lib/virtualbox/com/interface/audio_controller_type.rb +0 -9
  213. data/lib/virtualbox/com/interface/audio_driver_type.rb +0 -9
  214. data/lib/virtualbox/com/interface/bios_boot_menu_mode.rb +0 -9
  215. data/lib/virtualbox/com/interface/bios_settings.rb +0 -19
  216. data/lib/virtualbox/com/interface/clipboard_mode.rb +0 -9
  217. data/lib/virtualbox/com/interface/console.rb +0 -48
  218. data/lib/virtualbox/com/interface/cpu_property_type.rb +0 -9
  219. data/lib/virtualbox/com/interface/device_type.rb +0 -9
  220. data/lib/virtualbox/com/interface/dhcp_server.rb +0 -20
  221. data/lib/virtualbox/com/interface/firmware_type.rb +0 -9
  222. data/lib/virtualbox/com/interface/guest_os_type.rb +0 -21
  223. data/lib/virtualbox/com/interface/host.rb +0 -40
  224. data/lib/virtualbox/com/interface/host_network_interface.rb +0 -28
  225. data/lib/virtualbox/com/interface/host_network_interface_medium_type.rb +0 -9
  226. data/lib/virtualbox/com/interface/host_network_interface_status.rb +0 -9
  227. data/lib/virtualbox/com/interface/host_network_interface_type.rb +0 -9
  228. data/lib/virtualbox/com/interface/host_usb_device.rb +0 -11
  229. data/lib/virtualbox/com/interface/host_usb_device_filter.rb +0 -11
  230. data/lib/virtualbox/com/interface/hw_virt_ex_property_type.rb +0 -9
  231. data/lib/virtualbox/com/interface/machine.rb +0 -103
  232. data/lib/virtualbox/com/interface/machine_state.rb +0 -12
  233. data/lib/virtualbox/com/interface/medium.rb +0 -48
  234. data/lib/virtualbox/com/interface/medium_attachment.rb +0 -16
  235. data/lib/virtualbox/com/interface/medium_format.rb +0 -16
  236. data/lib/virtualbox/com/interface/medium_state.rb +0 -9
  237. data/lib/virtualbox/com/interface/medium_type.rb +0 -9
  238. data/lib/virtualbox/com/interface/medium_variant.rb +0 -9
  239. data/lib/virtualbox/com/interface/network_adapter.rb +0 -28
  240. data/lib/virtualbox/com/interface/network_adapter_type.rb +0 -9
  241. data/lib/virtualbox/com/interface/network_attachment_type.rb +0 -9
  242. data/lib/virtualbox/com/interface/nsiexception.rb +0 -21
  243. data/lib/virtualbox/com/interface/nsisupports.rb +0 -13
  244. data/lib/virtualbox/com/interface/parallel_port.rb +0 -15
  245. data/lib/virtualbox/com/interface/port_mode.rb +0 -9
  246. data/lib/virtualbox/com/interface/progress.rb +0 -58
  247. data/lib/virtualbox/com/interface/serial_port.rb +0 -17
  248. data/lib/virtualbox/com/interface/session.rb +0 -16
  249. data/lib/virtualbox/com/interface/session_state.rb +0 -9
  250. data/lib/virtualbox/com/interface/session_type.rb +0 -9
  251. data/lib/virtualbox/com/interface/shared_folder.rb +0 -15
  252. data/lib/virtualbox/com/interface/snapshot.rb +0 -18
  253. data/lib/virtualbox/com/interface/storage_bus.rb +0 -9
  254. data/lib/virtualbox/com/interface/storage_controller.rb +0 -21
  255. data/lib/virtualbox/com/interface/storage_controller_type.rb +0 -9
  256. data/lib/virtualbox/com/interface/system_properties.rb +0 -35
  257. data/lib/virtualbox/com/interface/usb_controller.rb +0 -18
  258. data/lib/virtualbox/com/interface/usb_device.rb +0 -22
  259. data/lib/virtualbox/com/interface/usb_device_filter.rb +0 -21
  260. data/lib/virtualbox/com/interface/usb_device_filter_action.rb +0 -9
  261. data/lib/virtualbox/com/interface/usb_device_state.rb +0 -9
  262. data/lib/virtualbox/com/interface/virtual_box_error_info.rb +0 -15
  263. data/lib/virtualbox/com/interface/virtual_system_description.rb +0 -17
  264. data/lib/virtualbox/com/interface/virtual_system_description_type.rb +0 -12
  265. data/lib/virtualbox/com/interface/virtual_system_description_value_type.rb +0 -9
  266. data/lib/virtualbox/com/interface/virtualbox.rb +0 -54
  267. data/lib/virtualbox/com/interface/vrdp_auth_type.rb +0 -9
  268. data/lib/virtualbox/com/interface/vrdp_server.rb +0 -17
data/.yardopts CHANGED
@@ -1,4 +1,3 @@
1
1
  -
2
2
  docs/GettingStarted.md
3
3
  docs/WhatsNew.md
4
- TODO
data/Rakefile CHANGED
@@ -32,7 +32,7 @@ begin
32
32
  t.options += ['--title', 'VirtualBox Ruby Library Documentation']
33
33
  end
34
34
  rescue LoadError
35
- puts "Yard not available. Install it with: gem install yard"
35
+ puts "Yard not available. Install it with: gem install yard bluecloth"
36
36
  end
37
37
 
38
38
  begin
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0
@@ -141,6 +141,7 @@ module VirtualBox
141
141
  attributes[name].merge!(options)
142
142
 
143
143
  # Create the method for reading this attribute
144
+ define_method("#{name}?") { read_attribute(name) } if options[:boolean]
144
145
  define_method(name) { read_attribute(name) }
145
146
 
146
147
  # Create the writer method for it unless the attribute is readonly,
@@ -3,41 +3,164 @@ module VirtualBox
3
3
  # Provides validation methods for a class. Unlike ActiveRecord,
4
4
  # validations are instance-level rather than class-level.
5
5
  module Validatable
6
+ # Returns the errors on a model. The structure of this is a hash, keyed
7
+ # by the field name. The value of each member in the hash is an array of
8
+ # error messages.
9
+ #
10
+ # @return [Hash]
6
11
  def errors
7
12
  @errors ||= {}
8
13
  end
9
14
 
15
+ # Returns the errors on a specific field. This returns nil if there are
16
+ # no errors, otherwise it returns an array of error messages.
17
+ def errors_on(field)
18
+ @errors[field.to_sym]
19
+ end
20
+
21
+ # Adds an error to a field. The error is a message.
10
22
  def add_error(field, error)
11
23
  errors[field] ||= []
12
24
  errors[field].push(error)
13
25
  end
14
26
 
27
+ # Clears all the errors from a model.
15
28
  def clear_errors
16
29
  @errors = {}
17
30
  end
18
31
 
32
+ def full_error_messages
33
+ full_error_messages = Array.new
34
+ errors.each do |field_name, messages|
35
+ messages.each do |message|
36
+ human_field_name = field_name.to_s.gsub('_', ' ').capitalize
37
+ full_error_messages << "#{human_field_name} #{message}"
38
+ end
39
+ end
40
+ full_error_messages
41
+ end
42
+
43
+ # This method calls the validate method on the model (which any subclass
44
+ # is expected to implement), and then checks that the validations didn't
45
+ # add any errors.
46
+ #
47
+ # @return [Boolean]
19
48
  def valid?
20
49
  validate
21
50
  errors.empty?
22
51
  end
23
52
 
24
- # Subclasses should override this method.
53
+ # Subclasses should override this method. Validation can be done any
54
+ # way an implementer feels. Helper methods such as {#validates_presence_of},
55
+ # {#validates_inclusion_of}, etc. exist, but they're use isn't required.
56
+ # {#add_error} can be used to add an error to any field. By convention
57
+ # this method should return `true` or `false` to signal any errors.
58
+ #
59
+ # @return [Boolean]
25
60
  def validate
26
61
  true
27
62
  end
28
63
 
29
- def validates_presence_of(field)
30
- if field.is_a?(Array)
31
- field.map { |v| validates_presence_of(v) }.all? { |v| v == true }
32
- else
64
+ # Validates the presence (non-emptiness) of a field or fields. This
65
+ # validation fails if the specified fields are either blank ("") or
66
+ # nil.
67
+ #
68
+ # Additionally, a custom error message can be specified:
69
+ #
70
+ # validates_presence_of :foo, :bar
71
+ # validates_presence_of :baz, :message => "must not be blank!"
72
+ #
73
+ # @return [Boolean]
74
+ def validates_presence_of(*fields)
75
+ options = __validates_extract_options(fields, {
76
+ :message => "can't be blank."
77
+ })
78
+
79
+ fields.collect { |field|
80
+ value = send(field)
81
+ if value.nil? || value.to_s.empty?
82
+ add_error(field, options[:message])
83
+ false
84
+ else
85
+ true
86
+ end
87
+ }.compact.all? { |v| v == true }
88
+ end
89
+
90
+ # Validates the format of a field with a given regular expression.
91
+ #
92
+ # validates_format_of :foo, :with => /\d+/
93
+ #
94
+ def validates_format_of(*fields)
95
+ options = __validates_extract_options(fields, {
96
+ :with => nil,
97
+ :message => "is not properly formatted."
98
+ })
99
+
100
+ fields.collect { |field|
33
101
  value = send(field)
34
- if value.nil? || value == ""
35
- add_error(field, "must not be blank.")
36
- return false
102
+ # Use validates_presence_of if you need it to be set
103
+ next if value.nil? || value.to_s.empty?
104
+ if options[:with] && value =~ options[:with]
105
+ true
37
106
  else
38
- return true
107
+ add_error(field, options[:message])
108
+ false
39
109
  end
40
- end
110
+ }.compact.all? { |v| v == true }
111
+ end
112
+
113
+ # Validates the numericality of a specific field.
114
+ #
115
+ # validates_numericality_of :field
116
+ #
117
+ def validates_numericality_of(*fields)
118
+ options = __validates_extract_options(fields, {
119
+ :message => "is not a number."
120
+ })
121
+
122
+ fields.collect { |field|
123
+ value = send(field)
124
+ # Use validates_presence_of if you need it to be set
125
+ next if value.nil? || value.to_s.empty?
126
+ if value.is_a?(Numeric) && value.to_s =~ /^\d$/
127
+ true
128
+ else
129
+ add_error(field, options[:message])
130
+ false
131
+ end
132
+ }.compact.all? { |v| v == true }
133
+ end
134
+
135
+ # Validates that a field's value is within a specific range,
136
+ # array, etc.
137
+ #
138
+ # validates_inclusion_of :foo, :in => [1,2,3]
139
+ # validates_inclusion_of :bar, :in => (1..6)
140
+ #
141
+ def validates_inclusion_of(*fields)
142
+ options = __validates_extract_options(fields, {
143
+ :in => nil,
144
+ :message => "value %s is not included in the list."
145
+ })
146
+
147
+ fields.collect { |field|
148
+ value = send(field)
149
+ # Use validates_presence_of if you need it to be set
150
+ return if value.nil? || value.to_s.empty?
151
+ if options[:in] && options[:in].include?(value)
152
+ true
153
+ else
154
+ message = options[:message] % value
155
+ add_error(field, message)
156
+ false
157
+ end
158
+ }.compact.all? { |v| v == true }
159
+ end
160
+
161
+ # Internal method. Should never be called.
162
+ def __validates_extract_options(fields, defaults)
163
+ defaults.merge(fields.last.is_a?(Hash) ? fields.pop : {})
41
164
  end
42
165
  end
43
166
  end
@@ -20,7 +20,7 @@ module VirtualBox
20
20
  include Relatable
21
21
  include Validatable
22
22
 
23
- class <<self
23
+ class << self
24
24
  # Returns whether or not the class should be reloaded.
25
25
  #
26
26
  # @return [Boolean]
@@ -237,7 +237,7 @@ module VirtualBox
237
237
 
238
238
  self.class.attributes.each do |name, options|
239
239
  value = read_attribute(name)
240
- value = if value.is_a?(AbstractModel) || value.is_a?(COM::AbstractInterface)
240
+ value = if value.is_a?(AbstractModel) || value.is_a?(COM::AbstractInterface) || value.is_a?(Proxies::Collection)
241
241
  "#<#{value.class.name}>"
242
242
  else
243
243
  value.inspect
@@ -253,4 +253,4 @@ module VirtualBox
253
253
  "#<#{self.class} #{values.sort.join(", ")}>".strip
254
254
  end
255
255
  end
256
- end
256
+ end
@@ -52,8 +52,11 @@ module VirtualBox
52
52
  end
53
53
 
54
54
  # Adds a VM to the appliance
55
- def add_machine(vm)
56
- vm.interface.export(interface)
55
+ def add_machine(vm, options = {})
56
+ sys_desc = vm.interface.export(interface)
57
+ options.each do |key, value|
58
+ sys_desc.add_description(key, value, value)
59
+ end
57
60
  end
58
61
  end
59
62
  end
@@ -1,11 +1,11 @@
1
1
  module VirtualBox
2
2
  class AudioAdapter < AbstractModel
3
3
  attribute :parent, :readonly => true, :property => false
4
- attribute :enabled
4
+ attribute :enabled, :boolean => true
5
5
  attribute :audio_controller
6
6
  attribute :audio_driver
7
7
 
8
- class <<self
8
+ class << self
9
9
  # Populates a relationship with another model.
10
10
  #
11
11
  # **This method typically won't be used except internally.**
@@ -32,6 +32,14 @@ module VirtualBox
32
32
  existing_record!
33
33
  end
34
34
 
35
+ def validate
36
+ super
37
+
38
+ validates_inclusion_of :enabled, :in => [true, false]
39
+ validates_inclusion_of :audio_controller, :in => COM::Util.versioned_interface(:AudioControllerType).map
40
+ validates_inclusion_of :audio_driver, :in => COM::Util.versioned_interface(:AudioDriverType).map
41
+ end
42
+
35
43
  def save
36
44
  parent.with_open_session do |session|
37
45
  machine = session.machine
@@ -41,4 +49,4 @@ module VirtualBox
41
49
  end
42
50
  end
43
51
  end
44
- end
52
+ end
@@ -2,10 +2,10 @@ module VirtualBox
2
2
  # Represents the BIOS settings of a {VM}.
3
3
  class BIOS < AbstractModel
4
4
  attribute :parent, :readonly => true, :property => false
5
- attribute :acpi_enabled
6
- attribute :io_apic_enabled
5
+ attribute :acpi_enabled, :boolean => true
6
+ attribute :io_apic_enabled, :boolean => true
7
7
 
8
- class <<self
8
+ class << self
9
9
  # Populates a relationship with another model.
10
10
  #
11
11
  # **This method typically won't be used except internally.**
@@ -32,6 +32,12 @@ module VirtualBox
32
32
  existing_record!
33
33
  end
34
34
 
35
+ def validate
36
+ super
37
+
38
+ validates_inclusion_of :acpi_enabled, :io_apic_enabled, :in => [true, false]
39
+ end
40
+
35
41
  def save
36
42
  parent.with_open_session do |session|
37
43
  machine = session.machine
@@ -41,4 +47,4 @@ module VirtualBox
41
47
  end
42
48
  end
43
49
  end
44
- end
50
+ end
@@ -5,13 +5,14 @@ module VirtualBox
5
5
  class AbstractEnum
6
6
  extend Enumerable
7
7
 
8
- class <<self
8
+ class << self
9
9
  # Defines the mapping of int => symbol for the given Enum.
10
10
  # The parameter to this can be an Array or Hash or anything which
11
11
  # can be indexed with `[]` and an integer and returns a value of
12
- # some sort.
13
- def map(value)
14
- @map = value
12
+ # some sort. If value is left nil, it will return the current mapping
13
+ def map(value = nil)
14
+ @map = value if value
15
+ @map
15
16
  end
16
17
 
17
18
  # Returns the symbol associatd with the given key
@@ -39,4 +40,4 @@ module VirtualBox
39
40
  end
40
41
  end
41
42
  end
42
- end
43
+ end
@@ -8,6 +8,7 @@ module VirtualBox
8
8
  # Windows (COM) and Unix (XPCOM), which have different calling conventions.
9
9
  class AbstractImplementer
10
10
  attr_reader :interface
11
+ attr_reader :lib
11
12
 
12
13
  # Initializes an implementer for the given {AbstractInterface}. The
13
14
  # implementor's other methods, such as {read_property} or
@@ -15,8 +16,9 @@ module VirtualBox
15
16
  # the interface.
16
17
  #
17
18
  # @param [AbstractInterface] interface
18
- def initialize(interface)
19
+ def initialize(interface, lib)
19
20
  @interface = interface
21
+ @lib = lib
20
22
  end
21
23
 
22
24
  # Read a property of the interface.
@@ -40,4 +42,4 @@ module VirtualBox
40
42
  end
41
43
  end
42
44
  end
43
- end
45
+ end
@@ -33,8 +33,9 @@ module VirtualBox
33
33
  #
34
34
  class AbstractInterface
35
35
  attr_reader :implementer
36
+ attr_reader :lib
36
37
 
37
- class <<self
38
+ class << self
38
39
  # Adds a function to the interface with the given name and function
39
40
  # spec. The spec determines the arguments required, the order they
40
41
  # are required in, and any out-arguments.
@@ -108,9 +109,10 @@ module VirtualBox
108
109
  end
109
110
 
110
111
  # Initializes the interface with the given implementer
111
- def initialize(implementer, *args)
112
+ def initialize(implementer, lib, *args)
112
113
  # Instantiate the implementer and set it
113
- @implementer = implementer.new(self, *args)
114
+ @lib = lib
115
+ @implementer = implementer.new(self, lib, *args)
114
116
  end
115
117
 
116
118
  # Reads a property with the given name by calling the read_property
@@ -162,4 +164,4 @@ module VirtualBox
162
164
  end
163
165
  end
164
166
  end
165
- end
167
+ end
@@ -0,0 +1,38 @@
1
+ require 'thread'
2
+
3
+ module VirtualBox
4
+ module COM
5
+ class BaseInterface
6
+ def initialize
7
+ @task_queue = Queue.new
8
+
9
+ @lib_thread = Thread.new(@task_queue) do |queue|
10
+ while true
11
+ task, result = queue.pop
12
+
13
+ # Run the task, set the return value, and run the waiter
14
+ # which will simply finish that thread
15
+ result << task.call
16
+ end
17
+ end
18
+ end
19
+
20
+ # This function takes a block and runs it on a thread which is
21
+ # guaranteed to be the same since the first time this is
22
+ # called. This is required by the MSCOM implementation and is a
23
+ # good idea in general so that multiple API calls aren't firing
24
+ # at once.
25
+ def on_lib_thread(&task)
26
+ # If we're already on the lib thread, then just run it!
27
+ return task.call if Thread.current == @lib_thread
28
+
29
+ # Add the task to the queue
30
+ result = Queue.new
31
+ @task_queue << [task, result]
32
+
33
+ # Pop the result off of the result queue
34
+ result.pop
35
+ end
36
+ end
37
+ end
38
+ end
@@ -8,11 +8,20 @@ module VirtualBox
8
8
  # FFI specific types
9
9
  NSRESULT_TYPE = :uint
10
10
 
11
+ # Creates all the FFI classes for a given version.
12
+ def self.for_version(version, &block)
13
+ @__module = Module.new
14
+ ::VirtualBox::COM::Util.set_interface_version(version)
15
+ const_set(::VirtualBox::COM::Util.version_const, @__module)
16
+ instance_eval(&block)
17
+ @__module = Kernel
18
+ end
19
+
11
20
  # Returns a Class which creates an FFI interface to the specified
12
21
  # com interface and potentially a parent class as well.
13
22
  def self.create_interface(interface, parent=nil)
14
23
  klass = Class.new(Interface)
15
- const_set(interface, klass)
24
+ @__module.const_set(interface, klass)
16
25
  klass.com_interface(interface, parent)
17
26
  klass
18
27
  end
@@ -30,7 +39,7 @@ module VirtualBox
30
39
  attr_reader :vtbl_parent
31
40
  attr_reader :vtbl
32
41
 
33
- class <<self
42
+ class << self
34
43
  # Sets up the args to the FFI::Struct `layout` method. This
35
44
  # method defines all the callbacks necessary for working with
36
45
  # FFI and also sets up any layout args to send in. The way the
@@ -39,7 +48,7 @@ module VirtualBox
39
48
  # put into the struct in the order defined in the {AbstractInterface}.
40
49
  def com_interface(interface, parent=nil)
41
50
  # Create the parent class and vtbl class
42
- interface = ::VirtualBox::COM::Interface.const_get(interface)
51
+ interface = ::VirtualBox::COM::Util.versioned_interface(interface)
43
52
  define_vtbl_parent_for_interface(interface)
44
53
  define_vtbl_for_interface(interface, parent)
45
54
  end
@@ -79,7 +88,7 @@ module VirtualBox
79
88
  def define_interface_parent(parent)
80
89
  return if parent.nil?
81
90
 
82
- parent_klass = Object.module_eval("::VirtualBox::COM::FFI::#{parent}::Vtbl")
91
+ parent_klass = Object.module_eval("::VirtualBox::COM::FFI::#{::VirtualBox::COM::Util.version_const}::#{parent}::Vtbl")
83
92
  layout_args << [:superklass, parent_klass]
84
93
  end
85
94
 
@@ -138,4 +147,4 @@ module VirtualBox
138
147
  end
139
148
  end
140
149
  end
141
- end
150
+ end
@@ -4,39 +4,43 @@ module VirtualBox
4
4
  # Creates all the interfaces for the FFI implementation. Eventually this
5
5
  # file should be conditionally loaded based on OS, so that Windows users
6
6
  # don't have to wait for all this translation to occur.
7
- create_interface(:NSISupports)
8
- create_interface(:NSIException, :NSISupports)
9
- create_interface(:Session, :NSISupports)
10
- create_interface(:VirtualBox, :NSISupports)
11
- create_interface(:Appliance, :NSISupports)
12
- create_interface(:AudioAdapter, :NSISupports)
13
- create_interface(:BIOSSettings, :NSISupports)
14
- create_interface(:Console, :NSISupports)
15
- create_interface(:DHCPServer, :NSISupports)
16
- create_interface(:GuestOSType, :NSISupports)
17
- create_interface(:Host, :NSISupports)
18
- create_interface(:HostNetworkInterface, :NSISupports)
19
- create_interface(:Machine, :NSISupports)
20
- create_interface(:Medium, :NSISupports)
21
- create_interface(:MediumAttachment, :NSISupports)
22
- create_interface(:MediumFormat, :NSISupports)
23
- create_interface(:NetworkAdapter, :NSISupports)
24
- create_interface(:ParallelPort, :NSISupports)
25
- create_interface(:Progress, :NSISupports)
26
- create_interface(:SerialPort, :NSISupports)
27
- create_interface(:SharedFolder, :NSISupports)
28
- create_interface(:Snapshot, :NSISupports)
29
- create_interface(:StorageController, :NSISupports)
30
- create_interface(:SystemProperties, :NSISupports)
31
- create_interface(:USBController, :NSISupports)
32
- create_interface(:USBDevice, :NSISupports)
33
- create_interface(:USBDeviceFilter, :NSISupports)
34
- create_interface(:VirtualBoxErrorInfo, :NSIException)
35
- create_interface(:VirtualSystemDescription, :NSISupports)
36
- create_interface(:VRDPServer, :NSISupports)
7
+ def self.setup(version)
8
+ for_version version do
9
+ create_interface(:NSISupports)
10
+ create_interface(:NSIException, :NSISupports)
11
+ create_interface(:Session, :NSISupports)
12
+ create_interface(:VirtualBox, :NSISupports)
13
+ create_interface(:Appliance, :NSISupports)
14
+ create_interface(:AudioAdapter, :NSISupports)
15
+ create_interface(:BIOSSettings, :NSISupports)
16
+ create_interface(:Console, :NSISupports)
17
+ create_interface(:DHCPServer, :NSISupports)
18
+ create_interface(:GuestOSType, :NSISupports)
19
+ create_interface(:Host, :NSISupports)
20
+ create_interface(:HostNetworkInterface, :NSISupports)
21
+ create_interface(:Machine, :NSISupports)
22
+ create_interface(:Medium, :NSISupports)
23
+ create_interface(:MediumAttachment, :NSISupports)
24
+ create_interface(:MediumFormat, :NSISupports)
25
+ create_interface(:NetworkAdapter, :NSISupports)
26
+ create_interface(:ParallelPort, :NSISupports)
27
+ create_interface(:Progress, :NSISupports)
28
+ create_interface(:SerialPort, :NSISupports)
29
+ create_interface(:SharedFolder, :NSISupports)
30
+ create_interface(:Snapshot, :NSISupports)
31
+ create_interface(:StorageController, :NSISupports)
32
+ create_interface(:SystemProperties, :NSISupports)
33
+ create_interface(:USBController, :NSISupports)
34
+ create_interface(:USBDevice, :NSISupports)
35
+ create_interface(:USBDeviceFilter, :NSISupports)
36
+ create_interface(:VirtualBoxErrorInfo, :NSIException)
37
+ create_interface(:VirtualSystemDescription, :NSISupports)
38
+ create_interface(:VRDPServer, :NSISupports)
37
39
 
38
- create_interface(:HostUSBDevice, :USBDevice)
39
- create_interface(:HostUSBDeviceFilter, :USBDeviceFilter)
40
+ create_interface(:HostUSBDevice, :USBDevice)
41
+ create_interface(:HostUSBDeviceFilter, :USBDeviceFilter)
42
+ end
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -5,7 +5,22 @@ module VirtualBox
5
5
  # with the FFI interface. These functions range from converting a
6
6
  # function spec to a FFI parameter list to dereferencing pointers.
7
7
  class Util
8
- class <<self
8
+ class << self
9
+ # Finds and returns the `COM::Interface` class associated with the type.
10
+ # If the class does not exist, a `NameError` will be raised.
11
+ #
12
+ # @return [Class]
13
+ def interface_klass(type)
14
+ ::VirtualBox::COM::Util.versioned_interface(type)
15
+ end
16
+
17
+ # Finds the versioned interface for the FFI module.
18
+ #
19
+ # @return [Class]
20
+ def versioned_interface(interface)
21
+ ::VirtualBox::COM::FFI.const_get(::VirtualBox::COM::Util.version_const).const_get(interface)
22
+ end
23
+
9
24
  # Converts a function spec from {AbstractInterface} to an FFI
10
25
  # function spec. This handles custom types (unicode strings,
11
26
  # arrays, and out-parameters) and will return a perfectly valid
@@ -33,7 +48,7 @@ module VirtualBox
33
48
  elsif item.to_s[0,1] == item.to_s[0,1].upcase
34
49
  begin
35
50
  # Try to get the class from the interfaces
36
- interface = COM::Interface.const_get(item.to_sym)
51
+ interface = interface_klass(item.to_sym)
37
52
 
38
53
  if interface.superclass == COM::AbstractInterface
39
54
  :pointer
@@ -85,7 +100,10 @@ module VirtualBox
85
100
  "vdi" => "VDI",
86
101
  "cpu" => "CPU",
87
102
  "ram" => "RAM",
88
- "hdd" => "HDD"
103
+ "hdd" => "HDD",
104
+ "rtc" => "RTC",
105
+ "utc" => "UTC",
106
+ "io" => "IO"
89
107
  }
90
108
 
91
109
  parts = string.to_s.split(/_/).collect do |part|
@@ -98,4 +116,4 @@ module VirtualBox
98
116
  end
99
117
  end
100
118
  end
101
- end
119
+ end