virtualbox 0.5.0 → 0.5.1
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/VERSION +1 -1
- data/lib/virtualbox/command.rb +10 -0
- data/lib/virtualbox/vm.rb +15 -19
- data/test/test_helper.rb +0 -2
- data/test/virtualbox/command_test.rb +29 -0
- data/test/virtualbox/vm_test.rb +16 -3
- data/virtualbox.gemspec +3 -3
- metadata +20 -9
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/virtualbox/command.rb
CHANGED
@@ -14,6 +14,16 @@ module VirtualBox
|
|
14
14
|
@@vboxmanage = "VBoxManage"
|
15
15
|
|
16
16
|
class <<self
|
17
|
+
# Returns a string of the version of VirtualBox installed, or nil if
|
18
|
+
# it can't detect VirtualBox.
|
19
|
+
#
|
20
|
+
# @return [String]
|
21
|
+
def version
|
22
|
+
result = execute("#{@@vboxmanage} --version")
|
23
|
+
return nil unless Command.success?
|
24
|
+
result.chomp
|
25
|
+
end
|
26
|
+
|
17
27
|
# Reads the XML file and returns a Nokogiri document. Reads the XML data
|
18
28
|
# from the specified file and returns a Nokogiri document.
|
19
29
|
#
|
data/lib/virtualbox/vm.rb
CHANGED
@@ -305,11 +305,7 @@ module VirtualBox
|
|
305
305
|
def load_attribute(name)
|
306
306
|
info = self.class.raw_info(@original_name)
|
307
307
|
|
308
|
-
if name == :state
|
309
|
-
# Simply force a state reload, and it'll write the attribute up
|
310
|
-
write_attribute(:state, info[:vmstate])
|
311
|
-
end
|
312
|
-
|
308
|
+
write_attribute(:state, info[:vmstate]) if name == :state
|
313
309
|
write_attribute(:synthcpu, info[:synthcpu]) unless loaded_attribute?(:synthcpu)
|
314
310
|
end
|
315
311
|
|
@@ -323,6 +319,7 @@ module VirtualBox
|
|
323
319
|
def state(reload=false)
|
324
320
|
if reload
|
325
321
|
load_attribute(:state)
|
322
|
+
clear_dirty!(:state)
|
326
323
|
end
|
327
324
|
|
328
325
|
read_attribute(:state)
|
@@ -332,13 +329,21 @@ module VirtualBox
|
|
332
329
|
# attributes of the virtual machine. If any related attributes were saved
|
333
330
|
# as well (such as storage controllers), those will be saved, too.
|
334
331
|
def save(raise_errors=false)
|
335
|
-
#
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
@original_name = name
|
332
|
+
# First save all the changed attributes in a single batch
|
333
|
+
saves = changes.inject([]) do |acc, kv|
|
334
|
+
key, values = kv
|
335
|
+
acc << ["--#{key}", values[1]]
|
340
336
|
end
|
341
337
|
|
338
|
+
# Flatten to pass into vboxmanage
|
339
|
+
saves.flatten!
|
340
|
+
|
341
|
+
# Save all the attributes in one command
|
342
|
+
Command.vboxmanage("modifyvm", @original_name, *saves)
|
343
|
+
|
344
|
+
# Now clear attributes and call super so relationships are saved
|
345
|
+
@original_name = name
|
346
|
+
clear_dirty!
|
342
347
|
super()
|
343
348
|
|
344
349
|
# Force reload
|
@@ -350,15 +355,6 @@ module VirtualBox
|
|
350
355
|
return false
|
351
356
|
end
|
352
357
|
|
353
|
-
# Saves a single attribute of the virtual machine. This should **not**
|
354
|
-
# be called except interally. Instead, you're probably looking for {#save}.
|
355
|
-
#
|
356
|
-
# **This method typically won't be used except internally.**
|
357
|
-
def save_attribute(key, value)
|
358
|
-
Command.vboxmanage("modifyvm", @original_name, "--#{key}", value)
|
359
|
-
super
|
360
|
-
end
|
361
|
-
|
362
358
|
# Exports a virtual machine. The virtual machine will be exported
|
363
359
|
# to the specified OVF file name. This directory will also have the
|
364
360
|
# `mf` file which contains the file checksums and also the virtual
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,35 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
2
|
|
3
3
|
class CommandTest < Test::Unit::TestCase
|
4
|
+
context "getting the version" do
|
5
|
+
setup do
|
6
|
+
VirtualBox::Command.stubs(:execute)
|
7
|
+
VirtualBox::Command.stubs(:success?).returns(true)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "run the command with the version flag" do
|
11
|
+
VirtualBox::Command.expects(:execute).with("VBoxManage --version").once.returns("7")
|
12
|
+
VirtualBox::Command.version
|
13
|
+
end
|
14
|
+
|
15
|
+
should "return the value of the command if it succeeded" do
|
16
|
+
version = "3.1.4r1940"
|
17
|
+
VirtualBox::Command.expects(:execute).returns(version)
|
18
|
+
assert_equal version, VirtualBox::Command.version
|
19
|
+
end
|
20
|
+
|
21
|
+
should "return the value of nil if the command failed" do
|
22
|
+
VirtualBox::Command.expects(:success?).returns(false)
|
23
|
+
assert_nil VirtualBox::Command.version
|
24
|
+
end
|
25
|
+
|
26
|
+
should "strip the newlines from the result" do
|
27
|
+
version = "3.1.4r1940"
|
28
|
+
VirtualBox::Command.expects(:execute).returns(version + "\n")
|
29
|
+
assert_equal version, VirtualBox::Command.version
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
4
33
|
context "parsing XML" do
|
5
34
|
should "open the file, parse it, and close the file" do
|
6
35
|
arg = "foo"
|
data/test/virtualbox/vm_test.rb
CHANGED
@@ -34,6 +34,12 @@ class VMTest < Test::Unit::TestCase
|
|
34
34
|
assert_equal "on", @vm.state
|
35
35
|
end
|
36
36
|
|
37
|
+
should "never have state as dirty" do
|
38
|
+
VirtualBox::VM.expects(:raw_info).returns({ :vmstate => "on" })
|
39
|
+
@vm.expects(:clear_dirty!).with(:state).once
|
40
|
+
@vm.state(true)
|
41
|
+
end
|
42
|
+
|
37
43
|
should "provide conveniance methods for determining VM state" do
|
38
44
|
VirtualBox::VM.expects(:raw_info).returns({ :vmstate => "poweroff" })
|
39
45
|
assert_equal "poweroff", @vm.state(true)
|
@@ -313,16 +319,23 @@ raw
|
|
313
319
|
end
|
314
320
|
|
315
321
|
should "save name first if changed, then following values should modify new VM" do
|
316
|
-
save_seq = sequence("save_seq")
|
317
322
|
new_name = "foo2"
|
318
|
-
VirtualBox::Command.expects(:vboxmanage).with("modifyvm", @name, "--name", new_name)
|
319
|
-
VirtualBox::Command.expects(:vboxmanage).with("modifyvm", new_name, "--ostype", "Zubuntu").in_sequence(save_seq)
|
323
|
+
VirtualBox::Command.expects(:vboxmanage).with("modifyvm", @name, "--ostype", "Zubuntu", "--name", new_name)
|
320
324
|
|
321
325
|
@vm.name = new_name
|
322
326
|
@vm.ostype = "Zubuntu"
|
323
327
|
assert @vm.save
|
324
328
|
end
|
325
329
|
|
330
|
+
should "save the new name as the original name after saving" do
|
331
|
+
new_name = "foo2"
|
332
|
+
assert_equal @name, @vm.instance_variable_get(:@original_name)
|
333
|
+
|
334
|
+
@vm.name = new_name
|
335
|
+
assert @vm.save
|
336
|
+
assert_equal new_name, @vm.instance_variable_get(:@original_name)
|
337
|
+
end
|
338
|
+
|
326
339
|
should "save the relationships as well" do
|
327
340
|
VirtualBox::Nic.expects(:save_relationship).once
|
328
341
|
VirtualBox::StorageController.expects(:save_relationship).once
|
data/virtualbox.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{virtualbox}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mitchell Hashimoto"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-03-09}
|
13
13
|
s.description = %q{Create and modify virtual machines in VirtualBox using pure ruby.}
|
14
14
|
s.email = %q{mitchell.hashimoto@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -79,7 +79,7 @@ Gem::Specification.new do |s|
|
|
79
79
|
s.homepage = %q{http://github.com/mitchellh/virtualbox}
|
80
80
|
s.rdoc_options = ["--charset=UTF-8"]
|
81
81
|
s.require_paths = ["lib"]
|
82
|
-
s.rubygems_version = %q{1.3.
|
82
|
+
s.rubygems_version = %q{1.3.6}
|
83
83
|
s.summary = %q{Create and modify virtual machines in VirtualBox using pure ruby.}
|
84
84
|
s.test_files = [
|
85
85
|
"test/test_helper.rb",
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virtualbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 1
|
9
|
+
version: 0.5.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Mitchell Hashimoto
|
@@ -9,19 +14,23 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-03-09 00:00:00 -08:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: nokogiri
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 4
|
30
|
+
- 1
|
23
31
|
version: 1.4.1
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
description: Create and modify virtual machines in VirtualBox using pure ruby.
|
26
35
|
email: mitchell.hashimoto@gmail.com
|
27
36
|
executables: []
|
@@ -103,18 +112,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
112
|
requirements:
|
104
113
|
- - ">="
|
105
114
|
- !ruby/object:Gem::Version
|
115
|
+
segments:
|
116
|
+
- 0
|
106
117
|
version: "0"
|
107
|
-
version:
|
108
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
119
|
requirements:
|
110
120
|
- - ">="
|
111
121
|
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
112
124
|
version: "0"
|
113
|
-
version:
|
114
125
|
requirements: []
|
115
126
|
|
116
127
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.3.
|
128
|
+
rubygems_version: 1.3.6
|
118
129
|
signing_key:
|
119
130
|
specification_version: 3
|
120
131
|
summary: Create and modify virtual machines in VirtualBox using pure ruby.
|