virtualbox 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. data/.gitignore +2 -1
  2. data/Gemfile +1 -1
  3. data/Rakefile +1 -1
  4. data/Readme.md +5 -21
  5. data/VERSION +1 -1
  6. data/docs/WhatsNew.md +9 -47
  7. data/lib/virtualbox.rb +7 -30
  8. data/lib/virtualbox/abstract_model.rb +25 -5
  9. data/lib/virtualbox/abstract_model/attributable.rb +5 -1
  10. data/lib/virtualbox/abstract_model/dirty.rb +2 -0
  11. data/lib/virtualbox/abstract_model/interface_attributes.rb +96 -0
  12. data/lib/virtualbox/abstract_model/relatable.rb +19 -8
  13. data/lib/virtualbox/appliance.rb +59 -0
  14. data/lib/virtualbox/audio_adapter.rb +44 -0
  15. data/lib/virtualbox/bios.rb +44 -0
  16. data/lib/virtualbox/com.rb +23 -0
  17. data/lib/virtualbox/com/abstract_enum.rb +42 -0
  18. data/lib/virtualbox/com/abstract_implementer.rb +43 -0
  19. data/lib/virtualbox/com/abstract_interface.rb +165 -0
  20. data/lib/virtualbox/com/ffi/interface.rb +141 -0
  21. data/lib/virtualbox/com/ffi/interfaces.rb +42 -0
  22. data/lib/virtualbox/com/ffi/util.rb +101 -0
  23. data/lib/virtualbox/com/ffi/vboxxpcomc.rb +31 -0
  24. data/lib/virtualbox/com/ffi_interface.rb +65 -0
  25. data/lib/virtualbox/com/implementer/base.rb +52 -0
  26. data/lib/virtualbox/com/implementer/ffi.rb +350 -0
  27. data/lib/virtualbox/com/implementer/mscom.rb +165 -0
  28. data/lib/virtualbox/com/implementer/nil.rb +10 -0
  29. data/lib/virtualbox/com/interface/appliance.rb +20 -0
  30. data/lib/virtualbox/com/interface/audio_adapter.rb +13 -0
  31. data/lib/virtualbox/com/interface/audio_controller_type.rb +9 -0
  32. data/lib/virtualbox/com/interface/audio_driver_type.rb +9 -0
  33. data/lib/virtualbox/com/interface/bios_boot_menu_mode.rb +9 -0
  34. data/lib/virtualbox/com/interface/bios_settings.rb +19 -0
  35. data/lib/virtualbox/com/interface/clipboard_mode.rb +9 -0
  36. data/lib/virtualbox/com/interface/console.rb +48 -0
  37. data/lib/virtualbox/com/interface/cpu_property_type.rb +9 -0
  38. data/lib/virtualbox/com/interface/device_type.rb +9 -0
  39. data/lib/virtualbox/com/interface/dhcp_server.rb +20 -0
  40. data/lib/virtualbox/com/interface/firmware_type.rb +9 -0
  41. data/lib/virtualbox/com/interface/guest_os_type.rb +21 -0
  42. data/lib/virtualbox/com/interface/host.rb +40 -0
  43. data/lib/virtualbox/com/interface/host_network_interface.rb +28 -0
  44. data/lib/virtualbox/com/interface/host_network_interface_medium_type.rb +9 -0
  45. data/lib/virtualbox/com/interface/host_network_interface_status.rb +9 -0
  46. data/lib/virtualbox/com/interface/host_network_interface_type.rb +9 -0
  47. data/lib/virtualbox/com/interface/host_usb_device.rb +11 -0
  48. data/lib/virtualbox/com/interface/host_usb_device_filter.rb +11 -0
  49. data/lib/virtualbox/com/interface/hw_virt_ex_property_type.rb +9 -0
  50. data/lib/virtualbox/com/interface/machine.rb +103 -0
  51. data/lib/virtualbox/com/interface/machine_state.rb +12 -0
  52. data/lib/virtualbox/com/interface/medium.rb +48 -0
  53. data/lib/virtualbox/com/interface/medium_attachment.rb +16 -0
  54. data/lib/virtualbox/com/interface/medium_format.rb +16 -0
  55. data/lib/virtualbox/com/interface/medium_state.rb +9 -0
  56. data/lib/virtualbox/com/interface/medium_type.rb +9 -0
  57. data/lib/virtualbox/com/interface/medium_variant.rb +9 -0
  58. data/lib/virtualbox/com/interface/network_adapter.rb +28 -0
  59. data/lib/virtualbox/com/interface/network_adapter_type.rb +9 -0
  60. data/lib/virtualbox/com/interface/network_attachment_type.rb +9 -0
  61. data/lib/virtualbox/com/interface/nsiexception.rb +21 -0
  62. data/lib/virtualbox/com/interface/nsisupports.rb +13 -0
  63. data/lib/virtualbox/com/interface/parallel_port.rb +15 -0
  64. data/lib/virtualbox/com/interface/port_mode.rb +9 -0
  65. data/lib/virtualbox/com/interface/progress.rb +58 -0
  66. data/lib/virtualbox/com/interface/serial_port.rb +17 -0
  67. data/lib/virtualbox/com/interface/session.rb +16 -0
  68. data/lib/virtualbox/com/interface/session_state.rb +9 -0
  69. data/lib/virtualbox/com/interface/session_type.rb +9 -0
  70. data/lib/virtualbox/com/interface/shared_folder.rb +15 -0
  71. data/lib/virtualbox/com/interface/snapshot.rb +18 -0
  72. data/lib/virtualbox/com/interface/storage_bus.rb +9 -0
  73. data/lib/virtualbox/com/interface/storage_controller.rb +21 -0
  74. data/lib/virtualbox/com/interface/storage_controller_type.rb +9 -0
  75. data/lib/virtualbox/com/interface/system_properties.rb +35 -0
  76. data/lib/virtualbox/com/interface/usb_controller.rb +18 -0
  77. data/lib/virtualbox/com/interface/usb_device.rb +22 -0
  78. data/lib/virtualbox/com/interface/usb_device_filter.rb +21 -0
  79. data/lib/virtualbox/com/interface/usb_device_filter_action.rb +9 -0
  80. data/lib/virtualbox/com/interface/usb_device_state.rb +9 -0
  81. data/lib/virtualbox/com/interface/virtual_box_error_info.rb +15 -0
  82. data/lib/virtualbox/com/interface/virtual_system_description.rb +17 -0
  83. data/lib/virtualbox/com/interface/virtual_system_description_type.rb +12 -0
  84. data/lib/virtualbox/com/interface/virtual_system_description_value_type.rb +9 -0
  85. data/lib/virtualbox/com/interface/virtualbox.rb +54 -0
  86. data/lib/virtualbox/com/interface/vrdp_auth_type.rb +9 -0
  87. data/lib/virtualbox/com/interface/vrdp_server.rb +17 -0
  88. data/lib/virtualbox/com/mscom_interface.rb +22 -0
  89. data/lib/virtualbox/com/util.rb +18 -0
  90. data/lib/virtualbox/dvd.rb +7 -94
  91. data/lib/virtualbox/exceptions.rb +24 -0
  92. data/lib/virtualbox/ext/glob_loader.rb +22 -0
  93. data/lib/virtualbox/ext/logger.rb +38 -0
  94. data/lib/virtualbox/ext/platform.rb +1 -1
  95. data/lib/virtualbox/extra_data.rb +25 -37
  96. data/lib/virtualbox/forwarded_port.rb +35 -13
  97. data/lib/virtualbox/global.rb +22 -80
  98. data/lib/virtualbox/hard_drive.rb +30 -97
  99. data/lib/virtualbox/lib.rb +82 -0
  100. data/lib/virtualbox/media.rb +7 -6
  101. data/lib/virtualbox/medium.rb +138 -0
  102. data/lib/virtualbox/medium_attachment.rb +61 -0
  103. data/lib/virtualbox/network_adapter.rb +134 -0
  104. data/lib/virtualbox/shared_folder.rb +53 -78
  105. data/lib/virtualbox/storage_controller.rb +76 -20
  106. data/lib/virtualbox/system_properties.rb +74 -0
  107. data/lib/virtualbox/usb_controller.rb +55 -0
  108. data/lib/virtualbox/version.rb +15 -0
  109. data/lib/virtualbox/virtual_system_description.rb +47 -0
  110. data/lib/virtualbox/vm.rb +160 -272
  111. data/test/test_helper.rb +0 -108
  112. data/test/virtualbox/abstract_model/attributable_test.rb +7 -1
  113. data/test/virtualbox/abstract_model/dirty_test.rb +1 -1
  114. data/test/virtualbox/abstract_model/interface_attributes_test.rb +169 -0
  115. data/test/virtualbox/abstract_model/relatable_test.rb +20 -0
  116. data/test/virtualbox/abstract_model_test.rb +40 -5
  117. data/test/virtualbox/appliance_test.rb +152 -0
  118. data/test/virtualbox/audio_adapter_test.rb +83 -0
  119. data/test/virtualbox/bios_test.rb +83 -0
  120. data/test/virtualbox/com/abstract_enum_test.rb +48 -0
  121. data/test/virtualbox/com/abstract_implementer_test.rb +39 -0
  122. data/test/virtualbox/com/abstract_interface_test.rb +139 -0
  123. data/test/virtualbox/com/ffi/interface_test.rb +249 -0
  124. data/test/virtualbox/com/ffi/util_test.rb +86 -0
  125. data/test/virtualbox/com/ffi_interface_test.rb +42 -0
  126. data/test/virtualbox/com/implementer/base_test.rb +37 -0
  127. data/test/virtualbox/com/implementer/ffi_test.rb +519 -0
  128. data/test/virtualbox/com/implementer/mscom_test.rb +208 -0
  129. data/test/virtualbox/com/mscom_interface_test.rb +17 -0
  130. data/test/virtualbox/com/util_test.rb +17 -0
  131. data/test/virtualbox/dvd_test.rb +4 -95
  132. data/test/virtualbox/ext/platform_test.rb +8 -0
  133. data/test/virtualbox/extra_data_test.rb +78 -102
  134. data/test/virtualbox/forwarded_port_test.rb +57 -7
  135. data/test/virtualbox/global_test.rb +25 -115
  136. data/test/virtualbox/hard_drive_test.rb +49 -212
  137. data/test/virtualbox/lib_test.rb +93 -0
  138. data/test/virtualbox/medium_attachment_test.rb +147 -0
  139. data/test/virtualbox/medium_test.rb +192 -0
  140. data/test/virtualbox/network_adapter_test.rb +160 -0
  141. data/test/virtualbox/shared_folder_test.rb +144 -160
  142. data/test/virtualbox/storage_controller_test.rb +166 -45
  143. data/test/virtualbox/system_properties_test.rb +87 -0
  144. data/test/virtualbox/usb_controller_test.rb +104 -0
  145. data/test/virtualbox/version_test.rb +34 -0
  146. data/test/virtualbox/virtual_system_description_test.rb +61 -0
  147. data/test/virtualbox/vm_test.rb +288 -322
  148. data/test/virtualbox_test.rb +1 -9
  149. data/virtualbox.gemspec +139 -23
  150. metadata +143 -27
  151. data/lib/virtualbox/attached_device.rb +0 -249
  152. data/lib/virtualbox/command.rb +0 -109
  153. data/lib/virtualbox/image.rb +0 -137
  154. data/lib/virtualbox/nic.rb +0 -111
  155. data/lib/virtualbox/system_property.rb +0 -55
  156. data/lib/virtualbox/usb.rb +0 -72
  157. data/test/virtualbox/attached_device_test.rb +0 -303
  158. data/test/virtualbox/command_test.rb +0 -152
  159. data/test/virtualbox/image_test.rb +0 -190
  160. data/test/virtualbox/nic_test.rb +0 -76
  161. data/test/virtualbox/system_property_test.rb +0 -71
  162. data/test/virtualbox/usb_test.rb +0 -35
@@ -1,111 +0,0 @@
1
- module VirtualBox
2
- # Represents a single NIC (Network Interface Card) of a virtual machine.
3
- #
4
- # **Currently, new NICs can't be created, so the only way to get this
5
- # object is through a {VM}'s `nics` relationship.**
6
- #
7
- # # Editing a NIC
8
- #
9
- # Nics can be modified directly in their relationship to other
10
- # virtual machines. When {VM#save} is called, it will also save any
11
- # changes to its relationships.
12
- #
13
- # vm = VirtualBox::VM.find("foo")
14
- # vm.nics[0].macaddress = @new_mac_address
15
- # vm.save
16
- #
17
- # # Attributes
18
- #
19
- # Properties of the model are exposed using standard ruby instance
20
- # methods which are generated on the fly. Because of this, they are not listed
21
- # below as available instance methods.
22
- #
23
- # These attributes can be accessed and modified via standard ruby-style
24
- # `instance.attribute` and `instance.attribute=` methods. The attributes are
25
- # listed below. If you aren't sure what this means or you can't understand
26
- # why the below is listed, please read {Attributable}.
27
- #
28
- # attribute :parent, :readonly => :readonly
29
- # attribute :nic
30
- # attribute :nictype
31
- # attribute :macaddress
32
- # attribute :cableconnected
33
- # attribute :bridgeadapter
34
- #
35
- class Nic < AbstractModel
36
- attribute :parent, :readonly => :readonly
37
- attribute :nic
38
- attribute :nictype, :populate_key => "type"
39
- attribute :macaddress, :populate_key => "MACAddress"
40
- attribute :cableconnected, :populate_key => "cable"
41
- attribute :bridgeadapter
42
-
43
- class <<self
44
- # Populates the nic relationship for anything which is related to it.
45
- #
46
- # **This method typically won't be used except internally.**
47
- #
48
- # @return [Array<Nic>]
49
- def populate_relationship(caller, doc)
50
- relation = Proxies::Collection.new(caller)
51
-
52
- doc.css("Hardware Network Adapter").each do |adapter|
53
- relation << new(caller, adapter)
54
- end
55
-
56
- relation
57
- end
58
-
59
- # Saves the relationship. This simply calls {#save} on every
60
- # member of the relationship.
61
- #
62
- # **This method typically won't be used except internally.**
63
- def save_relationship(caller, data)
64
- # Just call save on each nic with the VM
65
- data.each do |nic|
66
- nic.save(caller.name)
67
- end
68
- end
69
- end
70
-
71
- # Since there is currently no way to create a _new_ nic, this is
72
- # only used internally. Developers should NOT try to initialize their
73
- # own nic objects.
74
- def initialize(caller, data)
75
- super()
76
-
77
- @index = data["slot"].to_i + 1
78
-
79
- # Set the parent
80
- write_attribute(:parent, caller)
81
-
82
- # Convert each attribute value to a string
83
- attrs = {}
84
- data.attributes.each do |key, value|
85
- attrs[key] = value.to_s
86
- end
87
-
88
- populate_attributes(attrs)
89
-
90
- # The `nic` attribute is a bit more complicated, but not by
91
- # much
92
- if data["enabled"] == "true"
93
- write_attribute(:nic, data.children[1].name.downcase)
94
- else
95
- write_attribute(:nic, "none")
96
- end
97
-
98
- # Clear dirtiness
99
- clear_dirty!
100
- end
101
-
102
- # Saves a single attribute of the nic. This method is automatically
103
- # called on {#save}.
104
- #
105
- # **This method typically won't be used except internally.**
106
- def save_attribute(key, value, vmname)
107
- Command.vboxmanage("modifyvm", vmname, "--#{key}#{@index}", value)
108
- super
109
- end
110
- end
111
- end
@@ -1,55 +0,0 @@
1
- module VirtualBox
2
- # Represents the system properties of the system which VirtualBox
3
- # is running on. These system properties are immutable values which
4
- # are typically limits or specs of the host system. Some examples
5
- # of available properties are `Maximum guest RAM size` or
6
- # `Maximum Devices per SATA Port`.
7
- #
8
- # # Retrieving the System Properties
9
- #
10
- # Retrieving the system properties is done by calling the {all} method.
11
- # Since {SystemProperty} inherits from `Hash`, you can treat it just like
12
- # one. The keys are simply the typical keys downcased with spaces replaced
13
- # with underscores, and converted to a symbol. An example of accessing
14
- # system properties is shown below:
15
- #
16
- # properties = VirtualBox::SystemProperty.all
17
- # puts properties[:log_history_count]
18
- # puts properties[:maximum_guest_ram_size]
19
- #
20
- # Since {SystemProperty} is simply a hash, you can also iterate over it,
21
- # convert it easily to an array, etc.
22
- class SystemProperty < Hash
23
- class <<self
24
- # Returns the hash of all system properties. Each call will invoke a
25
- # system call to retrieve the properties (as in they're not cached
26
- # on the class), so if you need to access them many times, please
27
- # cache them yourself.
28
- #
29
- # @return [SystemProperty]
30
- def all
31
- raw = Command.vboxmanage("list", "systemproperties")
32
- parse_raw(raw)
33
- end
34
-
35
- # Parses the raw output of vboxmanage. This parses the raw output from
36
- # VBoxManage to parse the system properties.
37
- #
38
- # **This method typically won't be used except internally.**
39
- #
40
- # @param [String] data The raw output from vboxmanage.
41
- # @return [SystemProperty]
42
- def parse_raw(data)
43
- result = new
44
- data.split("\n").each do |line|
45
- next unless line =~ /^(.+?):\s+(.+?)$/
46
- value = $2.to_s
47
- key = $1.to_s.downcase.gsub(/\s/, "_")
48
- result[key.to_sym] = value
49
- end
50
-
51
- result
52
- end
53
- end
54
- end
55
- end
@@ -1,72 +0,0 @@
1
- module VirtualBox
2
- # Represents a single USB device of a virtual machine.
3
- #
4
- # **Currently, new USB devices can't be created, so the only way to get this
5
- # object is through a {VM}'s `usbs` relationship.**
6
- #
7
- # # Attributes
8
- #
9
- # Properties of the model are exposed using standard ruby instance
10
- # methods which are generated on the fly. Because of this, they are not listed
11
- # below as available instance methods.
12
- #
13
- # These attributes can be accessed and modified via standard ruby-style
14
- # `instance.attribute` and `instance.attribute=` methods. The attributes are
15
- # listed below. If you aren't sure what this means or you can't understand
16
- # why the below is listed, please read {Attributable}.
17
- #
18
- # attribute :parent, :readonly => :readonly
19
- # attribute :name
20
- # attribute :active
21
- # attribute :manufacturer
22
- # attribute :product
23
- # attribute :remote
24
- #
25
- class USB < AbstractModel
26
- attribute :parent, :readonly => :readonly
27
- attribute :name
28
- attribute :active
29
- attribute :manufacturer
30
- attribute :product
31
- attribute :remote
32
-
33
- class <<self
34
- # Populates the usb device relationship for anything which is related to it.
35
- #
36
- # **This method typically won't be used except internally.**
37
- #
38
- # @return [Array<USB>]
39
- def populate_relationship(caller, doc)
40
- relation = Proxies::Collection.new(caller)
41
-
42
- doc.css("Hardware USBController DeviceFilter").each do |device|
43
- relation << new(caller, device)
44
- end
45
-
46
- relation
47
- end
48
- end
49
-
50
- # Since there is currently no way to create a _new_ usb device, this is
51
- # only used internally. Developers should NOT try to initialize their
52
- # own usb device objects.
53
- def initialize(caller, data)
54
- super()
55
-
56
- # Set the parent
57
- write_attribute(:parent, caller)
58
-
59
- # Convert each attribute value to a string
60
- attrs = {}
61
-
62
- data.attributes.each do |key, value|
63
- attrs[key.to_sym] = value.to_s
64
- end
65
-
66
- populate_attributes(attrs)
67
-
68
- # Clear dirtiness
69
- clear_dirty!
70
- end
71
- end
72
- end
@@ -1,303 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
-
3
- class AttachedDeviceTest < Test::Unit::TestCase
4
- setup do
5
- @data = {
6
- :"foo controller-0-0" => "foomedium",
7
- :"foo controller-imageuuid-0-0" => "322f79fd-7da6-416f-a16f-e70066ccf165",
8
- :"foo controller-1-0" => "barmedium"
9
- }
10
-
11
- @vm = mock("vm")
12
- @vm.stubs(:name).returns("foo")
13
-
14
- @caller = mock("caller")
15
- @caller.stubs(:parent).returns(@vm)
16
- @caller.stubs(:name).returns("Foo Controller")
17
-
18
- # Stub execute to make sure nothing actually happens
19
- VirtualBox::Command.stubs(:execute).returns('')
20
-
21
- # Stub the config
22
- VirtualBox::Global.stubs(:config).returns(mock_xml_doc)
23
- end
24
-
25
- context "validations" do
26
- setup do
27
- @ad = VirtualBox::AttachedDevice.new
28
- @ad.image = VirtualBox::DVD.empty_drive
29
- @ad.port = 7
30
- @ad.added_to_relationship(@caller)
31
- end
32
-
33
- should "be valid with all fields" do
34
- assert @ad.valid?
35
- end
36
-
37
- should "be invalid with no image" do
38
- @ad.image = nil
39
- assert !@ad.valid?
40
- end
41
-
42
- should "be invalid with no port" do
43
- @ad.port = nil
44
- assert !@ad.valid?
45
- end
46
-
47
- should "be invalid if not in a relationship" do
48
- @ad.write_attribute(:parent, nil)
49
- assert !@ad.valid?
50
- end
51
- end
52
-
53
- context "medium" do
54
- setup do
55
- @ad = VirtualBox::AttachedDevice.new
56
- @hd = VirtualBox::HardDrive.new
57
- @hd.write_attribute(:uuid, @uuid)
58
- end
59
-
60
- should "be 'none' when image is nil" do
61
- assert_equal "none", @ad.medium
62
- end
63
-
64
- should "be the uuid of the image if its not nil" do
65
- @ad.image = @hd
66
- assert_equal @hd.uuid, @ad.medium
67
- end
68
-
69
- should "be 'emptydrive' if the image is an empty drive" do
70
- @ad.image = VirtualBox::DVD.empty_drive
71
- assert_equal "emptydrive", @ad.medium
72
- end
73
- end
74
-
75
- context "saving an existing device" do
76
- setup do
77
- @value = VirtualBox::AttachedDevice.populate_relationship(@caller, mock_xml_doc)
78
- @value = @value[0]
79
- @value.image = VirtualBox::DVD.empty_drive
80
- assert @value.changed?
81
- end
82
-
83
- should "not do anything if the device isn't change" do
84
- @value.clear_dirty!
85
- assert !@value.changed?
86
-
87
- VirtualBox::Command.expects(:vboxmanage).never
88
- @value.save
89
- end
90
-
91
- should "call vboxmanage" do
92
- VirtualBox::Command.expects(:vboxmanage).once
93
- @value.save
94
- end
95
-
96
- should "return false and not call vboxmanage if invalid" do
97
- VirtualBox::Command.expects(:vboxmanage).never
98
- @value.expects(:valid?).returns(false)
99
- assert !@value.save
100
- end
101
-
102
- should "not call destroy if the port didn't change" do
103
- @value.expects(:destroy).never
104
- assert !@value.port_changed?
105
- assert @value.save
106
- end
107
-
108
- should "call destroy with the old port if the port changed" do
109
- @value.expects(:destroy).with({:port => @value.port}, false)
110
- @value.port = 7
111
- assert @value.port_changed?
112
- assert @value.save
113
- end
114
-
115
- should "call destroy with the raise errors flag" do
116
- @value.expects(:destroy).with(anything, true).once
117
- @value.port = 7
118
- @value.save(true)
119
- end
120
- end
121
-
122
- context "creating a new attached device" do
123
- setup do
124
- @image = VirtualBox::HardDrive.new
125
- @ad = VirtualBox::AttachedDevice.new
126
- @ad.image = @image
127
- @ad.port = 3
128
- end
129
-
130
- should "return false and not call vboxmanage if invalid" do
131
- VirtualBox::Command.expects(:vboxmanage).never
132
- @ad.expects(:valid?).returns(false)
133
- assert !@ad.save
134
- end
135
-
136
- should "raise a ValidationFailedException if invalid and raise_errors is true" do
137
- @ad.expects(:valid?).returns(false)
138
- assert_raises(VirtualBox::Exceptions::ValidationFailedException) {
139
- @ad.save(true)
140
- }
141
- end
142
-
143
- context "has a parent" do
144
- setup do
145
- @ad.added_to_relationship(@caller)
146
- VirtualBox::Command.stubs(:vboxmanage)
147
- end
148
-
149
- should "not call destroy since its a new record" do
150
- @ad.expects(:destroy).never
151
- assert @ad.save
152
- end
153
-
154
- should "call the proper vboxcommand" do
155
- VirtualBox::Command.expects(:vboxmanage).with("storageattach", @vm.name, "--storagectl", @caller.name, "--port", @ad.port, "--device", "0", "--type", @image.image_type, "--medium", @ad.medium)
156
- @ad.save
157
- end
158
-
159
- should "return false if the command failed" do
160
- VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
161
- assert !@ad.save
162
- end
163
-
164
- should "return true if the command was a success" do
165
- assert @ad.save
166
- end
167
-
168
- should "raise an exception if true sent to save and error occured" do
169
- VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
170
- assert_raises(VirtualBox::Exceptions::CommandFailedException) {
171
- @ad.save(true)
172
- }
173
- end
174
-
175
- should "not be a new record after saving" do
176
- assert @ad.new_record?
177
- assert @ad.save
178
- assert !@ad.new_record?
179
- end
180
-
181
- should "not be changed after saving" do
182
- assert @ad.changed?
183
- assert @ad.save
184
- assert !@ad.changed?
185
- end
186
- end
187
- end
188
-
189
- context "constructor" do
190
- should "call populate_from_data if 3 args are given" do
191
- VirtualBox::AttachedDevice.any_instance.expects(:populate_from_data).with(1,2,3).once
192
- VirtualBox::AttachedDevice.new(1,2,3)
193
- end
194
-
195
- should "call populate_attributes if 1 arg is given" do
196
- VirtualBox::AttachedDevice.any_instance.expects(:populate_attributes).with(1).once
197
- ad = VirtualBox::AttachedDevice.new(1)
198
- assert ad.new_record?
199
- end
200
-
201
- should "raise a NoMethodError if anything other than 0,1,or 3 arguments" do
202
- # 9 seems like a reasonable max (maybe just a bit unreasonable!)
203
- 2.upto(9) do |i|
204
- next if i == 3
205
- args = Array.new(i, "A")
206
-
207
- assert_raises(NoMethodError) {
208
- VirtualBox::AttachedDevice.new(*args)
209
- }
210
- end
211
- end
212
- end
213
-
214
- context "destroying" do
215
- setup do
216
- @value = VirtualBox::AttachedDevice.populate_relationship(@caller, mock_xml_doc)
217
- @value = @value[0]
218
-
219
- @image = mock("image")
220
- @value.stubs(:image).returns(@image)
221
-
222
- VirtualBox::Command.stubs(:execute)
223
- end
224
-
225
- should "simply call destroy on each object when destroying the relationship" do
226
- obj_one = mock("one")
227
- obj_two = mock("two")
228
-
229
- obj_one.expects(:destroy).with("HELLO").once
230
- obj_two.expects(:destroy).with("HELLO").once
231
-
232
- VirtualBox::AttachedDevice.destroy_relationship(self, [obj_one, obj_two], "HELLO")
233
- end
234
-
235
- should "destroy with the specified port if set" do
236
- VirtualBox::Command.expects(:vboxmanage).with("storageattach", @vm.name, "--storagectl", @caller.name, "--port", 80, "--device", "0", "--medium", "none")
237
- @value.destroy(:port => 80)
238
- end
239
-
240
- should "destroy with the default port if not other port is specified" do
241
- VirtualBox::Command.expects(:vboxmanage).with("storageattach", @vm.name, "--storagectl", @caller.name, "--port", @value.port, "--device", "0", "--medium", "none")
242
- @value.destroy
243
- end
244
-
245
- should "not destroy image by default" do
246
- @image.expects(:destroy).never
247
- @value.destroy
248
- end
249
-
250
- should "destroy image if flag is set" do
251
- @image.expects(:destroy).once
252
- @value.destroy({
253
- :destroy_image => true
254
- })
255
- end
256
-
257
- should "ignore destroy image flag if image is nil" do
258
- @value.expects(:image).once.returns(nil)
259
- @value.destroy({
260
- :destroy_image => true
261
- })
262
- end
263
-
264
- should "return false if destroy failed" do
265
- VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
266
- assert !@value.destroy
267
- end
268
-
269
- should "raise an exception if destroy failed and an error occured" do
270
- VirtualBox::Command.stubs(:vboxmanage).raises(VirtualBox::Exceptions::CommandFailedException)
271
- assert_raises(VirtualBox::Exceptions::CommandFailedException) {
272
- @value.destroy({}, true)
273
- }
274
- end
275
-
276
- should "forward raise_errors flag to image.destroy" do
277
- @image.expects(:destroy).with(true).once
278
- @value.destroy({:destroy_image => true}, true)
279
- end
280
- end
281
-
282
- context "populating relationships" do
283
- setup do
284
- @value = VirtualBox::AttachedDevice.populate_relationship(@caller, mock_xml_doc)
285
- end
286
-
287
- should "create the correct amount of objects" do
288
- assert_equal 2, @value.length
289
- end
290
-
291
- should "create objects with proper values" do
292
- obj = @value[0]
293
- assert_equal "none", obj.medium
294
- assert_equal "2c16dd48-4cf1-497e-98fa-84ed55cfe71f", obj.uuid
295
- assert_equal "0", obj.port
296
-
297
- obj = @value[1]
298
- assert_equal "emptydrive", obj.medium
299
- assert_nil obj.uuid
300
- assert_equal "1", obj.port
301
- end
302
- end
303
- end