lab 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/.gitignore +4 -0
  2. data/config/test_lab.yml +11 -0
  3. data/config/test_targets.yml +21 -0
  4. data/lib/lab/controller/dynagen_controller.rb +6 -6
  5. data/lib/lab/controller/remote_esx_controller.rb +51 -51
  6. data/lib/lab/controller/remote_esxi_controller.rb +62 -0
  7. data/lib/lab/controller/remote_workstation_controller.rb +12 -12
  8. data/lib/lab/controller/virtualbox_controller.rb +16 -16
  9. data/lib/lab/controller/workstation_controller.rb +9 -9
  10. data/lib/lab/controller/workstation_vixr_controller.rb +9 -9
  11. data/lib/lab/controllers.rb +1 -3
  12. data/lib/lab/driver/dynagen_driver.rb +32 -32
  13. data/lib/lab/driver/fog_driver.rb +144 -144
  14. data/lib/lab/driver/remote_esxi_driver.rb +177 -0
  15. data/lib/lab/driver/remote_workstation_driver.rb +181 -181
  16. data/lib/lab/driver/virtualbox_driver.rb +132 -132
  17. data/lib/lab/driver/vm_driver.rb +177 -177
  18. data/lib/lab/driver/workstation_driver.rb +218 -218
  19. data/lib/lab/driver/workstation_vixr_driver.rb +108 -108
  20. data/lib/lab/drivers.rb +1 -1
  21. data/lib/lab/modifier/backtrack5_modifier.rb +8 -8
  22. data/lib/lab/modifier/dos_modifier.rb +3 -3
  23. data/lib/lab/modifier/test_modifier.rb +6 -6
  24. data/lib/lab/version.rb +1 -1
  25. data/lib/lab/vm.rb +242 -242
  26. data/lib/lab/vm_controller.rb +217 -211
  27. data/src/Gemfile +4 -0
  28. data/src/README.md +80 -0
  29. data/src/Rakefile +1 -0
  30. data/src/TODO +15 -0
  31. data/src/config/test_lab.yml +11 -0
  32. data/src/config/test_targets.yml +21 -0
  33. data/src/lab.gemspec +35 -0
  34. data/src/lib/lab.rb +2 -0
  35. data/src/lib/lab/controller/dynagen_controller.rb +14 -0
  36. data/src/lib/lab/controller/fog_controller.rb +6 -0
  37. data/src/lib/lab/controller/remote_esxi_controller.rb +62 -0
  38. data/src/lib/lab/controller/remote_workstation_controller.rb +22 -0
  39. data/src/lib/lab/controller/virtualbox_controller.rb +25 -0
  40. data/src/lib/lab/controller/vsphere_controller.rb +18 -0
  41. data/src/lib/lab/controller/workstation_controller.rb +17 -0
  42. data/src/lib/lab/controller/workstation_vixr_controller.rb +19 -0
  43. data/src/lib/lab/controllers.rb +9 -0
  44. data/src/lib/lab/driver/dynagen_driver.rb +47 -0
  45. data/src/lib/lab/driver/fog_driver.rb +104 -0
  46. data/src/lib/lab/driver/remote_esxi_driver.rb +177 -0
  47. data/src/lib/lab/driver/remote_workstation_driver.rb +197 -0
  48. data/src/lib/lab/driver/virtualbox_driver.rb +142 -0
  49. data/src/lib/lab/driver/vm_driver.rb +195 -0
  50. data/src/lib/lab/driver/vsphere_driver.rb +120 -0
  51. data/src/lib/lab/driver/workstation_driver.rb +234 -0
  52. data/src/lib/lab/driver/workstation_vixr_driver.rb +126 -0
  53. data/src/lib/lab/drivers.rb +9 -0
  54. data/src/lib/lab/modifier/backtrack5_modifier.rb +16 -0
  55. data/src/lib/lab/modifier/dos_modifier.rb +14 -0
  56. data/src/lib/lab/modifier/test_modifier.rb +16 -0
  57. data/src/lib/lab/modifiers.rb +3 -0
  58. data/src/lib/lab/version.rb +3 -0
  59. data/src/lib/lab/vm.rb +269 -0
  60. data/src/lib/lab/vm_controller.rb +275 -0
  61. data/src/test/.gitkeep +0 -0
  62. metadata +51 -12
  63. data/lib/lab/driver/remote_esx_driver.rb +0 -177
@@ -9,187 +9,187 @@ module Drivers
9
9
 
10
10
  class RemoteWorkstationDriver < VmDriver
11
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
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
193
 
194
194
  end
195
195
 
@@ -6,137 +6,137 @@ require 'nokogiri'
6
6
  ##
7
7
  module Lab
8
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
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
141
  end
142
142
  end