lab 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/config/test_lab.yml +11 -0
- data/config/test_targets.yml +21 -0
- data/lib/lab/controller/dynagen_controller.rb +6 -6
- data/lib/lab/controller/remote_esx_controller.rb +51 -51
- data/lib/lab/controller/remote_esxi_controller.rb +62 -0
- data/lib/lab/controller/remote_workstation_controller.rb +12 -12
- data/lib/lab/controller/virtualbox_controller.rb +16 -16
- data/lib/lab/controller/workstation_controller.rb +9 -9
- data/lib/lab/controller/workstation_vixr_controller.rb +9 -9
- data/lib/lab/controllers.rb +1 -3
- data/lib/lab/driver/dynagen_driver.rb +32 -32
- data/lib/lab/driver/fog_driver.rb +144 -144
- data/lib/lab/driver/remote_esxi_driver.rb +177 -0
- data/lib/lab/driver/remote_workstation_driver.rb +181 -181
- data/lib/lab/driver/virtualbox_driver.rb +132 -132
- data/lib/lab/driver/vm_driver.rb +177 -177
- data/lib/lab/driver/workstation_driver.rb +218 -218
- data/lib/lab/driver/workstation_vixr_driver.rb +108 -108
- data/lib/lab/drivers.rb +1 -1
- data/lib/lab/modifier/backtrack5_modifier.rb +8 -8
- data/lib/lab/modifier/dos_modifier.rb +3 -3
- data/lib/lab/modifier/test_modifier.rb +6 -6
- data/lib/lab/version.rb +1 -1
- data/lib/lab/vm.rb +242 -242
- data/lib/lab/vm_controller.rb +217 -211
- data/src/Gemfile +4 -0
- data/src/README.md +80 -0
- data/src/Rakefile +1 -0
- data/src/TODO +15 -0
- data/src/config/test_lab.yml +11 -0
- data/src/config/test_targets.yml +21 -0
- data/src/lab.gemspec +35 -0
- data/src/lib/lab.rb +2 -0
- data/src/lib/lab/controller/dynagen_controller.rb +14 -0
- data/src/lib/lab/controller/fog_controller.rb +6 -0
- data/src/lib/lab/controller/remote_esxi_controller.rb +62 -0
- data/src/lib/lab/controller/remote_workstation_controller.rb +22 -0
- data/src/lib/lab/controller/virtualbox_controller.rb +25 -0
- data/src/lib/lab/controller/vsphere_controller.rb +18 -0
- data/src/lib/lab/controller/workstation_controller.rb +17 -0
- data/src/lib/lab/controller/workstation_vixr_controller.rb +19 -0
- data/src/lib/lab/controllers.rb +9 -0
- data/src/lib/lab/driver/dynagen_driver.rb +47 -0
- data/src/lib/lab/driver/fog_driver.rb +104 -0
- data/src/lib/lab/driver/remote_esxi_driver.rb +177 -0
- data/src/lib/lab/driver/remote_workstation_driver.rb +197 -0
- data/src/lib/lab/driver/virtualbox_driver.rb +142 -0
- data/src/lib/lab/driver/vm_driver.rb +195 -0
- data/src/lib/lab/driver/vsphere_driver.rb +120 -0
- data/src/lib/lab/driver/workstation_driver.rb +234 -0
- data/src/lib/lab/driver/workstation_vixr_driver.rb +126 -0
- data/src/lib/lab/drivers.rb +9 -0
- data/src/lib/lab/modifier/backtrack5_modifier.rb +16 -0
- data/src/lib/lab/modifier/dos_modifier.rb +14 -0
- data/src/lib/lab/modifier/test_modifier.rb +16 -0
- data/src/lib/lab/modifiers.rb +3 -0
- data/src/lib/lab/version.rb +3 -0
- data/src/lib/lab/vm.rb +269 -0
- data/src/lib/lab/vm_controller.rb +275 -0
- data/src/test/.gitkeep +0 -0
- metadata +51 -12
- data/lib/lab/driver/remote_esx_driver.rb +0 -177
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'vm_driver'
|
2
|
+
|
3
|
+
##
|
4
|
+
## $Id$
|
5
|
+
##
|
6
|
+
|
7
|
+
# This driver was built against:
|
8
|
+
# VMware ESXi Host Agent 4.1.0 build-348481
|
9
|
+
|
10
|
+
module Lab
|
11
|
+
module Drivers
|
12
|
+
|
13
|
+
class RemoteEsxiDriver < VmDriver
|
14
|
+
|
15
|
+
def initialize(config)
|
16
|
+
unless config['user'] then raise ArgumentError, "Must provide a username" end
|
17
|
+
unless config['host'] then raise ArgumentError, "Must provide a hostname" end
|
18
|
+
|
19
|
+
super(config)
|
20
|
+
|
21
|
+
@user = filter_command(config['user'])
|
22
|
+
@host = filter_command(config['host'])
|
23
|
+
@port = config['port']
|
24
|
+
end
|
25
|
+
|
26
|
+
def start
|
27
|
+
remote_system_command("vim-cmd vmsvc/power.on #{@vmid}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def stop
|
31
|
+
remote_system_command("vim-cmd vmsvc/power.off #{@vmid}")
|
32
|
+
end
|
33
|
+
|
34
|
+
def suspend
|
35
|
+
remote_system_command("vim-cmd vmsvc/power.suspend #{@vmid}")
|
36
|
+
end
|
37
|
+
|
38
|
+
def pause
|
39
|
+
remote_system_command("vim-cmd vmsvc/power.suspend #{@vmid}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def resume
|
43
|
+
remote_system_command("vim-cmd vmsvc/power.suspendResume #{@vmid}")
|
44
|
+
end
|
45
|
+
|
46
|
+
def reset
|
47
|
+
remote_system_command("vim-cmd vmsvc/power.reset #{@vmid}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_snapshot(snapshot)
|
51
|
+
snapshot = filter_input(snapshot)
|
52
|
+
|
53
|
+
remote_system_command("vim-cmd vmsvc/snapshot.create #{@vmid} #{snapshot} \'lab created snapshot\' 1 true")
|
54
|
+
end
|
55
|
+
|
56
|
+
def revert_snapshot(snapshot)
|
57
|
+
|
58
|
+
snapshots = get_snapshots
|
59
|
+
|
60
|
+
# Look through our snapshot list, choose the right one based on display_name
|
61
|
+
snapshots.each do |snapshot_obj|
|
62
|
+
|
63
|
+
#puts "DEBUG: checking #{snapshot_obj}"
|
64
|
+
|
65
|
+
if snapshot_obj[:display_name].downcase == snapshot.downcase
|
66
|
+
snapshot_identifier = snapshot_obj[:name].join(" ")
|
67
|
+
|
68
|
+
#puts "DEBUG: I would revert to #{snapshot_obj}"
|
69
|
+
remote_system_command("vim-cmd vmsvc/snapshot.revert #{@vmid} 0 #{snapshot_identifier}")
|
70
|
+
return true
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# If we got here, the snapshot didn't exist
|
75
|
+
raise "Invalid Snapshot Name"
|
76
|
+
end
|
77
|
+
|
78
|
+
def delete_snapshot(snapshot, remove_children=false)
|
79
|
+
snapshots = get_snapshots
|
80
|
+
|
81
|
+
# Look through our snapshot list, choose the right one based on display_name
|
82
|
+
snapshots.each do |snapshot_obj|
|
83
|
+
|
84
|
+
#puts "DEBUG: checking #{snapshot_obj}"
|
85
|
+
|
86
|
+
if snapshot_obj[:display_name].downcase == snapshot.downcase
|
87
|
+
snapshot_identifier = snapshot_obj[:name].join(" ")
|
88
|
+
remote_system_command("vim-cmd vmsvc/snapshot.remove #{@vmid} #{remove_children} #{snapshot_identifier}")
|
89
|
+
return true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# If we got here, the snapshot didn't exist
|
94
|
+
raise "Invalid Snapshot Name"
|
95
|
+
end
|
96
|
+
|
97
|
+
def delete_all_snapshots
|
98
|
+
remote_system_command("vim-cmd vmsvc/snapshot.removeall #{@vmid}")
|
99
|
+
end
|
100
|
+
|
101
|
+
def run_command(command)
|
102
|
+
raise "Not Implemented"
|
103
|
+
end
|
104
|
+
|
105
|
+
def copy_from(from, to)
|
106
|
+
if @os == "linux"
|
107
|
+
scp_from(from, to)
|
108
|
+
else
|
109
|
+
raise "Unimplemented"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def copy_to(from, to)
|
114
|
+
if @os == "linux"
|
115
|
+
scp_to(from, to)
|
116
|
+
else
|
117
|
+
raise "Unimplemented"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def check_file_exists(file)
|
122
|
+
raise "Not Implemented"
|
123
|
+
end
|
124
|
+
|
125
|
+
def create_directory(directory)
|
126
|
+
raise "Not Implemented"
|
127
|
+
end
|
128
|
+
|
129
|
+
def cleanup
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
def running?
|
134
|
+
power_status_string = `ssh #{@user}@#{@host} \"vim-cmd vmsvc/power.getstate #{@vmid}\"`
|
135
|
+
return true if power_status_string =~ /Powered on/
|
136
|
+
false
|
137
|
+
end
|
138
|
+
|
139
|
+
def get_snapshots
|
140
|
+
# Command take the format:
|
141
|
+
# vmware-vim-cmd vmsvc/snapshot.revert [vmid: int] [snapshotlevel: int] [snapshotindex: int]
|
142
|
+
output = `ssh #{@user}@#{@host} \"vim-cmd vmsvc/snapshot.get #{@vmid}\"`
|
143
|
+
|
144
|
+
# this keeps track of the snapshots, takes the form:
|
145
|
+
#[ {:name => [0,0], :display_name => "String containing the snapshotname},
|
146
|
+
# {:name => [0,1], :display_name => "String containing the snapshotname}, ]
|
147
|
+
# ...
|
148
|
+
snapshots = []
|
149
|
+
|
150
|
+
# Use these to keep track of the parsing...
|
151
|
+
current_tree = -1
|
152
|
+
current_num = 0
|
153
|
+
count = 0
|
154
|
+
|
155
|
+
# Do the parsing & stick the snapshots in the snapshots array
|
156
|
+
output_lines = output.split("\n")
|
157
|
+
output_lines.each do |line|
|
158
|
+
if line.include?("|") # this is a new snapshot
|
159
|
+
if line.include?("ROOT") # it's a root
|
160
|
+
current_num = 0
|
161
|
+
current_tree = current_tree + 1 # new tree
|
162
|
+
snapshots << { :name => [current_num, current_tree], :display_name => output_lines[count+1].split(":").last.strip }
|
163
|
+
else
|
164
|
+
current_num = current_num + 1 # new snapshot in current tree
|
165
|
+
snapshots << { :name => [current_num, current_tree], :display_name => output_lines[count+1].split(":").last.strip }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
count = count+1
|
169
|
+
end
|
170
|
+
|
171
|
+
snapshots
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'vm_driver'
|
2
|
+
|
3
|
+
##
|
4
|
+
## $Id$
|
5
|
+
##
|
6
|
+
|
7
|
+
module Lab
|
8
|
+
module Drivers
|
9
|
+
|
10
|
+
class RemoteWorkstationDriver < VmDriver
|
11
|
+
|
12
|
+
attr_accessor :location # among other things
|
13
|
+
|
14
|
+
def initialize(config)
|
15
|
+
|
16
|
+
unless config['user'] then raise ArgumentError, "Must provide a username" end
|
17
|
+
unless config['host'] then raise ArgumentError, "Must provide a hostname" end
|
18
|
+
|
19
|
+
super(config)
|
20
|
+
|
21
|
+
@user = filter_command(config['user'])
|
22
|
+
@host = filter_command(config['host'])
|
23
|
+
end
|
24
|
+
|
25
|
+
def start
|
26
|
+
remote_system_command("vmrun -T ws start \'#{@location}\' nogui")
|
27
|
+
end
|
28
|
+
|
29
|
+
def stop
|
30
|
+
remote_system_command("vmrun -T ws stop \'#{@location}\' nogui")
|
31
|
+
end
|
32
|
+
|
33
|
+
def suspend
|
34
|
+
remote_system_command("vmrun -T ws suspend \'#{@location}\' nogui")
|
35
|
+
end
|
36
|
+
|
37
|
+
def pause
|
38
|
+
remote_system_command("vmrun -T ws pause \'#{@location}\' nogui")
|
39
|
+
end
|
40
|
+
|
41
|
+
def reset
|
42
|
+
remote_system_command("vmrun -T ws reset \'#{@location}\' nogui")
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_snapshot(snapshot)
|
46
|
+
snapshot = filter_input(snapshot)
|
47
|
+
remote_system_command("vmrun -T ws snapshot \'#{@location}\' #{snapshot} nogui")
|
48
|
+
end
|
49
|
+
|
50
|
+
def revert_snapshot(snapshot)
|
51
|
+
snapshot = filter_input(snapshot)
|
52
|
+
remote_system_command("vmrun -T ws revertToSnapshot \'#{@location}\' #{snapshot} nogui")
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete_snapshot(snapshot)
|
56
|
+
snapshot = filter_input(snapshot)
|
57
|
+
remote_system_command("vmrun -T ws deleteSnapshot \'#{@location}\' #{snapshot} nogui" )
|
58
|
+
end
|
59
|
+
|
60
|
+
def run_command(command)
|
61
|
+
# generate local & remote script paths
|
62
|
+
script_rand_name = rand(10000)
|
63
|
+
|
64
|
+
if @os == "windows"
|
65
|
+
local_tempfile_path = "/tmp/lab_script_#{script_rand_name}.bat"
|
66
|
+
remote_tempfile_path = "C:\\\\lab_script_#{script_rand_name}.bat"
|
67
|
+
remote_run_command = remote_tempfile_path
|
68
|
+
else
|
69
|
+
local_tempfile_path = "/tmp/lab_script_#{script_rand_name}.sh"
|
70
|
+
remote_tempfile_path = "/tmp/lab_script_#{script_rand_name}.sh"
|
71
|
+
remote_run_command = "/bin/sh #{remote_tempfile_path}"
|
72
|
+
end
|
73
|
+
|
74
|
+
# write out our script locally
|
75
|
+
File.open(local_tempfile_path, 'w') {|f| f.write(command) }
|
76
|
+
|
77
|
+
# we really can't filter command, so we're gonna stick it in a script
|
78
|
+
if @tools
|
79
|
+
# copy it to the vm host - this is because we're a remote driver
|
80
|
+
remote_copy_command = "scp #{local_tempfile_path} #{@user}@#{@host}:#{local_tempfile_path}"
|
81
|
+
system_command(remote_copy_command)
|
82
|
+
|
83
|
+
# we have it on the vm host, copy it to the vm guest
|
84
|
+
vmrunstr = "ssh #{@user}@#{@host} \"vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
85
|
+
"copyFileFromHostToGuest \'#{@location}\' \'#{local_tempfile_path}\' " +
|
86
|
+
"\'#{remote_tempfile_path}\' nogui\""
|
87
|
+
system_command(vmrunstr)
|
88
|
+
|
89
|
+
# now run it on the guest
|
90
|
+
vmrunstr = "ssh #{@user}@#{@host} \"vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
91
|
+
"runProgramInGuest \'#{@location}\' -noWait -activeWindow \'#{remote_run_command}\'"
|
92
|
+
system_command(vmrunstr)
|
93
|
+
|
94
|
+
## CLEANUP
|
95
|
+
# delete it on the guest
|
96
|
+
vmrunstr = "ssh #{@user}@#{@host} \"vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
97
|
+
"deleteFileInGuest \'#{@location}\' \'#{remote_tempfile_path}\'"
|
98
|
+
system_command(vmrunstr)
|
99
|
+
|
100
|
+
# and delete it on the vm host
|
101
|
+
vmhost_delete_command = "ssh #{@user}@#{@host} rm #{local_tempfile_path}"
|
102
|
+
system_command(vmhost_delete_command)
|
103
|
+
|
104
|
+
# delete it locally
|
105
|
+
local_delete_command = "rm #{local_tempfile_path}"
|
106
|
+
system_command(local_delete_command)
|
107
|
+
else
|
108
|
+
# since we can't copy easily w/o tools, let's just run it directly :/
|
109
|
+
if @os == "linux"
|
110
|
+
scp_to(local_tempfile_path, remote_tempfile_path)
|
111
|
+
ssh_exec(remote_run_command)
|
112
|
+
ssh_exec("rm #{remote_tempfile_path}")
|
113
|
+
else
|
114
|
+
raise "Not Implemented - Install VmWare Tools"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def copy_from(from, to)
|
120
|
+
from = filter_input(from)
|
121
|
+
to = filter_input(to)
|
122
|
+
|
123
|
+
# copy it to the vm host - this is because we're a remote driver
|
124
|
+
remote_copy_command = "scp #{from} #{@user}@#{@host}:#{from}"
|
125
|
+
system_command(remote_copy_command)
|
126
|
+
|
127
|
+
if @tools
|
128
|
+
remote_system_command("ssh #{@user}@#{@host} \"vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
129
|
+
"copyFileFromGuestToHost \'#{@location}\' \'#{from}\' \'#{to}\' nogui")
|
130
|
+
else
|
131
|
+
scp_from(to,from)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def copy_to(from, to)
|
136
|
+
|
137
|
+
from = filter_input(from)
|
138
|
+
to = filter_input(to)
|
139
|
+
|
140
|
+
# copy it to the vm host - this is because we're a remote driver
|
141
|
+
remote_copy_command = "scp #{from} #{@user}@#{@host}:#{from}"
|
142
|
+
system_command(remote_copy_command)
|
143
|
+
|
144
|
+
if @tools
|
145
|
+
remote_system_command("vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
146
|
+
"copyFileFromHostToGuest \'#{@location}\' \'#{from}\' \'#{to}\' nogui")
|
147
|
+
else
|
148
|
+
scp_to(from,to)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def check_file_exists(file)
|
153
|
+
|
154
|
+
if @tools
|
155
|
+
file = filter_input(file)
|
156
|
+
remote_system_command("vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
157
|
+
"fileExistsInGuest \'#{@location}\' \'{file}\' nogui")
|
158
|
+
else
|
159
|
+
raise "Not Implemented - Install VmWare Tools"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def create_directory(directory)
|
164
|
+
directory = filter_input(directory)
|
165
|
+
|
166
|
+
if @tools
|
167
|
+
emote_system_command("ssh #{@user}@#{@host} vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
168
|
+
"createDirectoryInGuest \'#{@location}\' \'#{directory}\' nogui")
|
169
|
+
system_command(vmrunstr)
|
170
|
+
else
|
171
|
+
raise "Not Implemented - Install VmWare Tools"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def cleanup
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
def running?
|
180
|
+
## Get running VMs
|
181
|
+
running = `ssh #{@user}@#{@host} \"vmrun list nogui\"`
|
182
|
+
running_array = running.split("\n")
|
183
|
+
running_array.shift
|
184
|
+
|
185
|
+
running_array.each do |vmx|
|
186
|
+
if vmx.to_s == @location.to_s
|
187
|
+
return true
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
false
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'vm_driver'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
##
|
5
|
+
## $Id$
|
6
|
+
##
|
7
|
+
module Lab
|
8
|
+
module Drivers
|
9
|
+
class VirtualBoxDriver < VmDriver
|
10
|
+
|
11
|
+
attr_accessor :location
|
12
|
+
|
13
|
+
def initialize(config)
|
14
|
+
|
15
|
+
super(config)
|
16
|
+
|
17
|
+
## Check to see if we already know this vm, if not, go on location
|
18
|
+
vmid_list = ::Lab::Controllers::VirtualBoxController::config_list
|
19
|
+
unless vmid_list.include? @vmid
|
20
|
+
raise "Error, no such vm: #{@vmid}" unless @location
|
21
|
+
|
22
|
+
if !File.exist?(@location)
|
23
|
+
raise ArgumentError,"Error, no vm at: #{@location}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Registering @location
|
27
|
+
@vmid = register_and_return_vmid
|
28
|
+
end
|
29
|
+
|
30
|
+
vmInfo = `VBoxManage showvminfo \"#{@vmid}\" --machinereadable`
|
31
|
+
@location = vmInfo.scan(/CfgFile=\"(.*?)\"/).flatten[0].to_s
|
32
|
+
|
33
|
+
if !File.exist?(@location)
|
34
|
+
raise ArgumentError,"Couldn't find: " + @location
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def register_and_return_vmid
|
40
|
+
|
41
|
+
xml = Nokogiri::XML(File.new(@location))
|
42
|
+
vmid = xml.root.xpath("//Machine[@name]")
|
43
|
+
|
44
|
+
## only register if we don't already know the vmid
|
45
|
+
if !::Lab::Controllers::VirtualBoxController::config_list.include? vmid
|
46
|
+
system_command("VBoxManage registervm \"#{@location}\"")
|
47
|
+
end
|
48
|
+
|
49
|
+
return vmid
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def unregister
|
54
|
+
system_command("VBoxManage unregistervm \"#{@vmid}\"")
|
55
|
+
end
|
56
|
+
|
57
|
+
def start
|
58
|
+
system_command("VBoxManage startvm \"#{@vmid}\"")
|
59
|
+
end
|
60
|
+
|
61
|
+
def stop
|
62
|
+
system_command("VBoxManage controlvm \"#{@vmid}\" poweroff")
|
63
|
+
end
|
64
|
+
|
65
|
+
def suspend
|
66
|
+
system_command("VBoxManage controlvm \"#{@vmid}\" savestate")
|
67
|
+
end
|
68
|
+
|
69
|
+
def pause
|
70
|
+
system_command("VBoxManage controlvm \"#{@vmid}\" pause")
|
71
|
+
end
|
72
|
+
|
73
|
+
def reset
|
74
|
+
system_command("VBoxManage controlvm \"#{@vmid}\" reset")
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_snapshot(snapshot)
|
78
|
+
snapshot = filter_input(snapshot)
|
79
|
+
system_command("VBoxManage snapshot \"#{@vmid}\" take #{snapshot}")
|
80
|
+
end
|
81
|
+
|
82
|
+
def revert_snapshot(snapshot)
|
83
|
+
snapshot = filter_input(snapshot)
|
84
|
+
system_command("VBoxManage snapshot \"#{@vmid}\" restore #{snapshot}")
|
85
|
+
end
|
86
|
+
|
87
|
+
def delete_snapshot(snapshot)
|
88
|
+
snapshot = filter_input(snapshot)
|
89
|
+
system_command("VBoxManage snapshot \"#{@vmid}\" delete #{snapshot}")
|
90
|
+
end
|
91
|
+
|
92
|
+
def run_command(command, arguments=nil)
|
93
|
+
command = filter_input(command)
|
94
|
+
arguments = filter_input(arguments)
|
95
|
+
|
96
|
+
command = "VBoxManage guestcontrol exec \"#{@vmid}\" \"#{command}\" --username \"#{@vm_user}\"" +
|
97
|
+
" --password \"#{@vm_pass}\" --arguments \"#{arguments}\""
|
98
|
+
system_command(command)
|
99
|
+
end
|
100
|
+
|
101
|
+
def copy_from(from, to)
|
102
|
+
from = filter_input(from)
|
103
|
+
to = filter_input(to)
|
104
|
+
|
105
|
+
raise "Not supported by Virtual Box"
|
106
|
+
end
|
107
|
+
|
108
|
+
def copy_to(from, to)
|
109
|
+
from = filter_input(from)
|
110
|
+
to = filter_input(to)
|
111
|
+
|
112
|
+
command = "VBoxManage guestcontrol copyto \"#{@vmid}\" \"#{from}\" \"#{to}\" " +
|
113
|
+
"--username \"#{@vm_user}\" --password \"#{@vm_pass}\""
|
114
|
+
system_command(command)
|
115
|
+
end
|
116
|
+
|
117
|
+
def check_file_exists(file)
|
118
|
+
file = filter_input(file)
|
119
|
+
|
120
|
+
raise "Not supported by Virtual Box"
|
121
|
+
end
|
122
|
+
|
123
|
+
def create_directory(directory)
|
124
|
+
directory = filter_input(directory)
|
125
|
+
|
126
|
+
command = "VBoxManage guestcontrol createdir \"#{@vmid}\" \"#{directory}\" " +
|
127
|
+
"--username \"#{@vm_user}\" --password \"#{@vm_pass}\""
|
128
|
+
system_command(command)
|
129
|
+
end
|
130
|
+
|
131
|
+
def cleanup
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
def running?
|
136
|
+
## Get running Vms
|
137
|
+
::Lab::Controllers::VirtualBoxController::running_list.include? @vmid
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|