bbrowning-virtualbox 0.7.6.dev
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.
- data/.gitignore +8 -0
- data/.yardopts +3 -0
- data/Gemfile +16 -0
- data/LICENSE +19 -0
- data/Rakefile +33 -0
- data/Readme.md +70 -0
- data/docs/GettingStarted.md +196 -0
- data/docs/WhatsNew.md +12 -0
- data/features/README.md +33 -0
- data/features/global.feature +19 -0
- data/features/global_extra_data.feature +27 -0
- data/features/step_definitions/abstract_model_steps.rb +39 -0
- data/features/step_definitions/extra_data_steps.rb +36 -0
- data/features/step_definitions/global_steps.rb +29 -0
- data/features/step_definitions/nat_engine_steps.rb +76 -0
- data/features/step_definitions/network_adapter_steps.rb +38 -0
- data/features/step_definitions/shared_folder_steps.rb +76 -0
- data/features/step_definitions/snapshot_steps.rb +74 -0
- data/features/step_definitions/storage_controller_steps.rb +16 -0
- data/features/step_definitions/virtualbox_steps.rb +17 -0
- data/features/step_definitions/vm_steps.rb +50 -0
- data/features/support/env.rb +61 -0
- data/features/support/helpers.rb +38 -0
- data/features/support/hooks.rb +30 -0
- data/features/support/ordered_hash.rb +49 -0
- data/features/support/vboxmanage.rb +191 -0
- data/features/version.feature +16 -0
- data/features/vm.feature +13 -0
- data/features/vm_bios.feature +29 -0
- data/features/vm_cpu.feature +29 -0
- data/features/vm_extra_data.feature +35 -0
- data/features/vm_hw_virt.feature +29 -0
- data/features/vm_nat_engine.feature +57 -0
- data/features/vm_network_adapters.feature +27 -0
- data/features/vm_shared_folders.feature +42 -0
- data/features/vm_snapshots.feature +29 -0
- data/features/vm_storage_controllers.feature +11 -0
- data/lib/virtualbox.rb +11 -0
- data/lib/virtualbox/abstract_model.rb +281 -0
- data/lib/virtualbox/abstract_model/attributable.rb +290 -0
- data/lib/virtualbox/abstract_model/dirty.rb +177 -0
- data/lib/virtualbox/abstract_model/interface_attributes.rb +98 -0
- data/lib/virtualbox/abstract_model/relatable.rb +332 -0
- data/lib/virtualbox/abstract_model/validatable.rb +167 -0
- data/lib/virtualbox/abstract_model/version_matcher.rb +35 -0
- data/lib/virtualbox/appliance.rb +62 -0
- data/lib/virtualbox/audio_adapter.rb +52 -0
- data/lib/virtualbox/bios.rb +50 -0
- data/lib/virtualbox/com.rb +23 -0
- data/lib/virtualbox/com/abstract_enum.rb +43 -0
- data/lib/virtualbox/com/abstract_implementer.rb +45 -0
- data/lib/virtualbox/com/abstract_interface.rb +167 -0
- data/lib/virtualbox/com/base_interface.rb +38 -0
- data/lib/virtualbox/com/ffi/interface.rb +150 -0
- data/lib/virtualbox/com/ffi/interfaces.rb +54 -0
- data/lib/virtualbox/com/ffi/util.rb +119 -0
- data/lib/virtualbox/com/ffi/vboxxpcomc.rb +31 -0
- data/lib/virtualbox/com/ffi_interface.rb +96 -0
- data/lib/virtualbox/com/implementer/base.rb +59 -0
- data/lib/virtualbox/com/implementer/ffi.rb +361 -0
- data/lib/virtualbox/com/implementer/mscom.rb +175 -0
- data/lib/virtualbox/com/implementer/nil.rb +10 -0
- data/lib/virtualbox/com/interface/3.1.x/access_mode.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/appliance.rb +22 -0
- data/lib/virtualbox/com/interface/3.1.x/audio_adapter.rb +15 -0
- data/lib/virtualbox/com/interface/3.1.x/audio_controller_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/audio_driver_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/bios_boot_menu_mode.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/bios_settings.rb +21 -0
- data/lib/virtualbox/com/interface/3.1.x/clipboard_mode.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/console.rb +50 -0
- data/lib/virtualbox/com/interface/3.1.x/cpu_property_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/device_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/dhcp_server.rb +22 -0
- data/lib/virtualbox/com/interface/3.1.x/firmware_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/guest_os_type.rb +23 -0
- data/lib/virtualbox/com/interface/3.1.x/host.rb +42 -0
- data/lib/virtualbox/com/interface/3.1.x/host_network_interface.rb +30 -0
- data/lib/virtualbox/com/interface/3.1.x/host_network_interface_medium_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/host_network_interface_status.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/host_network_interface_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/host_usb_device.rb +13 -0
- data/lib/virtualbox/com/interface/3.1.x/host_usb_device_filter.rb +13 -0
- data/lib/virtualbox/com/interface/3.1.x/hw_virt_ex_property_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/machine.rb +105 -0
- data/lib/virtualbox/com/interface/3.1.x/machine_state.rb +14 -0
- data/lib/virtualbox/com/interface/3.1.x/medium.rb +50 -0
- data/lib/virtualbox/com/interface/3.1.x/medium_attachment.rb +18 -0
- data/lib/virtualbox/com/interface/3.1.x/medium_format.rb +18 -0
- data/lib/virtualbox/com/interface/3.1.x/medium_state.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/medium_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/medium_variant.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/network_adapter.rb +30 -0
- data/lib/virtualbox/com/interface/3.1.x/network_adapter_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/network_attachment_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/nsiexception.rb +23 -0
- data/lib/virtualbox/com/interface/3.1.x/nsisupports.rb +15 -0
- data/lib/virtualbox/com/interface/3.1.x/parallel_port.rb +17 -0
- data/lib/virtualbox/com/interface/3.1.x/port_mode.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/progress.rb +63 -0
- data/lib/virtualbox/com/interface/3.1.x/serial_port.rb +19 -0
- data/lib/virtualbox/com/interface/3.1.x/session.rb +18 -0
- data/lib/virtualbox/com/interface/3.1.x/session_state.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/session_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/shared_folder.rb +17 -0
- data/lib/virtualbox/com/interface/3.1.x/snapshot.rb +20 -0
- data/lib/virtualbox/com/interface/3.1.x/storage_bus.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/storage_controller.rb +23 -0
- data/lib/virtualbox/com/interface/3.1.x/storage_controller_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/system_properties.rb +37 -0
- data/lib/virtualbox/com/interface/3.1.x/usb_controller.rb +20 -0
- data/lib/virtualbox/com/interface/3.1.x/usb_device.rb +24 -0
- data/lib/virtualbox/com/interface/3.1.x/usb_device_filter.rb +23 -0
- data/lib/virtualbox/com/interface/3.1.x/usb_device_filter_action.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/usb_device_state.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/virtual_box_error_info.rb +17 -0
- data/lib/virtualbox/com/interface/3.1.x/virtual_system_description.rb +19 -0
- data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_type.rb +14 -0
- data/lib/virtualbox/com/interface/3.1.x/virtual_system_description_value_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/virtualbox.rb +67 -0
- data/lib/virtualbox/com/interface/3.1.x/vrdp_auth_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.1.x/vrdp_server.rb +19 -0
- data/lib/virtualbox/com/interface/3.2.x/access_mode.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/appliance.rb +22 -0
- data/lib/virtualbox/com/interface/3.2.x/audio_adapter.rb +15 -0
- data/lib/virtualbox/com/interface/3.2.x/audio_controller_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/audio_driver_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/bios_boot_menu_mode.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/bios_settings.rb +21 -0
- data/lib/virtualbox/com/interface/3.2.x/clipboard_mode.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/console.rb +50 -0
- data/lib/virtualbox/com/interface/3.2.x/cpu_property_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/device_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/dhcp_server.rb +22 -0
- data/lib/virtualbox/com/interface/3.2.x/firmware_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/guest.rb +13 -0
- data/lib/virtualbox/com/interface/3.2.x/guest_os_type.rb +33 -0
- data/lib/virtualbox/com/interface/3.2.x/host.rb +43 -0
- data/lib/virtualbox/com/interface/3.2.x/host_network_interface.rb +30 -0
- data/lib/virtualbox/com/interface/3.2.x/host_network_interface_medium_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/host_network_interface_status.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/host_network_interface_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/host_usb_device.rb +13 -0
- data/lib/virtualbox/com/interface/3.2.x/host_usb_device_filter.rb +13 -0
- data/lib/virtualbox/com/interface/3.2.x/hw_virt_ex_property_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/keyboard_hid_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/machine.rb +118 -0
- data/lib/virtualbox/com/interface/3.2.x/machine_state.rb +14 -0
- data/lib/virtualbox/com/interface/3.2.x/medium.rb +51 -0
- data/lib/virtualbox/com/interface/3.2.x/medium_attachment.rb +18 -0
- data/lib/virtualbox/com/interface/3.2.x/medium_format.rb +18 -0
- data/lib/virtualbox/com/interface/3.2.x/medium_state.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/medium_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/medium_variant.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/nat_alias_mode.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/nat_engine.rb +27 -0
- data/lib/virtualbox/com/interface/3.2.x/nat_protocol.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/network_adapter.rb +34 -0
- data/lib/virtualbox/com/interface/3.2.x/network_adapter_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/network_attachment_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/nsiexception.rb +23 -0
- data/lib/virtualbox/com/interface/3.2.x/nsisupports.rb +15 -0
- data/lib/virtualbox/com/interface/3.2.x/parallel_port.rb +17 -0
- data/lib/virtualbox/com/interface/3.2.x/pointing_hid_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/port_mode.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/progress.rb +63 -0
- data/lib/virtualbox/com/interface/3.2.x/serial_port.rb +19 -0
- data/lib/virtualbox/com/interface/3.2.x/session.rb +18 -0
- data/lib/virtualbox/com/interface/3.2.x/session_state.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/session_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/shared_folder.rb +17 -0
- data/lib/virtualbox/com/interface/3.2.x/snapshot.rb +20 -0
- data/lib/virtualbox/com/interface/3.2.x/storage_bus.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/storage_controller.rb +24 -0
- data/lib/virtualbox/com/interface/3.2.x/storage_controller_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/system_properties.rb +42 -0
- data/lib/virtualbox/com/interface/3.2.x/usb_controller.rb +21 -0
- data/lib/virtualbox/com/interface/3.2.x/usb_device.rb +24 -0
- data/lib/virtualbox/com/interface/3.2.x/usb_device_filter.rb +23 -0
- data/lib/virtualbox/com/interface/3.2.x/usb_device_filter_action.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/usb_device_state.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/virtual_box_error_info.rb +17 -0
- data/lib/virtualbox/com/interface/3.2.x/virtual_system_description.rb +19 -0
- data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_type.rb +14 -0
- data/lib/virtualbox/com/interface/3.2.x/virtual_system_description_value_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/virtualbox.rb +67 -0
- data/lib/virtualbox/com/interface/3.2.x/vrdp_auth_type.rb +11 -0
- data/lib/virtualbox/com/interface/3.2.x/vrdp_server.rb +21 -0
- data/lib/virtualbox/com/mscom_interface.rb +44 -0
- data/lib/virtualbox/com/nil_interface.rb +7 -0
- data/lib/virtualbox/com/util.rb +32 -0
- data/lib/virtualbox/cpu.rb +61 -0
- data/lib/virtualbox/dhcp_server.rb +89 -0
- data/lib/virtualbox/dvd.rb +27 -0
- data/lib/virtualbox/exceptions.rb +39 -0
- data/lib/virtualbox/ext/byte_normalizer.rb +17 -0
- data/lib/virtualbox/ext/glob_loader.rb +22 -0
- data/lib/virtualbox/ext/logger.rb +38 -0
- data/lib/virtualbox/ext/platform.rb +27 -0
- data/lib/virtualbox/ext/subclass_listing.rb +24 -0
- data/lib/virtualbox/extra_data.rb +127 -0
- data/lib/virtualbox/forwarded_port.rb +222 -0
- data/lib/virtualbox/global.rb +102 -0
- data/lib/virtualbox/guest_property.rb +116 -0
- data/lib/virtualbox/hard_drive.rb +246 -0
- data/lib/virtualbox/host.rb +71 -0
- data/lib/virtualbox/host_network_interface.rb +137 -0
- data/lib/virtualbox/hw_virtualization.rb +63 -0
- data/lib/virtualbox/lib.rb +84 -0
- data/lib/virtualbox/media.rb +20 -0
- data/lib/virtualbox/medium.rb +145 -0
- data/lib/virtualbox/medium_attachment.rb +61 -0
- data/lib/virtualbox/nat_engine.rb +71 -0
- data/lib/virtualbox/nat_forwarded_port.rb +171 -0
- data/lib/virtualbox/network_adapter.rb +166 -0
- data/lib/virtualbox/proxies/collection.rb +57 -0
- data/lib/virtualbox/shared_folder.rb +220 -0
- data/lib/virtualbox/snapshot.rb +185 -0
- data/lib/virtualbox/storage_controller.rb +160 -0
- data/lib/virtualbox/system_properties.rb +74 -0
- data/lib/virtualbox/usb_controller.rb +59 -0
- data/lib/virtualbox/usb_device_filter.rb +74 -0
- data/lib/virtualbox/version.rb +36 -0
- data/lib/virtualbox/virtual_system_description.rb +47 -0
- data/lib/virtualbox/vm.rb +684 -0
- data/lib/virtualbox/vrdp_server.rb +59 -0
- data/test/test_helper.rb +18 -0
- data/test/virtualbox/abstract_model/attributable_test.rb +269 -0
- data/test/virtualbox/abstract_model/dirty_test.rb +83 -0
- data/test/virtualbox/abstract_model/interface_attributes_test.rb +194 -0
- data/test/virtualbox/abstract_model/relatable_test.rb +348 -0
- data/test/virtualbox/abstract_model/validatable_test.rb +308 -0
- data/test/virtualbox/abstract_model/version_matcher_test.rb +41 -0
- data/test/virtualbox/abstract_model_test.rb +462 -0
- data/test/virtualbox/appliance_test.rb +159 -0
- data/test/virtualbox/audio_adapter_test.rb +83 -0
- data/test/virtualbox/bios_test.rb +83 -0
- data/test/virtualbox/com/abstract_enum_test.rb +49 -0
- data/test/virtualbox/com/abstract_implementer_test.rb +40 -0
- data/test/virtualbox/com/abstract_interface_test.rb +140 -0
- data/test/virtualbox/com/ffi/interface_test.rb +249 -0
- data/test/virtualbox/com/ffi/util_test.rb +108 -0
- data/test/virtualbox/com/ffi_interface_test.rb +42 -0
- data/test/virtualbox/com/implementer/base_test.rb +38 -0
- data/test/virtualbox/com/implementer/ffi_test.rb +527 -0
- data/test/virtualbox/com/implementer/mscom_test.rb +247 -0
- data/test/virtualbox/com/mscom_interface_test.rb +17 -0
- data/test/virtualbox/com/util_test.rb +17 -0
- data/test/virtualbox/cpu_test.rb +103 -0
- data/test/virtualbox/dhcp_server_test.rb +165 -0
- data/test/virtualbox/dvd_test.rb +28 -0
- data/test/virtualbox/ext/byte_normalizer_test.rb +34 -0
- data/test/virtualbox/ext/platform_test.rb +50 -0
- data/test/virtualbox/ext/subclass_listing_test.rb +25 -0
- data/test/virtualbox/extra_data_test.rb +155 -0
- data/test/virtualbox/forwarded_port_test.rb +286 -0
- data/test/virtualbox/global_test.rb +46 -0
- data/test/virtualbox/hard_drive_test.rb +141 -0
- data/test/virtualbox/host_network_interface_test.rb +254 -0
- data/test/virtualbox/host_test.rb +94 -0
- data/test/virtualbox/hw_virtualization_test.rb +103 -0
- data/test/virtualbox/lib_test.rb +93 -0
- data/test/virtualbox/medium_attachment_test.rb +147 -0
- data/test/virtualbox/medium_test.rb +192 -0
- data/test/virtualbox/nat_engine_test.rb +106 -0
- data/test/virtualbox/nat_forwarded_port_test.rb +222 -0
- data/test/virtualbox/network_adapter_test.rb +191 -0
- data/test/virtualbox/proxies/collection_test.rb +102 -0
- data/test/virtualbox/shared_folder_test.rb +219 -0
- data/test/virtualbox/snapshot_test.rb +231 -0
- data/test/virtualbox/storage_controller_test.rb +197 -0
- data/test/virtualbox/system_properties_test.rb +87 -0
- data/test/virtualbox/usb_controller_test.rb +112 -0
- data/test/virtualbox/usb_device_filter_test.rb +93 -0
- data/test/virtualbox/version_test.rb +59 -0
- data/test/virtualbox/virtual_system_description_test.rb +61 -0
- data/test/virtualbox/vm_test.rb +637 -0
- data/test/virtualbox/vrdp_server_test.rb +83 -0
- data/test/virtualbox_test.rb +11 -0
- data/virtualbox.gemspec +25 -0
- metadata +397 -0
|
@@ -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
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
module VirtualBox
|
|
2
|
+
# Represents a virtual machine snapshot. Snapshots allow users of virtual
|
|
3
|
+
# machines to make a lightweight "snapshot" of a virtual machine at any
|
|
4
|
+
# moment. This snapshot can be taken while the virtual machine is running
|
|
5
|
+
# or while its powered off. Snapshotting creates a differencing image for
|
|
6
|
+
# the hard drive which allows a virtual machine to restore itself to the
|
|
7
|
+
# exact state of where it was snapshotted.
|
|
8
|
+
#
|
|
9
|
+
# # Getting Snapshots
|
|
10
|
+
#
|
|
11
|
+
# Snapshots are accessed from the `current_snapshot` relationship on {VM}.
|
|
12
|
+
# There is no other way to access snapshots. After getting the current
|
|
13
|
+
# snapshot, you can easily traverse the tree of snapshots by accessing
|
|
14
|
+
# `parent` or `children` on the snapshot. An example follows:
|
|
15
|
+
#
|
|
16
|
+
# vm = VirtualBox::VM.find("MyWindowsXP")
|
|
17
|
+
# p vm.current_snapshot # the current snapshot
|
|
18
|
+
# p vm.current_snapshot.children # The children of the current snapshot
|
|
19
|
+
# p vm.current_snapshot.parent # The current snapshot's parent
|
|
20
|
+
# p vm.current_snapshot.parent.parent.children # You get the idea.
|
|
21
|
+
#
|
|
22
|
+
# # Taking a Snapshot
|
|
23
|
+
#
|
|
24
|
+
# To take a snapshot, call the {VM#take_snapshot} method. Please view
|
|
25
|
+
# the documentation on that method for more information.
|
|
26
|
+
#
|
|
27
|
+
# # Restoring a Snapshot
|
|
28
|
+
#
|
|
29
|
+
# To restore a snapshot, call the {#restore} method. A simple example
|
|
30
|
+
# is shown below:
|
|
31
|
+
#
|
|
32
|
+
# vm = VirtualBox::VM.find("MyWindowsXP")
|
|
33
|
+
# snapshot = vm.current_snapshot.parent
|
|
34
|
+
# snapshot.restore
|
|
35
|
+
#
|
|
36
|
+
# **Note:** The VM object will not immediately update to reflect any settings
|
|
37
|
+
# changes or current snapshot changes from the restore. To grab the updates,
|
|
38
|
+
# either load a new VM object or call {VM#reload}.
|
|
39
|
+
#
|
|
40
|
+
# # Deleting a Snapshot
|
|
41
|
+
#
|
|
42
|
+
# To delete a snapshot, simply find the snapshot of interest and call
|
|
43
|
+
# it's {#destroy} method. A quick example is shown below:
|
|
44
|
+
#
|
|
45
|
+
# vm = VirtualBox::VM.find("MyWindowsXP")
|
|
46
|
+
# snapshot = vm.current_snapshot # Grab the current snapshot
|
|
47
|
+
# snapshot.destroy # Destroy it
|
|
48
|
+
#
|
|
49
|
+
# Note that this doesn't actually affect the `current_snapshot`
|
|
50
|
+
# relationship on the VM. To update all the proper values, you have to call
|
|
51
|
+
# {VM#reload}.
|
|
52
|
+
#
|
|
53
|
+
class Snapshot < AbstractModel
|
|
54
|
+
attribute :uuid, :readonly => true, :property => :id
|
|
55
|
+
attribute :name
|
|
56
|
+
attribute :description
|
|
57
|
+
attribute :time_stamp, :readonly => true
|
|
58
|
+
attribute :online, :readonly => true, :boolean => true
|
|
59
|
+
attribute :interface, :readonly => true, :property => false
|
|
60
|
+
relationship :parent, :Snapshot, :lazy => true
|
|
61
|
+
relationship :machine, :VM, :lazy => true
|
|
62
|
+
relationship :children, :Snapshot, :lazy => true
|
|
63
|
+
|
|
64
|
+
class << self
|
|
65
|
+
# Populates a relationship with another model. Since a snapshot
|
|
66
|
+
# can be in a relationship with multiple items, this method forwards
|
|
67
|
+
# to other methods such as {populate_vm_relationship}.
|
|
68
|
+
#
|
|
69
|
+
# **This method typically won't be used except internally.**
|
|
70
|
+
def populate_relationship(caller, data)
|
|
71
|
+
if data.is_a?(COM::Util.versioned_interface(:Machine))
|
|
72
|
+
populate_machine_relationship(caller, data)
|
|
73
|
+
elsif data.is_a?(Array)
|
|
74
|
+
populate_children_relationship(caller, data)
|
|
75
|
+
elsif data.is_a?(COM::Util.versioned_interface(:Snapshot)) || data.nil?
|
|
76
|
+
populate_parent_relationship(caller, data)
|
|
77
|
+
else
|
|
78
|
+
raise Exceptions::Exception.new("Invalid relationship data for Snapshot: #{data}")
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Populates the VM relationship as the "current snapshot."
|
|
83
|
+
#
|
|
84
|
+
# **This method typically won't be used except internally.**
|
|
85
|
+
#
|
|
86
|
+
# @return [Snapshot]
|
|
87
|
+
def populate_machine_relationship(caller, machine)
|
|
88
|
+
# The current snapshot can and will be nil if there are no snapshots
|
|
89
|
+
# taken. In that case, we just return nil.
|
|
90
|
+
snapshot = machine.current_snapshot
|
|
91
|
+
snapshot ? new(machine.current_snapshot) : nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Populates the VM relationship as the "current snapshot."
|
|
95
|
+
#
|
|
96
|
+
# **This method typically won't be used except internally.**
|
|
97
|
+
#
|
|
98
|
+
# @return [Snapshot]
|
|
99
|
+
def populate_parent_relationship(caller, parent)
|
|
100
|
+
# If the parent is nil then that means the child is the root
|
|
101
|
+
# snapshot
|
|
102
|
+
parent ? new(parent) : nil
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Populates the snapshot child tree relationship.
|
|
106
|
+
#
|
|
107
|
+
# **This method typically won't be used except internally.**
|
|
108
|
+
#
|
|
109
|
+
# @return [Array<Snapshot>]
|
|
110
|
+
def populate_children_relationship(caller, snapshots)
|
|
111
|
+
result = Proxies::Collection.new(caller)
|
|
112
|
+
|
|
113
|
+
snapshots.each do |snapshot|
|
|
114
|
+
result << new(snapshot)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
result
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Initializes a new snapshot. This should never be called on its own.
|
|
122
|
+
# Snapshots should be accessed beginning with the `current_snapshot` on
|
|
123
|
+
# a VM, and can be further accessed by traversing the parent/child tree
|
|
124
|
+
# of the snapshot.
|
|
125
|
+
def initialize(snapshot)
|
|
126
|
+
write_attribute(:interface, snapshot)
|
|
127
|
+
initialize_attributes(snapshot)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def initialize_attributes(snapshot)
|
|
131
|
+
# Load the interface attributes
|
|
132
|
+
load_interface_attributes(snapshot)
|
|
133
|
+
|
|
134
|
+
# Clear dirtiness, since this should only be called initially and
|
|
135
|
+
# therefore shouldn't affect dirtiness
|
|
136
|
+
clear_dirty!
|
|
137
|
+
|
|
138
|
+
# But this is an existing record
|
|
139
|
+
existing_record!
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Loads the lazy relationships.
|
|
143
|
+
#
|
|
144
|
+
# **This method should only be called internally.**
|
|
145
|
+
def load_relationship(name)
|
|
146
|
+
populate_relationship(:parent, interface.parent)
|
|
147
|
+
populate_relationship(:machine, interface.machine)
|
|
148
|
+
populate_relationship(:children, interface.children)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# Timestamp that the snapshot was taken. This method overwrites the
|
|
152
|
+
# typical attribute so it can return a Time object.
|
|
153
|
+
def time_stamp
|
|
154
|
+
# Seconds, microseconds, since the time stamp is in milliseconds
|
|
155
|
+
value = read_attribute(:time_stamp)
|
|
156
|
+
Time.at(value / 1000, (value % 1000) * 1000)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Restore a snapshot. This will restore this snapshot's virtual machine
|
|
160
|
+
# to the state that this snapshot represents. This method will block while
|
|
161
|
+
# the restore occurs.
|
|
162
|
+
#
|
|
163
|
+
# If a block is given to the function, it will be yielded with a progress
|
|
164
|
+
# object which can be used to track the progress of the operation.
|
|
165
|
+
def restore(&block)
|
|
166
|
+
machine.with_open_session do |session|
|
|
167
|
+
session.console.restore_snapshot(interface).wait(&block)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Destroy a snapshot. This will physically remove the snapshot. Once this
|
|
172
|
+
# method is called, there is no undo. If this snapshot is a parent of other
|
|
173
|
+
# snapshots, the differencing image of this snapshot will be merged with
|
|
174
|
+
# the child snapshots so no data is lost. This process can sometimes take
|
|
175
|
+
# some time. This method will block while this process occurs.
|
|
176
|
+
#
|
|
177
|
+
# If a block is given to the function, it will be yielded with a progress
|
|
178
|
+
# object which can be used to track the progress of the operation.
|
|
179
|
+
def destroy(&block)
|
|
180
|
+
machine.with_open_session do |session|
|
|
181
|
+
session.console.delete_snapshot(uuid).wait(&block)
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
end
|