lab 0.2.2 → 0.2.3

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 (42) hide show
  1. data/config/test_lab.yml +61 -0
  2. data/lab.gemspec +4 -1
  3. data/lib/lab/controller/vsphere_controller.rb +2 -46
  4. data/lib/lab/driver/vsphere_driver.rb +2 -2
  5. data/lib/lab/version.rb +1 -1
  6. data/lib/lab/vm_controller.rb +15 -4
  7. data/util/console.rb +10 -0
  8. metadata +21 -43
  9. data/src/Gemfile +0 -4
  10. data/src/Rakefile +0 -1
  11. data/src/TODO +0 -15
  12. data/src/config/test_lab.yml +0 -11
  13. data/src/config/test_targets.yml +0 -21
  14. data/src/lab.gemspec +0 -35
  15. data/src/lib/lab/controller/dynagen_controller.rb +0 -14
  16. data/src/lib/lab/controller/fog_controller.rb +0 -6
  17. data/src/lib/lab/controller/remote_esxi_controller.rb +0 -62
  18. data/src/lib/lab/controller/remote_workstation_controller.rb +0 -22
  19. data/src/lib/lab/controller/virtualbox_controller.rb +0 -25
  20. data/src/lib/lab/controller/vsphere_controller.rb +0 -18
  21. data/src/lib/lab/controller/workstation_controller.rb +0 -17
  22. data/src/lib/lab/controller/workstation_vixr_controller.rb +0 -19
  23. data/src/lib/lab/controllers.rb +0 -9
  24. data/src/lib/lab/driver/dynagen_driver.rb +0 -47
  25. data/src/lib/lab/driver/fog_driver.rb +0 -104
  26. data/src/lib/lab/driver/remote_esxi_driver.rb +0 -177
  27. data/src/lib/lab/driver/remote_workstation_driver.rb +0 -197
  28. data/src/lib/lab/driver/virtualbox_driver.rb +0 -142
  29. data/src/lib/lab/driver/vm_driver.rb +0 -195
  30. data/src/lib/lab/driver/vsphere_driver.rb +0 -120
  31. data/src/lib/lab/driver/workstation_driver.rb +0 -234
  32. data/src/lib/lab/driver/workstation_vixr_driver.rb +0 -126
  33. data/src/lib/lab/drivers.rb +0 -9
  34. data/src/lib/lab/modifier/backtrack5_modifier.rb +0 -16
  35. data/src/lib/lab/modifier/dos_modifier.rb +0 -14
  36. data/src/lib/lab/modifier/test_modifier.rb +0 -16
  37. data/src/lib/lab/modifiers.rb +0 -3
  38. data/src/lib/lab/version.rb +0 -3
  39. data/src/lib/lab/vm.rb +0 -269
  40. data/src/lib/lab/vm_controller.rb +0 -275
  41. data/src/lib/lab.rb +0 -2
  42. data/src/test/.gitkeep +0 -0
@@ -1,104 +0,0 @@
1
- require 'vm_driver'
2
-
3
- ##
4
- ## $Id$
5
- ##
6
-
7
- module Lab
8
- module Drivers
9
- class FogDriver < VmDriver
10
-
11
- def initialize(config,fog_config)
12
-
13
- super(config)
14
- @fog_config = fog_config
15
-
16
- # Soft dependency
17
- begin
18
- require 'fog'
19
- rescue LoadError
20
- raise "WARNING: Library fog not found. Could not create driver"
21
- end
22
-
23
- if @fog_config['fog_type'] == "ec2"
24
-
25
- # AWS / EC2 Base Credential Configuration
26
- @aws_cert_file = IO.read(fog_config['fog_aws_cert_file']).chomp if fog_config['fog_aws_cert_file']
27
- @aws_private_key_file = IO.read(fog_config['fog_aws_private_key_file']).chomp if fog_config['fog_aws_private_key_file']
28
- @ec2_access_key_file = IO.read(fog_config['fog_ec2_access_key_file']).chomp if fog_config['fog_ec2_access_key_file']
29
- @ec2_secret_access_key_file = IO.read(fog_config['fog_ec2_secret_access_key_file']).chomp if fog_config['fog_ec2_secret_access_key_file']
30
-
31
- # Instance Keys
32
- @ec2_instance_public_key_file = IO.read(fog_config['fog_ec2_instance_public_key_file']).chomp if fog_config['fog_ec2_instance_public_key_file']
33
- @ec2_instance_private_key_file = IO.read(fog_config['fog_ec2_instance_private_key_file']).chomp if fog_config['fog_ec2_instance_private_key_file']
34
-
35
- # Instance Details
36
- @ec2_base_ami = fog_config['fog_ec2_base_ami']
37
- @ec2_flavor = fog_config['fog_ec2_flavor']
38
- @ec2_user = fog_config['fog_ec2_user']
39
- @ec2_region = fog_config['fog_ec2_region']
40
-
41
- # Set up a connection
42
- @compute = Fog::Compute.new(
43
- :provider => "Aws",
44
- :aws_access_key_id => @aws_access_key_file,
45
- :aws_secret_access_key => @aws_secret_access_key_file )
46
- else
47
- raise "Unsupported fog type"
48
- end
49
- end
50
-
51
- def start
52
- ec2_settings = {
53
- :image_id => @ec2_base_ami,
54
- :flavor_id => @ec2_flavor,
55
- :public_key_path => @ec2_instance_public_key_file,
56
- :private_key_path => @ec2_instance_private_key_file,
57
- :username => @ec2_user}
58
- begin
59
- @fog_server = @compute.servers.bootstrap(ec2_settings)
60
- rescue Fog::Compute::AWS::Error => e
61
- raise "Couldn't authenticate to AWS - did you place keys in the creds/ directory?"
62
- exit
63
- end
64
- end
65
-
66
- def stop
67
- @fog_server.destroy
68
- end
69
-
70
- def suspend
71
- raise "unimplemented"
72
- end
73
-
74
- def pause
75
- raise "unimplemented"
76
- end
77
-
78
- def reset
79
- raise "unimplemented"
80
- end
81
-
82
- def create_snapshot(snapshot)
83
- raise "unimplemented"
84
- end
85
-
86
- def revert_snapshot(snapshot)
87
- raise "unimplemented"
88
- end
89
-
90
- def delete_snapshot(snapshot)
91
- raise "unimplemented"
92
- end
93
-
94
- def cleanup
95
- @fog_server.destroy
96
- end
97
-
98
- def running?
99
- return true #TODO
100
- end
101
-
102
- end
103
- end
104
- end
@@ -1,177 +0,0 @@
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
@@ -1,197 +0,0 @@
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
@@ -1,142 +0,0 @@
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