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.
- data/.gitignore +8 -0
- data/.yardopts +3 -0
- data/Gemfile +16 -0
- data/LICENSE +19 -0
- data/Rakefile +37 -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 +63 -0
- data/lib/virtualbox/com/ffi/util.rb +121 -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 +381 -0
- data/lib/virtualbox/com/implementer/mscom.rb +189 -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/interface/4.0.x/access_mode.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/appliance.rb +23 -0
- data/lib/virtualbox/com/interface/4.0.x/audio_adapter.rb +15 -0
- data/lib/virtualbox/com/interface/4.0.x/audio_controller_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/audio_driver_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/auth_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/bios_boot_menu_mode.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/bios_settings.rb +21 -0
- data/lib/virtualbox/com/interface/4.0.x/cleanup_mode.rb +12 -0
- data/lib/virtualbox/com/interface/4.0.x/clipboard_mode.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/console.rb +50 -0
- data/lib/virtualbox/com/interface/4.0.x/cpu_property_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/device_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/dhcp_server.rb +22 -0
- data/lib/virtualbox/com/interface/4.0.x/event_source.rb +13 -0
- data/lib/virtualbox/com/interface/4.0.x/fault_tolerance_state.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/firmware_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/guest.rb +13 -0
- data/lib/virtualbox/com/interface/4.0.x/guest_os_type.rb +33 -0
- data/lib/virtualbox/com/interface/4.0.x/host.rb +43 -0
- data/lib/virtualbox/com/interface/4.0.x/host_network_interface.rb +30 -0
- data/lib/virtualbox/com/interface/4.0.x/host_network_interface_medium_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/host_network_interface_status.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/host_network_interface_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/host_usb_device.rb +13 -0
- data/lib/virtualbox/com/interface/4.0.x/host_usb_device_filter.rb +13 -0
- data/lib/virtualbox/com/interface/4.0.x/hw_virt_ex_property_type.rb +12 -0
- data/lib/virtualbox/com/interface/4.0.x/keyboard_hid_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/lock_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/machine.rb +132 -0
- data/lib/virtualbox/com/interface/4.0.x/machine_state.rb +14 -0
- data/lib/virtualbox/com/interface/4.0.x/medium.rb +53 -0
- data/lib/virtualbox/com/interface/4.0.x/medium_attachment.rb +18 -0
- data/lib/virtualbox/com/interface/4.0.x/medium_format.rb +18 -0
- data/lib/virtualbox/com/interface/4.0.x/medium_state.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/medium_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/medium_variant.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/nat_alias_mode.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/nat_engine.rb +27 -0
- data/lib/virtualbox/com/interface/4.0.x/nat_protocol.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/network_adapter.rb +35 -0
- data/lib/virtualbox/com/interface/4.0.x/network_adapter_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/network_attachment_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/nsiexception.rb +23 -0
- data/lib/virtualbox/com/interface/4.0.x/nsisupports.rb +15 -0
- data/lib/virtualbox/com/interface/4.0.x/parallel_port.rb +17 -0
- data/lib/virtualbox/com/interface/4.0.x/pointing_hid_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/port_mode.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/progress.rb +64 -0
- data/lib/virtualbox/com/interface/4.0.x/serial_port.rb +19 -0
- data/lib/virtualbox/com/interface/4.0.x/session.rb +18 -0
- data/lib/virtualbox/com/interface/4.0.x/session_state.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/session_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/shared_folder.rb +17 -0
- data/lib/virtualbox/com/interface/4.0.x/snapshot.rb +20 -0
- data/lib/virtualbox/com/interface/4.0.x/storage_bus.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/storage_controller.rb +24 -0
- data/lib/virtualbox/com/interface/4.0.x/storage_controller_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/system_properties.rb +42 -0
- data/lib/virtualbox/com/interface/4.0.x/usb_controller.rb +21 -0
- data/lib/virtualbox/com/interface/4.0.x/usb_device.rb +24 -0
- data/lib/virtualbox/com/interface/4.0.x/usb_device_filter.rb +23 -0
- data/lib/virtualbox/com/interface/4.0.x/usb_device_filter_action.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/usb_device_state.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/virtual_box_error_info.rb +17 -0
- data/lib/virtualbox/com/interface/4.0.x/virtual_system_description.rb +19 -0
- data/lib/virtualbox/com/interface/4.0.x/virtual_system_description_type.rb +14 -0
- data/lib/virtualbox/com/interface/4.0.x/virtual_system_description_value_type.rb +11 -0
- data/lib/virtualbox/com/interface/4.0.x/virtualbox.rb +50 -0
- data/lib/virtualbox/com/interface/4.0.x/vrde_server.rb +23 -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 +35 -0
- data/lib/virtualbox/ext/logger.rb +38 -0
- data/lib/virtualbox/ext/platform.rb +31 -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 +96 -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 +64 -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 +73 -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 +649 -0
- data/lib/virtualbox/vrde_server.rb +57 -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 +255 -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 +633 -0
- data/test/virtualbox/vrde_server_test.rb +83 -0
- data/test/virtualbox_test.rb +11 -0
- data/virtualbox.gemspec +24 -0
- 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
|