bbrowning-virtualbox 0.7.6.dev
Sign up to get free protection for your applications and to get access to all the features.
- 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,61 @@
|
|
1
|
+
module VirtualBox
|
2
|
+
# Represents the attachment of a medium (DVD, Hard Drive, etc) to a
|
3
|
+
# virtual machine, and specifically to a {StorageController}.
|
4
|
+
class MediumAttachment < AbstractModel
|
5
|
+
attribute :parent, :readonly => true, :property => false
|
6
|
+
attribute :controller_name, :readonly => :true, :property => :controller
|
7
|
+
attribute :port, :readonly => true
|
8
|
+
attribute :device, :readonly => true
|
9
|
+
attribute :passthrough, :readonly => true
|
10
|
+
attribute :type, :readonly => true
|
11
|
+
relationship :medium, :Medium
|
12
|
+
relationship :storage_controller, :StorageController
|
13
|
+
|
14
|
+
class << self
|
15
|
+
# Populates a relationship with another model.
|
16
|
+
#
|
17
|
+
# **This method typically won't be used except internally.**
|
18
|
+
#
|
19
|
+
# @return [Array<MediumAttachment>]
|
20
|
+
def populate_relationship(caller, imachine)
|
21
|
+
relation = Proxies::Collection.new(caller)
|
22
|
+
|
23
|
+
imachine.medium_attachments.each do |ima|
|
24
|
+
relation << new(caller, ima)
|
25
|
+
end
|
26
|
+
|
27
|
+
relation
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(parent, imedium_attachment)
|
32
|
+
populate_attributes({:parent => parent}, :ignore_relationships => true)
|
33
|
+
initialize_attributes(imedium_attachment)
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize_attributes(ima)
|
37
|
+
load_interface_attributes(ima)
|
38
|
+
populate_relationship(:medium, ima.medium)
|
39
|
+
populate_relationship(:storage_controller, self)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Detaches the medium from it's parent virtual machine. Note that this
|
43
|
+
# **does not delete** the `medium` which this attachment references; it
|
44
|
+
# merely removes the assocation of said medium with this attachment's
|
45
|
+
# virtual machine.
|
46
|
+
def detach
|
47
|
+
parent.with_open_session do |session|
|
48
|
+
machine = session.machine
|
49
|
+
|
50
|
+
machine.detach_device(storage_controller.name, port, device)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Destroy this medium attachment. This simply detaches the medium attachment.
|
55
|
+
# This will also delete the medium if that option is specified.
|
56
|
+
def destroy(opts={})
|
57
|
+
detach
|
58
|
+
medium.destroy(opts[:destroy_medium] == :delete) if opts[:destroy_medium] && medium
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module VirtualBox
|
2
|
+
# Represents a NAT engine for a given {NetworkAdapter}. This data is
|
3
|
+
# available through the `nat_driver` relationship on
|
4
|
+
# {NetworkAdapter} only if the adapter is a NAT adapter.
|
5
|
+
class NATEngine < AbstractModel
|
6
|
+
attribute :parent, :readonly => true, :property => false
|
7
|
+
attribute :network
|
8
|
+
attribute :tftp_prefix
|
9
|
+
attribute :tftp_boot_file
|
10
|
+
attribute :tftp_next_server
|
11
|
+
attribute :alias_mode
|
12
|
+
attribute :dns_pass_domain
|
13
|
+
attribute :dns_proxy
|
14
|
+
attribute :dns_use_host_resolver
|
15
|
+
attribute :interface, :readonly => true, :property => false
|
16
|
+
relationship :forwarded_ports, :NATForwardedPort
|
17
|
+
|
18
|
+
class << self
|
19
|
+
# Populates the NAT engine for anything which is related to it.
|
20
|
+
#
|
21
|
+
# **This method typically won't be used except internally.**
|
22
|
+
#
|
23
|
+
# @return [NATEngine]
|
24
|
+
def populate_relationship(caller, inat)
|
25
|
+
return nil if inat.nil?
|
26
|
+
new(caller, inat)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Saves the relationship. This simply calls {#save} on every
|
30
|
+
# member of the relationship.
|
31
|
+
#
|
32
|
+
# **This method typically won't be used except internally.**
|
33
|
+
def save_relationship(caller, item)
|
34
|
+
item.save
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(caller, inat)
|
39
|
+
super()
|
40
|
+
initialize_attributes(caller, inat)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Initializes the attributes of an existing NAT engine.
|
44
|
+
def initialize_attributes(parent, inat)
|
45
|
+
write_attribute(:parent, parent)
|
46
|
+
write_attribute(:interface, inat)
|
47
|
+
|
48
|
+
# Load the interface attributes associated with this model
|
49
|
+
load_interface_attributes(inat)
|
50
|
+
populate_relationships(inat)
|
51
|
+
|
52
|
+
# Clear dirty and set as existing
|
53
|
+
clear_dirty!
|
54
|
+
existing_record!
|
55
|
+
end
|
56
|
+
|
57
|
+
def save
|
58
|
+
modify_engine do |nat|
|
59
|
+
save_changed_interface_attributes(nat)
|
60
|
+
save_relationships
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# Helper method to get the mutable `INATEngine` interface.
|
65
|
+
def modify_engine
|
66
|
+
parent.modify_adapter do |adapter|
|
67
|
+
yield adapter.nat_driver
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -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, :version => "3.2", :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
|