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.
- data/config/test_lab.yml +61 -0
- data/lab.gemspec +4 -1
- data/lib/lab/controller/vsphere_controller.rb +2 -46
- data/lib/lab/driver/vsphere_driver.rb +2 -2
- data/lib/lab/version.rb +1 -1
- data/lib/lab/vm_controller.rb +15 -4
- data/util/console.rb +10 -0
- metadata +21 -43
- data/src/Gemfile +0 -4
- data/src/Rakefile +0 -1
- data/src/TODO +0 -15
- data/src/config/test_lab.yml +0 -11
- data/src/config/test_targets.yml +0 -21
- data/src/lab.gemspec +0 -35
- data/src/lib/lab/controller/dynagen_controller.rb +0 -14
- data/src/lib/lab/controller/fog_controller.rb +0 -6
- data/src/lib/lab/controller/remote_esxi_controller.rb +0 -62
- data/src/lib/lab/controller/remote_workstation_controller.rb +0 -22
- data/src/lib/lab/controller/virtualbox_controller.rb +0 -25
- data/src/lib/lab/controller/vsphere_controller.rb +0 -18
- data/src/lib/lab/controller/workstation_controller.rb +0 -17
- data/src/lib/lab/controller/workstation_vixr_controller.rb +0 -19
- data/src/lib/lab/controllers.rb +0 -9
- data/src/lib/lab/driver/dynagen_driver.rb +0 -47
- data/src/lib/lab/driver/fog_driver.rb +0 -104
- data/src/lib/lab/driver/remote_esxi_driver.rb +0 -177
- data/src/lib/lab/driver/remote_workstation_driver.rb +0 -197
- data/src/lib/lab/driver/virtualbox_driver.rb +0 -142
- data/src/lib/lab/driver/vm_driver.rb +0 -195
- data/src/lib/lab/driver/vsphere_driver.rb +0 -120
- data/src/lib/lab/driver/workstation_driver.rb +0 -234
- data/src/lib/lab/driver/workstation_vixr_driver.rb +0 -126
- data/src/lib/lab/drivers.rb +0 -9
- data/src/lib/lab/modifier/backtrack5_modifier.rb +0 -16
- data/src/lib/lab/modifier/dos_modifier.rb +0 -14
- data/src/lib/lab/modifier/test_modifier.rb +0 -16
- data/src/lib/lab/modifiers.rb +0 -3
- data/src/lib/lab/version.rb +0 -3
- data/src/lib/lab/vm.rb +0 -269
- data/src/lib/lab/vm_controller.rb +0 -275
- data/src/lib/lab.rb +0 -2
- data/src/test/.gitkeep +0 -0
@@ -1,16 +0,0 @@
|
|
1
|
-
# This assumes you're on a recent ubuntu
|
2
|
-
# TODO - enforce this, or split it out...
|
3
|
-
|
4
|
-
module Lab
|
5
|
-
module Modifier
|
6
|
-
module Test
|
7
|
-
def install_nmap
|
8
|
-
run_command("sudo apt-get install nmap")
|
9
|
-
end
|
10
|
-
|
11
|
-
def nmap(options)
|
12
|
-
run_command("nmap #{filter_input(options)}")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
data/src/lib/lab/modifiers.rb
DELETED
data/src/lib/lab/version.rb
DELETED
data/src/lib/lab/vm.rb
DELETED
@@ -1,269 +0,0 @@
|
|
1
|
-
#
|
2
|
-
module Lab
|
3
|
-
|
4
|
-
#
|
5
|
-
# This class encapsulates a vm, provides functionality on that vm, and contains a single driver.
|
6
|
-
#
|
7
|
-
class Vm
|
8
|
-
|
9
|
-
attr_accessor :vmid
|
10
|
-
attr_accessor :hostname
|
11
|
-
attr_accessor :description
|
12
|
-
attr_accessor :user
|
13
|
-
attr_accessor :host
|
14
|
-
attr_accessor :location
|
15
|
-
attr_accessor :driver
|
16
|
-
attr_accessor :credentials
|
17
|
-
attr_accessor :tools
|
18
|
-
attr_accessor :type
|
19
|
-
attr_accessor :os
|
20
|
-
attr_accessor :arch
|
21
|
-
attr_accessor :tags
|
22
|
-
|
23
|
-
## Initialize takes a vm configuration hash of the form
|
24
|
-
## - vmid (unique id)
|
25
|
-
## hostname (unique name)
|
26
|
-
## description (describes the vm's contents)
|
27
|
-
## driver (vm driver)
|
28
|
-
## location (if applicable - local system)
|
29
|
-
## user (if applicable - remote system)
|
30
|
-
## host (if applicable - remote system)
|
31
|
-
## pass (if applicable - remote system) # DISCOURAGED - USE KEYS!
|
32
|
-
## tools (true if tools are installed)
|
33
|
-
## type ( qa / vulnerable / etc - freeform option)
|
34
|
-
## credentials (of the form [ {'user'=>"user",'pass'=>"pass", 'admin' => false}, ... ])
|
35
|
-
## os (currently linux / windows / solaris / aix) - may be used in modifiers
|
36
|
-
## arch (currently 32 / 64)
|
37
|
-
## modifiers - array of strings, can be anything in the modifiers directory
|
38
|
-
## tags - array of strings associated with this vm
|
39
|
-
|
40
|
-
def initialize(config = {})
|
41
|
-
|
42
|
-
# TODO - This is a mess. clean up, and pass stuff down to drivers
|
43
|
-
# and then rework the code that uses this api.
|
44
|
-
@vmid = config['vmid'].to_s
|
45
|
-
raise "Invalid VMID" unless @vmid
|
46
|
-
|
47
|
-
# Grab the hostname if specified, otherwise use the vmid
|
48
|
-
# VMID will be different in the case of ESX
|
49
|
-
@hostname = config['hostname']
|
50
|
-
if !@hostname
|
51
|
-
@hostname = @vmid
|
52
|
-
end
|
53
|
-
|
54
|
-
@driver_type = filter_input(config['driver'])
|
55
|
-
@driver_type.downcase!
|
56
|
-
|
57
|
-
@location = filter_input(config['location'])
|
58
|
-
@description = config['description']
|
59
|
-
@tools = config['tools']
|
60
|
-
@os = config['os']
|
61
|
-
@arch = config['arch']
|
62
|
-
@type = filter_input(config['type']) || "unspecified"
|
63
|
-
@credentials = config['credentials'] || []
|
64
|
-
|
65
|
-
# TODO - Currently only implemented for the first set
|
66
|
-
if @credentials.count > 0
|
67
|
-
@vm_user = filter_input(@credentials[0]['user']) || "\'\'"
|
68
|
-
@vm_pass = filter_input(@credentials[0]['pass']) || "\'\'"
|
69
|
-
@vm_keyfile = filter_input(@credentials[0]['keyfile'])
|
70
|
-
end
|
71
|
-
|
72
|
-
# Only applicable to remote systems
|
73
|
-
@user = filter_input(config['user']) || nil
|
74
|
-
@host = filter_input(config['host']) || nil
|
75
|
-
@port = filter_input(config['port']) || nil
|
76
|
-
@pass = filter_input(config['pass']) || nil # DISCORAGED, use keys!
|
77
|
-
|
78
|
-
# Only dynagen systems need this
|
79
|
-
@platform = config['platform']
|
80
|
-
|
81
|
-
# Only fog systems need this
|
82
|
-
@fog_config = config['fog_config']
|
83
|
-
|
84
|
-
# Process the correct driver
|
85
|
-
if @driver_type == "workstation"
|
86
|
-
@driver = Lab::Drivers::WorkstationDriver.new(config)
|
87
|
-
elsif @driver_type == "remote_workstation"
|
88
|
-
@driver = Lab::Drivers::RemoteWorkstationDriver.new(config)
|
89
|
-
elsif @driver_type == "virtualbox"
|
90
|
-
@driver = Lab::Drivers::VirtualBoxDriver.new(config)
|
91
|
-
elsif @driver_type == "fog"
|
92
|
-
@driver = Lab::Drivers::FogDriver.new(config, config['fog_config'])
|
93
|
-
elsif @driver_type == "dynagen"
|
94
|
-
@driver = Lab::Drivers::DynagenDriver.new(config, config['dynagen_config'])
|
95
|
-
elsif @driver_type == "remote_esxi"
|
96
|
-
@driver = Lab::Drivers::RemoteEsxiDriver.new(config)
|
97
|
-
elsif @driver_type == "vsphere"
|
98
|
-
@driver = Lab::Drivers::VsphereDriver.new(config)
|
99
|
-
#elsif @driver_type == "qemu"
|
100
|
-
# @driver = Lab::Drivers::QemuDriver.new
|
101
|
-
#elsif @driver_type == "qemudo"
|
102
|
-
# @driver = Lab::Drivers::QemudoDriver.new
|
103
|
-
else
|
104
|
-
raise "Unknown Driver Type"
|
105
|
-
end
|
106
|
-
|
107
|
-
# Load in a list of modifiers. These provide additional methods
|
108
|
-
# Currently it is up to the user to verify that
|
109
|
-
# modifiers are properly used with the correct VM image.
|
110
|
-
#
|
111
|
-
# If not, the results are likely to be disasterous.
|
112
|
-
@modifiers = config['modifiers']
|
113
|
-
|
114
|
-
if @modifiers
|
115
|
-
begin
|
116
|
-
@modifiers.each { |modifier| self.class.send(:include, eval("Lab::Modifier::#{modifier}"))}
|
117
|
-
rescue Exception => e
|
118
|
-
# modifier likely didn't exist
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
#
|
123
|
-
# Grab a tags array
|
124
|
-
#
|
125
|
-
@tags = config['tags']
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
def running?
|
130
|
-
@driver.running?
|
131
|
-
end
|
132
|
-
|
133
|
-
def location
|
134
|
-
@driver.location
|
135
|
-
end
|
136
|
-
|
137
|
-
def start
|
138
|
-
@driver.start
|
139
|
-
end
|
140
|
-
|
141
|
-
def stop
|
142
|
-
@driver.stop
|
143
|
-
end
|
144
|
-
|
145
|
-
def pause
|
146
|
-
@driver.pause
|
147
|
-
end
|
148
|
-
|
149
|
-
def suspend
|
150
|
-
@driver.suspend
|
151
|
-
end
|
152
|
-
|
153
|
-
def reset
|
154
|
-
@driver.reset
|
155
|
-
end
|
156
|
-
|
157
|
-
def resume
|
158
|
-
@driver.resume
|
159
|
-
end
|
160
|
-
|
161
|
-
def create_snapshot(snapshot)
|
162
|
-
@driver.create_snapshot(snapshot)
|
163
|
-
end
|
164
|
-
|
165
|
-
def revert_snapshot(snapshot)
|
166
|
-
@driver.revert_snapshot(snapshot)
|
167
|
-
end
|
168
|
-
|
169
|
-
def delete_snapshot(snapshot)
|
170
|
-
@driver.delete_snapshot(snapshot)
|
171
|
-
end
|
172
|
-
|
173
|
-
def revert_and_start(snapshot)
|
174
|
-
@driver.revert_snapshot(snapshot)
|
175
|
-
@driver.start
|
176
|
-
end
|
177
|
-
|
178
|
-
def copy_to(from,to)
|
179
|
-
@driver.copy_to(from,to)
|
180
|
-
end
|
181
|
-
|
182
|
-
def copy_from(from,to)
|
183
|
-
@driver.copy_from(from,to)
|
184
|
-
end
|
185
|
-
|
186
|
-
def run_command(command)
|
187
|
-
@driver.run_command(command)
|
188
|
-
end
|
189
|
-
|
190
|
-
def check_file_exists(file)
|
191
|
-
@driver.check_file_exists(file)
|
192
|
-
end
|
193
|
-
|
194
|
-
def create_directory(directory)
|
195
|
-
@driver.create_directory(directory)
|
196
|
-
end
|
197
|
-
|
198
|
-
def open_uri(uri)
|
199
|
-
# we don't filter the uri, as it's getting tossed into a script
|
200
|
-
# by the driver
|
201
|
-
if @os == "windows"
|
202
|
-
command = "\"C:\\program files\\internet explorer\\iexplore.exe\" #{uri}"
|
203
|
-
else
|
204
|
-
command = "firefox #{uri}"
|
205
|
-
end
|
206
|
-
|
207
|
-
@driver.run_command(command)
|
208
|
-
end
|
209
|
-
|
210
|
-
def to_s
|
211
|
-
return "#{@hostname}"
|
212
|
-
end
|
213
|
-
|
214
|
-
def to_yaml
|
215
|
-
|
216
|
-
# TODO - push this down to the drivers.
|
217
|
-
|
218
|
-
# Standard configuration options
|
219
|
-
out = " - vmid: #{@vmid}\n"
|
220
|
-
out += " hostname: #{@hostname}\n"
|
221
|
-
out += " driver: #{@driver_type}\n"
|
222
|
-
out += " description: |\n #{@description}\n"
|
223
|
-
out += " location: #{@location}\n"
|
224
|
-
out += " type: #{@type}\n"
|
225
|
-
out += " tools: #{@tools}\n"
|
226
|
-
out += " os: #{@os}\n"
|
227
|
-
out += " arch: #{@arch}\n"
|
228
|
-
|
229
|
-
if @user or @host # Remote vm/drivers only
|
230
|
-
out += " user: #{@user}\n"
|
231
|
-
out += " host: #{@host}\n"
|
232
|
-
out += " port: #{@port}\n"
|
233
|
-
out += " pass: #{@pass}\n"
|
234
|
-
end
|
235
|
-
|
236
|
-
if @platform
|
237
|
-
out += " platform: #{@platform}\n"
|
238
|
-
end
|
239
|
-
|
240
|
-
if @fog_config
|
241
|
-
out += @fog_config.to_yaml
|
242
|
-
end
|
243
|
-
|
244
|
-
if @dynagen_config
|
245
|
-
out += @dynagen_config.to_yaml
|
246
|
-
end
|
247
|
-
|
248
|
-
out += " credentials:\n"
|
249
|
-
@credentials.each do |credential|
|
250
|
-
out += " - user: #{credential['user']}\n"
|
251
|
-
out += " pass: #{credential['pass']}\n"
|
252
|
-
end
|
253
|
-
|
254
|
-
return out
|
255
|
-
end
|
256
|
-
private
|
257
|
-
|
258
|
-
def filter_input(string)
|
259
|
-
return "" unless string # nil becomes empty string
|
260
|
-
return unless string.class == String # Allow other types
|
261
|
-
|
262
|
-
unless /^[(!)\d*\w*\s*\[\]\{\}\/\\\.\-\"\(\)]*$/.match string
|
263
|
-
raise "WARNING! Invalid character in: #{string}"
|
264
|
-
end
|
265
|
-
|
266
|
-
string
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|
@@ -1,275 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# $Id$
|
3
|
-
#
|
4
|
-
# This is the main lab controller. Require this controller to get all
|
5
|
-
# lab functionality.
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
$:.unshift(File.expand_path(File.dirname(__FILE__)))
|
10
|
-
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'driver')))
|
11
|
-
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'controller')))
|
12
|
-
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'modifier')))
|
13
|
-
|
14
|
-
require 'find'
|
15
|
-
require 'yaml'
|
16
|
-
require 'enumerator'
|
17
|
-
require 'fileutils'
|
18
|
-
|
19
|
-
require 'vm'
|
20
|
-
require 'controllers'
|
21
|
-
require 'drivers'
|
22
|
-
require 'modifiers'
|
23
|
-
|
24
|
-
require 'net/scp'
|
25
|
-
require 'net/ssh'
|
26
|
-
|
27
|
-
module Lab
|
28
|
-
module Controllers
|
29
|
-
class VmController
|
30
|
-
|
31
|
-
include Enumerable
|
32
|
-
include Lab::Controllers::WorkstationController
|
33
|
-
include Lab::Controllers::RemoteWorkstationController
|
34
|
-
include Lab::Controllers::VirtualBoxController
|
35
|
-
include Lab::Controllers::FogController
|
36
|
-
include Lab::Controllers::DynagenController
|
37
|
-
include Lab::Controllers::RemoteEsxiController
|
38
|
-
include Lab::Controllers::VsphereController
|
39
|
-
#include Lab::Controllers::QemuController
|
40
|
-
#include Lab::Controllers::QemudoController
|
41
|
-
def initialize (labdef=nil)
|
42
|
-
|
43
|
-
# Start with an empty array of vm objects
|
44
|
-
@vms = []
|
45
|
-
|
46
|
-
# labdef is a just a big array of hashes
|
47
|
-
load_vms(labdef) if labdef
|
48
|
-
end
|
49
|
-
|
50
|
-
def clear!
|
51
|
-
@vms = []
|
52
|
-
end
|
53
|
-
|
54
|
-
def [](x)
|
55
|
-
# Support indexing by both names and number
|
56
|
-
if x.class == String
|
57
|
-
find_by_vmid(x)
|
58
|
-
else
|
59
|
-
return @vms[x]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def find_by_vmid(search)
|
64
|
-
@vms.each do |vm|
|
65
|
-
return vm if vm.hostname.to_s.downcase == search.to_s.downcase
|
66
|
-
end
|
67
|
-
return nil
|
68
|
-
end
|
69
|
-
|
70
|
-
def find_by_tag(search)
|
71
|
-
@vms.each do |vm|
|
72
|
-
vm.tags.each do |tag|
|
73
|
-
return vm if tag.downcase == search.to_s.downcase
|
74
|
-
end
|
75
|
-
end
|
76
|
-
return nil
|
77
|
-
end
|
78
|
-
|
79
|
-
def add_vm(vmid, location=nil, os=nil, tools=nil, credentials=nil, user=nil, host=nil)
|
80
|
-
@vms << Vm.new( {
|
81
|
-
'vmid' => vmid,
|
82
|
-
'driver' => type,
|
83
|
-
'location' => location,
|
84
|
-
'credentials' => credentials,
|
85
|
-
'user' => user,
|
86
|
-
'host' => host
|
87
|
-
})
|
88
|
-
end
|
89
|
-
|
90
|
-
def remove_by_vmid(vmid)
|
91
|
-
@vms.delete(self.find_by_vmid(vmid))
|
92
|
-
end
|
93
|
-
|
94
|
-
def from_file(file)
|
95
|
-
load_vms(YAML::load_file(file))
|
96
|
-
end
|
97
|
-
|
98
|
-
def load_vms(vms)
|
99
|
-
vms.each do |item|
|
100
|
-
vm = Vm.new(item)
|
101
|
-
@vms << vm unless includes_vmid? vm.vmid
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def to_file(file)
|
106
|
-
File.open(file, 'w') { |f| @vms.each { |vm| f.puts vm.to_yaml } }
|
107
|
-
end
|
108
|
-
|
109
|
-
def each &block
|
110
|
-
@vms.each { |vm| yield vm }
|
111
|
-
end
|
112
|
-
|
113
|
-
def includes?(specified_vm)
|
114
|
-
@vms.each { |vm| if (vm == specified_vm) then return true end }
|
115
|
-
end
|
116
|
-
|
117
|
-
def includes_vmid?(vmid)
|
118
|
-
@vms.each do |vm|
|
119
|
-
return true if (vm.vmid == vmid)
|
120
|
-
end
|
121
|
-
false
|
122
|
-
end
|
123
|
-
|
124
|
-
#
|
125
|
-
# Build a vm lab from a directory of files. Really only useful for file-based
|
126
|
-
# vm hosts. (vmware workstation)
|
127
|
-
#
|
128
|
-
def build_from_dir(driver_type, dir, clear=false)
|
129
|
-
|
130
|
-
if clear
|
131
|
-
@vms = []
|
132
|
-
end
|
133
|
-
|
134
|
-
if driver_type.downcase == "workstation"
|
135
|
-
vm_list = ::Lab::Controllers::WorkstationController::dir_list(dir)
|
136
|
-
elsif driver_type.downcase == "remote_workstation"
|
137
|
-
vm_list = ::Lab::Controllers::RemoteWorkstationController::dir_list(dir)
|
138
|
-
elsif driver_type.downcase == "virtualbox"
|
139
|
-
vm_list = ::Lab::Controllers::VirtualBoxController::dir_list(dir)
|
140
|
-
elsif driver_type.downcase == "fog"
|
141
|
-
vm_list = ::Lab::Controllers::FogController::dir_list(dir)
|
142
|
-
elsif driver_type.downcase == "Dynagen"
|
143
|
-
vm_list = ::Lab::Controllers::DynagenController::dir_list(dir)
|
144
|
-
elsif driver_type.downcase == "remote_esxi"
|
145
|
-
vm_list =::Lab::Controllers::RemoteEsxiController::dir_list(dir)
|
146
|
-
elsif driver_type.downcase == "vsphere"
|
147
|
-
vm_list =::Lab::Controllers::VsphereController::dir_list(dir)
|
148
|
-
else
|
149
|
-
raise TypeError, "Unsupported VM Type"
|
150
|
-
end
|
151
|
-
|
152
|
-
vm_list.each_index do |index|
|
153
|
-
@vms << Vm.new( {'vmid' => "vm_#{index}", 'driver' => driver_type, 'location' => vm_list[index]} )
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
|
158
|
-
#
|
159
|
-
# Builds a vm lab from all running vms. Handy for connecting and saving out
|
160
|
-
# a config or just managing the currently running vms
|
161
|
-
#
|
162
|
-
def build_from_running(driver_type=nil, user=nil, host=nil, clear=false, pass=nil)
|
163
|
-
|
164
|
-
if clear
|
165
|
-
@vms = []
|
166
|
-
end
|
167
|
-
|
168
|
-
case driver_type.intern
|
169
|
-
when :workstation
|
170
|
-
vm_list = ::Lab::Controllers::WorkstationController::running_list
|
171
|
-
vm_list.each do |item|
|
172
|
-
# Name the VM
|
173
|
-
index = @vms.count + 1
|
174
|
-
# Add it to the vm list
|
175
|
-
@vms << Vm.new({
|
176
|
-
'vmid' => "vm_#{index}",
|
177
|
-
'driver' => driver_type,
|
178
|
-
'location' => item
|
179
|
-
})
|
180
|
-
end
|
181
|
-
when :remote_workstation
|
182
|
-
vm_list = ::Lab::Controllers::RemoteWorkstationController::running_list(user, host)
|
183
|
-
vm_list.each do |item|
|
184
|
-
# Name the VM
|
185
|
-
index = @vms.count + 1
|
186
|
-
# Add it to the VM list
|
187
|
-
@vms << Vm.new({
|
188
|
-
'vmid' => "vm_#{index}",
|
189
|
-
'driver' => driver_type,
|
190
|
-
'location' => item,
|
191
|
-
'user' => user,
|
192
|
-
'host' => host
|
193
|
-
})
|
194
|
-
end
|
195
|
-
when :virtualbox
|
196
|
-
vm_list = ::Lab::Controllers::VirtualBoxController::running_list
|
197
|
-
vm_list.each do |item|
|
198
|
-
# Add it to the vm list
|
199
|
-
@vms << Vm.new( {
|
200
|
-
'vmid' => "#{item}",
|
201
|
-
'driver' => driver_type,
|
202
|
-
'location' => nil
|
203
|
-
})
|
204
|
-
end
|
205
|
-
when :fog
|
206
|
-
raise "Unsupported"
|
207
|
-
when :dynagen
|
208
|
-
raise "Unsupported"
|
209
|
-
when :remote_esxi
|
210
|
-
vm_list = ::Lab::Controllers::RemoteEsxiController::running_list(user,host)
|
211
|
-
vm_list.each do |item|
|
212
|
-
@vms << Vm.new( {
|
213
|
-
'vmid' => "#{item[:id]}",
|
214
|
-
'name' => "#{item[:name]}",
|
215
|
-
'driver' => driver_type,
|
216
|
-
'user' => user,
|
217
|
-
'host' => host
|
218
|
-
})
|
219
|
-
end
|
220
|
-
when :vsphere
|
221
|
-
vm_list = ::Lab::Controllers::VsphereController::running_list(user,host,pass)
|
222
|
-
vm_list.each do |item|
|
223
|
-
@vms << Vm.new( {
|
224
|
-
'vmid' => "#{item[:id]}",
|
225
|
-
'name' => "#{item[:name]}",
|
226
|
-
'driver' => driver_type,
|
227
|
-
'user' => user,
|
228
|
-
'host' => host,
|
229
|
-
'pass' => pass
|
230
|
-
})
|
231
|
-
end
|
232
|
-
else
|
233
|
-
raise TypeError, "Unsupported VM Type"
|
234
|
-
end
|
235
|
-
|
236
|
-
end
|
237
|
-
|
238
|
-
#
|
239
|
-
# Applicable only to virtualbox. Reads the config file & parses / creates
|
240
|
-
# VM objects for each vm.
|
241
|
-
#
|
242
|
-
def build_from_config(driver_type=nil, user=nil, host=nil, clear=false)
|
243
|
-
if clear
|
244
|
-
@vms = []
|
245
|
-
end
|
246
|
-
|
247
|
-
case driver_type.intern
|
248
|
-
when :virtualbox
|
249
|
-
vm_list = ::Lab::Controllers::VirtualBoxController::config_list
|
250
|
-
|
251
|
-
vm_list.each do |item|
|
252
|
-
# Add it to the vm list
|
253
|
-
@vms << Vm.new( {
|
254
|
-
'vmid' => "#{item}",
|
255
|
-
'driver' => driver_type,
|
256
|
-
'location' => nil,
|
257
|
-
'user' => user,
|
258
|
-
'host' => host } )
|
259
|
-
end
|
260
|
-
|
261
|
-
else
|
262
|
-
raise TypeError, "Unsupported VM Type"
|
263
|
-
end
|
264
|
-
|
265
|
-
end
|
266
|
-
|
267
|
-
def running?(vmid)
|
268
|
-
if includes_vmid?(vmid)
|
269
|
-
return self.find_by_vmid(vmid).running?
|
270
|
-
end
|
271
|
-
return false
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
end
|
data/src/lib/lab.rb
DELETED
data/src/test/.gitkeep
DELETED
File without changes
|