virtual_box 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/LICENSE +21 -0
- data/Manifest +17 -0
- data/README.textile +19 -0
- data/Rakefile +28 -0
- data/lib/virtual_box.rb +12 -0
- data/lib/virtual_box/command_line.rb +27 -0
- data/lib/virtual_box/version.rb +46 -0
- data/lib/virtual_box/vm.rb +35 -0
- data/lib/virtual_box/vm/general_settings.rb +136 -0
- data/lib/virtual_box/vm/identity.rb +43 -0
- data/lib/virtual_box/vm/lifecycle.rb +42 -0
- data/test/command_line_test.rb +19 -0
- data/test/general_settings_test.rb +20 -0
- data/test/lifecycle_test.rb +64 -0
- data/test/version_test.rb +56 -0
- data/testdata/golden_general_params.txt +1 -0
- data/virtual_box.gemspec +37 -0
- metadata +108 -0
data/CHANGELOG
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.0.1. Initial release.
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Zergling.Net
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
lib/virtual_box/command_line.rb
|
3
|
+
lib/virtual_box/version.rb
|
4
|
+
lib/virtual_box/vm/general_settings.rb
|
5
|
+
lib/virtual_box/vm/identity.rb
|
6
|
+
lib/virtual_box/vm/lifecycle.rb
|
7
|
+
lib/virtual_box/vm.rb
|
8
|
+
lib/virtual_box.rb
|
9
|
+
LICENSE
|
10
|
+
Manifest
|
11
|
+
Rakefile
|
12
|
+
README.textile
|
13
|
+
test/command_line_test.rb
|
14
|
+
test/general_settings_test.rb
|
15
|
+
test/lifecycle_test.rb
|
16
|
+
test/version_test.rb
|
17
|
+
testdata/golden_general_params.txt
|
data/README.textile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
h1. VirtualBox
|
2
|
+
|
3
|
+
This gem is a Ruby API for VirtualBox, Sun's open-source virtualization software
|
4
|
+
that supports Linux, Mac OS X, and Windows.
|
5
|
+
|
6
|
+
h2. Features
|
7
|
+
|
8
|
+
Currently, the gem supports the following features:
|
9
|
+
* (work in progress) creating and starting virtual machines
|
10
|
+
* VirtualBox version detection (OSE vs. regular)
|
11
|
+
|
12
|
+
h2. Contributions
|
13
|
+
|
14
|
+
Please don't hesitate to fork the project and send pull requests.
|
15
|
+
|
16
|
+
Right now, the API is built on top of the VBoxManage command-line utility. This
|
17
|
+
is an easy implementation, but the performance leaves to be desired. If someone
|
18
|
+
cares enough, VirtualBox has a binary API based on XPCOM (Linux, OS X) / COM
|
19
|
+
(Windows). Changes for using the binary API would be greatly appreciated.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Rakefile that uses echoe to manage virtual_box's gemspec.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'echoe'
|
9
|
+
|
10
|
+
Echoe.new('virtual_box') do |p|
|
11
|
+
p.project = 'zerglings' # rubyforge project
|
12
|
+
|
13
|
+
p.author = 'Victor Costan'
|
14
|
+
p.email = 'victor@zergling.net'
|
15
|
+
p.summary = "Ruby API for VirtualBox (Sun's OSS virtualization software)."
|
16
|
+
p.url = 'http://github.com/costan/virtual_box'
|
17
|
+
p.dependencies = []
|
18
|
+
p.development_dependencies = ["echoe >=3.1.1", "flexmock >=0.8.6"]
|
19
|
+
|
20
|
+
p.need_tar_gz = true
|
21
|
+
p.need_zip = true
|
22
|
+
p.rdoc_pattern = /^(lib|bin|tasks|ext)|^BUILD|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/
|
23
|
+
end
|
24
|
+
|
25
|
+
if $0 == __FILE__
|
26
|
+
Rake.application = Rake::Application.new
|
27
|
+
Rake.application.run
|
28
|
+
end
|
data/lib/virtual_box.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Main include file for the virtual_box gem.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require 'virtual_box/command_line.rb'
|
8
|
+
require 'virtual_box/version.rb'
|
9
|
+
require 'virtual_box/vm/general_settings.rb'
|
10
|
+
require 'virtual_box/vm/identity.rb'
|
11
|
+
require 'virtual_box/vm/lifecycle.rb'
|
12
|
+
require 'virtual_box/vm.rb'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Interface to the command line.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require 'english'
|
8
|
+
|
9
|
+
# :nodoc: namespace
|
10
|
+
module VirtualBox
|
11
|
+
|
12
|
+
|
13
|
+
# Runs a command in a sub-shell, waiting until the command completes.
|
14
|
+
#
|
15
|
+
# Args:
|
16
|
+
# command:: a string containing the command to be executed
|
17
|
+
#
|
18
|
+
# Returns:
|
19
|
+
# a hash with the following keys:
|
20
|
+
# :status:: the command's exit status
|
21
|
+
# :output:: a string with the command's output
|
22
|
+
def self.shell_command(command)
|
23
|
+
output = Kernel.`(command)
|
24
|
+
{ :status => $CHILD_STATUS, :output => output }
|
25
|
+
end
|
26
|
+
|
27
|
+
end # namespace VirtualBox
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# VirtualBox version detection.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
# :nodoc: namespace
|
8
|
+
module VirtualBox
|
9
|
+
@version_info = nil
|
10
|
+
|
11
|
+
# True if the installed VirtualBox is the open-source edition.
|
12
|
+
#
|
13
|
+
# The open-source edition of VirtualBox has some limitations, such as no support
|
14
|
+
# for RDP and USB devices.
|
15
|
+
def self.ose?
|
16
|
+
version_info ? (version_info[:edition] == 'OSE') : nil
|
17
|
+
end
|
18
|
+
|
19
|
+
# Version information about the installed VirtualBox.
|
20
|
+
#
|
21
|
+
# Returns:
|
22
|
+
# false if VirtualBox is not installed; otherwise, a hash with the keys:
|
23
|
+
# revision:: (number) the SVN revision that VirtualBox is built off of
|
24
|
+
# edition:: the VirtualBox edition (nil for the personal edition, 'OSE'
|
25
|
+
# for the open-source edition)
|
26
|
+
# version:: the VirtualBox version (e.g. '3.0.4')
|
27
|
+
def self.version_info
|
28
|
+
return @version_info unless @version_info.nil?
|
29
|
+
|
30
|
+
cmd_result = shell_command 'VBoxManage --version'
|
31
|
+
return @version_info = false if cmd_result[:status] != 0
|
32
|
+
|
33
|
+
output = cmd_result[:output].strip
|
34
|
+
@version_info = {}
|
35
|
+
if revision_offset = output.rindex('r')
|
36
|
+
@version_info[:revision] = output[revision_offset + 1, output.length].to_i
|
37
|
+
output.slice! revision_offset..-1
|
38
|
+
end
|
39
|
+
if edition_offset = output.rindex('_')
|
40
|
+
@version_info[:edition] = output[edition_offset + 1, output.length]
|
41
|
+
output.slice! edition_offset..-1
|
42
|
+
end
|
43
|
+
@version_info[:version] = output
|
44
|
+
@version_info
|
45
|
+
end
|
46
|
+
end # namespace VirtualBox
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Definition for the main VM class.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
# :nodoc: namespace
|
8
|
+
module VirtualBox
|
9
|
+
|
10
|
+
# A VirtualBox virtual machine.
|
11
|
+
class VM
|
12
|
+
include GeneralSettings
|
13
|
+
include Identity
|
14
|
+
include Lifecycle
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
reset_identity
|
18
|
+
reset_settings
|
19
|
+
end
|
20
|
+
|
21
|
+
# Resets the VM's settings to their defaults.
|
22
|
+
#
|
23
|
+
# The defaults are chosen somewhat arbitrarily by the gem's author.
|
24
|
+
def reset_settings
|
25
|
+
reset_general_settings
|
26
|
+
end
|
27
|
+
|
28
|
+
# Arguments to "VBoxManage modifyvm" describing the VM's settings.
|
29
|
+
def modifyvm_params
|
30
|
+
params = ''
|
31
|
+
params << modifyvm_general_params
|
32
|
+
end
|
33
|
+
end # class VM
|
34
|
+
|
35
|
+
end # namespace VirtualBox
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# General VM settings, covered in section 8.5.1 of the VirtualBox User Manual.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
# :nodoc: namespace
|
8
|
+
module VirtualBox
|
9
|
+
|
10
|
+
# :nodoc: documented in vm.rb
|
11
|
+
class VM
|
12
|
+
|
13
|
+
|
14
|
+
# Mix-in for the VM class covering the general VM settings.
|
15
|
+
module GeneralSettings
|
16
|
+
# The amount of megabytes of RAM in the VM.
|
17
|
+
attr_accessor :ram
|
18
|
+
# The amount of megabytes of video RAM in the VM.
|
19
|
+
attr_accessor :video_ram
|
20
|
+
|
21
|
+
# Whether the VM supports PAE (36-bit address space).
|
22
|
+
attr_accessor :pae
|
23
|
+
# Whether the VM supports ACPI.
|
24
|
+
attr_accessor :acpi
|
25
|
+
# Whether the VM supports I/O APIC.
|
26
|
+
#
|
27
|
+
# This is necessary for 64-bit OSes, but makes the virtualization slower.
|
28
|
+
attr_accessor :io_apic
|
29
|
+
|
30
|
+
# Whether the VM attempts to use hardware support (Intel VT-x or AMD-V).
|
31
|
+
#
|
32
|
+
# Hardware virtualization can increase VM performance, especially used in
|
33
|
+
# conjunction with the other hardware virtualization options. However, using
|
34
|
+
# hardware virtualzation in conjunction with other hypervisors can crash the
|
35
|
+
# host machine.
|
36
|
+
attr_accessor :hardware_virtualization
|
37
|
+
# Whether the VM uses hardware support for nested paging.
|
38
|
+
#
|
39
|
+
# The option is used only if hardware_virtualization is set.
|
40
|
+
attr_accessor :nested_paging
|
41
|
+
# Whether the VM uses hardware support for tagged TLB (VPID).
|
42
|
+
#
|
43
|
+
# The option is used only if hardware_virtualization is set.
|
44
|
+
attr_accessor :tagged_tlb
|
45
|
+
|
46
|
+
# Whether the VM supports 3D acceleration.
|
47
|
+
#
|
48
|
+
# 3D acceleration will only work with the proper guest extensions.
|
49
|
+
attr_accessor :accelerate_3d
|
50
|
+
|
51
|
+
# Whether the BIOS logo will fade in when the VM boots.
|
52
|
+
attr_accessor :bios_logo_fade_in
|
53
|
+
# Whether the BIOS logo will fade out when the VM boots.
|
54
|
+
attr_accessor :bios_logo_fade_out
|
55
|
+
# The number of seconds to display the BIOS logo when the VM boots.
|
56
|
+
attr_accessor :bios_logo_display_time
|
57
|
+
# Whether the BIOS allows the user to temporarily override the boot VM device.
|
58
|
+
#
|
59
|
+
# If +false+, no override is allowed. Otherwise, the user can press F12 at
|
60
|
+
# boot time to select a boot device. The user gets a prompt at boot time if
|
61
|
+
# the value is +true+. If the value is +:menu_only+ the user does not get a
|
62
|
+
# prompt, but can still press F12 to select a device.
|
63
|
+
attr_accessor :bios_boot_menu
|
64
|
+
# Indicates the boot device search order for the VM's BIOS.
|
65
|
+
#
|
66
|
+
# This is an array that can contain the following symbols: +:floppy+, +:dvd+,
|
67
|
+
# +:disk+, +:net+. Symbols should not be repeated.
|
68
|
+
attr_accessor :boot_order
|
69
|
+
|
70
|
+
# Resets the VM's general settings to their defaults.
|
71
|
+
#
|
72
|
+
# The defaults are chosen somewhat arbitrarily by the gem's author.
|
73
|
+
def reset_general_settings
|
74
|
+
self.ram = 512
|
75
|
+
self.video_ram = 12
|
76
|
+
|
77
|
+
self.pae = false
|
78
|
+
self.acpi = true
|
79
|
+
self.io_apic = false
|
80
|
+
|
81
|
+
self.hardware_virtualization = true
|
82
|
+
self.nested_paging = true
|
83
|
+
self.tagged_tlb = true
|
84
|
+
|
85
|
+
self.accelerate_3d = false
|
86
|
+
|
87
|
+
self.bios_logo_fade_in = false
|
88
|
+
self.bios_logo_fade_out = false
|
89
|
+
self.bios_logo_display_time = 0
|
90
|
+
self.bios_boot_menu = false
|
91
|
+
|
92
|
+
self.boot_order = [:disk, :net, :dvd]
|
93
|
+
end
|
94
|
+
|
95
|
+
# Arguments to "VBoxManage modifyvm" describing the VM's general settings.
|
96
|
+
def modifyvm_general_params
|
97
|
+
params = ''
|
98
|
+
params << " --memory #{ram}"
|
99
|
+
params << " --vram #{video_ram}"
|
100
|
+
|
101
|
+
params << " --pae #{pae ? 'on' : 'off'}"
|
102
|
+
params << " --acpi #{acpi ? 'on' : 'off'}"
|
103
|
+
params << " --io_apic #{io_apic ? 'on' : 'off'}"
|
104
|
+
|
105
|
+
params << " --hwvirtex #{hardware_virtualization ? 'on' : 'off'}"
|
106
|
+
nested_paging_enabled = hardware_virtualization && nested_paging
|
107
|
+
params << " --nestedpaging #{nested_paging_enabled ? 'on' : 'off'}"
|
108
|
+
tagged_tlb_enabled = hardware_virtualization && tagged_tlb
|
109
|
+
params << " --vtxvpid #{tagged_tlb_enabled ? 'on' : 'off'}"
|
110
|
+
|
111
|
+
params << " --bioslogofadein #{@bios_logo_fade_in ? 'on' : 'off'}"
|
112
|
+
params << " --bioslogofadeout #{@bios_logo_fade_out ? 'on' : 'off'}"
|
113
|
+
params << " --bioslogodisplaytime #{@bios_logo_display_time}"
|
114
|
+
bios_boot_menu_str = case @bios_boot_menu
|
115
|
+
when false
|
116
|
+
'disabled'
|
117
|
+
when true
|
118
|
+
'messageandmenu'
|
119
|
+
when :menu_only
|
120
|
+
'message'
|
121
|
+
else
|
122
|
+
nil
|
123
|
+
end
|
124
|
+
params << " --biosbootmenu #{bios_boot_menu_str}"
|
125
|
+
unique_boot_order = boot_order.uniq
|
126
|
+
1.upto(4) do |i|
|
127
|
+
params << " --boot#{i} #{unique_boot_order[i - 1] || 'none'}"
|
128
|
+
end
|
129
|
+
|
130
|
+
params
|
131
|
+
end
|
132
|
+
end # module GeneralSettings
|
133
|
+
|
134
|
+
end # class VM
|
135
|
+
|
136
|
+
end # namespace VirtualBox
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# VM identity (name and UUID) management.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
# :nodoc: namespace
|
8
|
+
module VirtualBox
|
9
|
+
|
10
|
+
# :nodoc: documented in vm.rb
|
11
|
+
class VM
|
12
|
+
|
13
|
+
|
14
|
+
# Mix-in for the VM class covering identity management.
|
15
|
+
module Identity
|
16
|
+
# The VM's user-friendly name.
|
17
|
+
attr_accessor :name
|
18
|
+
|
19
|
+
# The VM's UUID (unique id).
|
20
|
+
attr_accessor :uuid
|
21
|
+
|
22
|
+
# Resets the VM's name and UUID.
|
23
|
+
def reset_identity
|
24
|
+
@name = nil
|
25
|
+
@uuid = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
# :nodoc: documented as attribute
|
29
|
+
def uuid
|
30
|
+
# TODO(overmind): obtain UUID from name if it's not available
|
31
|
+
@uuid
|
32
|
+
end
|
33
|
+
|
34
|
+
# :nodoc: documented as attribute
|
35
|
+
def name
|
36
|
+
# TODO(overmind): obtain name from UUID if it's not available
|
37
|
+
@name
|
38
|
+
end
|
39
|
+
end # module Lifecycle
|
40
|
+
|
41
|
+
end # class VM
|
42
|
+
|
43
|
+
end # namespace VirtualBox
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# VM life-cycle management.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
# :nodoc: namespace
|
8
|
+
module VirtualBox
|
9
|
+
|
10
|
+
# :nodoc: documented in vm.rb
|
11
|
+
class VM
|
12
|
+
|
13
|
+
|
14
|
+
# Mix-in for the VM class covering life-cycle management.
|
15
|
+
module Lifecycle
|
16
|
+
# Starts the virtual machine.
|
17
|
+
#
|
18
|
+
# The following options are supported:
|
19
|
+
# :gui:: if set to true, VMs will be started in a GUI; this is intended to
|
20
|
+
# help debugging
|
21
|
+
# :rdp:: if set to true, RDP support will be enabled; by default, RDP
|
22
|
+
# support is disabled; VirtualBox OSE does not support RDP, so the
|
23
|
+
# call will raise an exception
|
24
|
+
def start(options = {})
|
25
|
+
if options[:gui]
|
26
|
+
command = "VBoxManage startvm #{uuid} --type gui"
|
27
|
+
else
|
28
|
+
command = "VBoxHeadless --startvm #{uuid}"
|
29
|
+
end
|
30
|
+
|
31
|
+
if VirtualBox.ose?
|
32
|
+
raise 'Cannot enable RDP support on VirtualBox OSE' if options[:rdp]
|
33
|
+
else
|
34
|
+
command += " --vrdp #{options[:rdp] ? 'on' : 'off'}"
|
35
|
+
end
|
36
|
+
VirtualBox.shell_command(command)[:status] == 0
|
37
|
+
end
|
38
|
+
end # module Lifecycle
|
39
|
+
|
40
|
+
end # class VM
|
41
|
+
|
42
|
+
end # namespace VirtualBox
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Interface to the command line.
|
2
|
+
#
|
3
|
+
# Author:: Victor Costan
|
4
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
5
|
+
# License:: MIT
|
6
|
+
|
7
|
+
require 'virtual_box'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
|
11
|
+
class CommandLineTest < Test::Unit::TestCase
|
12
|
+
def test_shell_command
|
13
|
+
golden = { :status => 0, :output => "Hello\n" }
|
14
|
+
VirtualBox.shell_command 'echo Hello'
|
15
|
+
|
16
|
+
golden = { :status => 1, :output => "Boom\n" }
|
17
|
+
VirtualBox.shell_command 'ruby -e "print :Hello; exit 1"'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Author:: Victor Costan
|
2
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
3
|
+
# License:: MIT
|
4
|
+
|
5
|
+
require 'virtual_box'
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
|
9
|
+
class GeneralSettingsTest < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
@testdata_path = File.join(File.dirname(__FILE__), '..', 'testdata')
|
12
|
+
@vm = VirtualBox::VM.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_modifyvm_general_params
|
16
|
+
golden_params = File.read File.join(@testdata_path,
|
17
|
+
'golden_general_params.txt')
|
18
|
+
assert_equal golden_params, @vm.modifyvm_general_params
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Author:: Victor Costan
|
2
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
3
|
+
# License:: MIT
|
4
|
+
|
5
|
+
require 'virtual_box'
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'flexmock/test_unit'
|
10
|
+
|
11
|
+
|
12
|
+
class LifecycleTest < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
super
|
15
|
+
|
16
|
+
@uuid = 'test-uuid'
|
17
|
+
@vm = VirtualBox::VM.new
|
18
|
+
@vm.uuid = @uuid
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_start
|
22
|
+
flexmock(VirtualBox).should_receive(:ose?).and_return(false)
|
23
|
+
flexmock(VirtualBox).should_receive(:shell_command).once.
|
24
|
+
with("VBoxHeadless --startvm #{@uuid} --vrdp off").
|
25
|
+
and_return({:status => 0, :output => ""})
|
26
|
+
|
27
|
+
assert @vm.start
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_start_rdp
|
31
|
+
flexmock(VirtualBox).should_receive(:ose?).and_return(false)
|
32
|
+
flexmock(VirtualBox).should_receive(:shell_command).once.
|
33
|
+
with("VBoxHeadless --startvm #{@uuid} --vrdp on").
|
34
|
+
and_return({:status => 0, :output => ""})
|
35
|
+
|
36
|
+
assert @vm.start(:rdp => true)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_start_with_ose
|
40
|
+
flexmock(VirtualBox).should_receive(:ose?).and_return(true)
|
41
|
+
flexmock(VirtualBox).should_receive(:shell_command).once.
|
42
|
+
with("VBoxHeadless --startvm #{@uuid}").
|
43
|
+
and_return({:status => 0, :output => ""})
|
44
|
+
|
45
|
+
assert @vm.start
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_start_rdp_with_ose
|
49
|
+
flexmock(VirtualBox).should_receive(:ose?).and_return(true)
|
50
|
+
|
51
|
+
assert_raise RuntimeError do
|
52
|
+
@vm.start :rdp => true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_start_gui_with_error
|
57
|
+
flexmock(VirtualBox).should_receive(:ose?).and_return(false)
|
58
|
+
flexmock(VirtualBox).should_receive(:shell_command).once.
|
59
|
+
with("VBoxManage startvm #{@uuid} --type gui --vrdp off").
|
60
|
+
and_return({:status => 127, :output => ""})
|
61
|
+
|
62
|
+
assert_equal false, @vm.start(:gui => true)
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Author:: Victor Costan
|
2
|
+
# Copyright:: Copyright (C) 2009 Zergling.Net
|
3
|
+
# License:: MIT
|
4
|
+
|
5
|
+
require 'virtual_box'
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'flexmock/test_unit'
|
10
|
+
|
11
|
+
|
12
|
+
class VersionTest < Test::Unit::TestCase
|
13
|
+
def setup
|
14
|
+
super
|
15
|
+
|
16
|
+
# Hack to reset the cached version information.
|
17
|
+
VirtualBox.instance_variable_set :@version_info, nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_version_info_std
|
21
|
+
flexmock(VirtualBox).should_receive(:shell_command).once.
|
22
|
+
and_return({:status => 0, :output => "3.0.4r50677\n"})
|
23
|
+
|
24
|
+
assert_equal '3.0.4', VirtualBox.version_info[:version]
|
25
|
+
assert_equal nil, VirtualBox.version_info[:edition]
|
26
|
+
assert_equal 50677, VirtualBox.version_info[:revision]
|
27
|
+
|
28
|
+
assert_equal false, VirtualBox.ose?
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_version_info_ose
|
32
|
+
flexmock(VirtualBox).should_receive(:shell_command).once.
|
33
|
+
and_return({:status => 0, :output => "3.0.2_OSEr49928\n"})
|
34
|
+
|
35
|
+
assert_equal '3.0.2', VirtualBox.version_info[:version]
|
36
|
+
assert_equal 'OSE', VirtualBox.version_info[:edition]
|
37
|
+
assert_equal 49928, VirtualBox.version_info[:revision]
|
38
|
+
|
39
|
+
assert_equal true, VirtualBox.ose?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_version_info_none
|
43
|
+
flexmock(VirtualBox).should_receive(:shell_command).once.
|
44
|
+
and_return({:status => 127, :output => "3.0.2_OSEr49928\n"})
|
45
|
+
|
46
|
+
assert_equal false, VirtualBox.version_info
|
47
|
+
assert_equal nil, VirtualBox.ose?
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_live
|
51
|
+
assert_equal Hash, VirtualBox.version_info.class,
|
52
|
+
'version_info result should be a hash'
|
53
|
+
assert VirtualBox.version_info[:version],
|
54
|
+
'version_info should have a :version key'
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
--memory 512 --vram 12 --pae off --acpi on --io_apic off --hwvirtex on --nestedpaging on --vtxvpid on --bioslogofadein off --bioslogofadeout off --bioslogodisplaytime 0 --biosbootmenu disabled --boot1 disk --boot2 net --boot3 dvd --boot4 none
|
data/virtual_box.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{virtual_box}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Victor Costan"]
|
9
|
+
s.date = %q{2009-08-21}
|
10
|
+
s.description = %q{Ruby API for VirtualBox (Sun's OSS virtualization software).}
|
11
|
+
s.email = %q{victor@zergling.net}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/virtual_box/command_line.rb", "lib/virtual_box/version.rb", "lib/virtual_box/vm/general_settings.rb", "lib/virtual_box/vm/identity.rb", "lib/virtual_box/vm/lifecycle.rb", "lib/virtual_box/vm.rb", "lib/virtual_box.rb", "LICENSE", "README.textile"]
|
13
|
+
s.files = ["CHANGELOG", "lib/virtual_box/command_line.rb", "lib/virtual_box/version.rb", "lib/virtual_box/vm/general_settings.rb", "lib/virtual_box/vm/identity.rb", "lib/virtual_box/vm/lifecycle.rb", "lib/virtual_box/vm.rb", "lib/virtual_box.rb", "LICENSE", "Manifest", "Rakefile", "README.textile", "test/command_line_test.rb", "test/general_settings_test.rb", "test/lifecycle_test.rb", "test/version_test.rb", "testdata/golden_general_params.txt", "virtual_box.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/costan/virtual_box}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Virtual_box", "--main", "README.textile"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{zerglings}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Ruby API for VirtualBox (Sun's OSS virtualization software).}
|
20
|
+
s.test_files = ["test/command_line_test.rb", "test/general_settings_test.rb", "test/lifecycle_test.rb", "test/version_test.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 3
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_development_dependency(%q<echoe>, [">= 3.1.1"])
|
28
|
+
s.add_development_dependency(%q<flexmock>, [">= 0.8.6"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<echoe>, [">= 3.1.1"])
|
31
|
+
s.add_dependency(%q<flexmock>, [">= 0.8.6"])
|
32
|
+
end
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<echoe>, [">= 3.1.1"])
|
35
|
+
s.add_dependency(%q<flexmock>, [">= 0.8.6"])
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: virtual_box
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Costan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-21 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: echoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.1.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: flexmock
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.6
|
34
|
+
version:
|
35
|
+
description: Ruby API for VirtualBox (Sun's OSS virtualization software).
|
36
|
+
email: victor@zergling.net
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- CHANGELOG
|
43
|
+
- lib/virtual_box/command_line.rb
|
44
|
+
- lib/virtual_box/version.rb
|
45
|
+
- lib/virtual_box/vm/general_settings.rb
|
46
|
+
- lib/virtual_box/vm/identity.rb
|
47
|
+
- lib/virtual_box/vm/lifecycle.rb
|
48
|
+
- lib/virtual_box/vm.rb
|
49
|
+
- lib/virtual_box.rb
|
50
|
+
- LICENSE
|
51
|
+
- README.textile
|
52
|
+
files:
|
53
|
+
- CHANGELOG
|
54
|
+
- lib/virtual_box/command_line.rb
|
55
|
+
- lib/virtual_box/version.rb
|
56
|
+
- lib/virtual_box/vm/general_settings.rb
|
57
|
+
- lib/virtual_box/vm/identity.rb
|
58
|
+
- lib/virtual_box/vm/lifecycle.rb
|
59
|
+
- lib/virtual_box/vm.rb
|
60
|
+
- lib/virtual_box.rb
|
61
|
+
- LICENSE
|
62
|
+
- Manifest
|
63
|
+
- Rakefile
|
64
|
+
- README.textile
|
65
|
+
- test/command_line_test.rb
|
66
|
+
- test/general_settings_test.rb
|
67
|
+
- test/lifecycle_test.rb
|
68
|
+
- test/version_test.rb
|
69
|
+
- testdata/golden_general_params.txt
|
70
|
+
- virtual_box.gemspec
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/costan/virtual_box
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options:
|
77
|
+
- --line-numbers
|
78
|
+
- --inline-source
|
79
|
+
- --title
|
80
|
+
- Virtual_box
|
81
|
+
- --main
|
82
|
+
- README.textile
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
version:
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: "1.2"
|
96
|
+
version:
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project: zerglings
|
100
|
+
rubygems_version: 1.3.5
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Ruby API for VirtualBox (Sun's OSS virtualization software).
|
104
|
+
test_files:
|
105
|
+
- test/command_line_test.rb
|
106
|
+
- test/general_settings_test.rb
|
107
|
+
- test/lifecycle_test.rb
|
108
|
+
- test/version_test.rb
|