2010-12-28 19:47:33 +00:00
|
|
|
##
|
|
|
|
## $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'workstation_driver'
|
2011-05-24 15:56:32 +00:00
|
|
|
require 'workstation_vixr_driver'
|
2011-01-17 05:58:16 +00:00
|
|
|
require 'remote_workstation_driver'
|
2011-02-16 02:15:24 +00:00
|
|
|
require 'virtualbox_driver'
|
2011-05-24 15:56:32 +00:00
|
|
|
require 'dynagen_driver'
|
2011-05-31 15:51:22 +00:00
|
|
|
#require 'fog_amazon_driver'
|
2011-02-08 07:26:18 +00:00
|
|
|
#require 'amazon_driver'
|
2011-05-24 15:56:32 +00:00
|
|
|
#require 'qemu_driver'
|
|
|
|
#require 'qemudo_driver'
|
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
module Lab
|
2010-12-28 19:47:33 +00:00
|
|
|
class Vm
|
|
|
|
|
|
|
|
attr_accessor :vmid
|
2011-05-24 15:56:32 +00:00
|
|
|
attr_accessor :location
|
2010-12-28 19:47:33 +00:00
|
|
|
attr_accessor :driver
|
|
|
|
attr_accessor :credentials
|
|
|
|
attr_accessor :tools
|
2011-02-10 10:56:36 +00:00
|
|
|
attr_accessor :type
|
2011-05-24 15:56:32 +00:00
|
|
|
attr_accessor :user
|
|
|
|
attr_accessor :host
|
|
|
|
attr_accessor :os
|
|
|
|
attr_accessor :arch
|
2010-12-28 19:47:33 +00:00
|
|
|
|
|
|
|
## Initialize takes a vm configuration hash of the form
|
|
|
|
## - vmid (unique identifier)
|
2011-01-17 05:58:16 +00:00
|
|
|
## driver (vm technology)
|
2011-05-24 15:56:32 +00:00
|
|
|
## user (if applicable - remote system)
|
|
|
|
## host (if applicable - remote system)
|
2011-01-17 05:58:16 +00:00
|
|
|
## location (file / uri)
|
|
|
|
## credentials (of the form [ {'user'=>"user",'pass'=>"pass", 'admin' => false}, ... ])
|
2011-05-24 15:56:32 +00:00
|
|
|
## os (currently only linux / windows)
|
|
|
|
## arch (currently only 32 / 64
|
2010-12-28 19:47:33 +00:00
|
|
|
def initialize(config = {})
|
2011-02-16 02:15:24 +00:00
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
# Mandatory
|
2011-02-16 02:15:24 +00:00
|
|
|
@vmid = config['vmid']
|
2011-05-24 15:56:32 +00:00
|
|
|
raise "Invalid VMID" unless @vmid
|
2011-02-16 02:15:24 +00:00
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
@driver = nil
|
2011-05-31 15:51:22 +00:00
|
|
|
@driver_type = filter_input(config['driver'])
|
|
|
|
@driver_type.downcase!
|
2011-05-24 15:56:32 +00:00
|
|
|
|
|
|
|
@type = filter_input(config['type']) || "unspecified"
|
|
|
|
@tools = config['tools'] || false # don't filter this, not used in cmdlines
|
|
|
|
@os = config['os'] || nil
|
|
|
|
@arch = config['arch'] || nil
|
2011-02-08 07:26:18 +00:00
|
|
|
@credentials = config['credentials'] || []
|
2010-12-28 19:47:33 +00:00
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
# Optional for virtualbox
|
|
|
|
@location = filter_input(config['location'])
|
|
|
|
|
|
|
|
# Only applicable to remote systems
|
2011-05-31 15:51:22 +00:00
|
|
|
@user = filter_input(config['user']) || nil
|
|
|
|
@host = filter_input(config['host']) || nil
|
2011-01-17 05:58:16 +00:00
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
#Only dynagen
|
|
|
|
@platform = config['platform']
|
|
|
|
|
2011-05-31 15:51:22 +00:00
|
|
|
#puts "DEBUG: " + driver_type + " driver requested."
|
|
|
|
|
|
|
|
if @driver_type == "workstation"
|
2011-06-04 05:57:09 +00:00
|
|
|
@driver = Lab::Drivers::WorkstationDriver.new(@vmid, @location, @os, @tools, @credentials)
|
2011-05-31 15:51:22 +00:00
|
|
|
elsif @driver_type == "workstation_vixr"
|
2011-06-04 05:57:09 +00:00
|
|
|
@driver = Lab::Drivers::WorkstationVixrDriver.new(@vmid, @location, @os, @tools, @user, @host, @credentials)
|
2011-05-31 15:51:22 +00:00
|
|
|
elsif @driver_type == "remote_workstation"
|
2011-05-24 15:56:32 +00:00
|
|
|
@driver = Lab::Drivers::RemoteWorkstationDriver.new(@vmid, @location, @os, @tools, @user, @host, @credentials)
|
2011-05-31 15:51:22 +00:00
|
|
|
elsif @driver_type == "virtualbox"
|
2011-05-24 15:56:32 +00:00
|
|
|
@driver = Lab::Drivers::VirtualBoxDriver.new(@vmid, @location, @credentials)
|
2011-05-31 15:51:22 +00:00
|
|
|
elsif @driver_type == "dynagen"
|
2011-05-24 15:56:32 +00:00
|
|
|
@driver = Lab::Drivers::DynagenDriver.new(@vmid, @location,@platform)
|
2011-05-31 15:51:22 +00:00
|
|
|
#elsif @driver_type == "fog_amazon"
|
|
|
|
# @driver = Lab::Drivers::FogAmazonDriver.new
|
|
|
|
#elsif @driver_type == "qemu"
|
2011-05-24 15:56:32 +00:00
|
|
|
# @driver = Lab::Drivers::QemuDriver.new
|
2011-05-31 15:51:22 +00:00
|
|
|
#elsif @driver_type == "qemudo"
|
2011-05-24 15:56:32 +00:00
|
|
|
# @driver = Lab::Drivers::QemudoDriver.new
|
2011-05-31 15:51:22 +00:00
|
|
|
#elsif @driver_type == "amazon"
|
2011-02-16 02:15:24 +00:00
|
|
|
# @driver = Lab::Drivers::AmazonDriver.new
|
2010-12-28 19:47:33 +00:00
|
|
|
else
|
2011-05-24 15:56:32 +00:00
|
|
|
raise "Unknown Driver Type"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def running?
|
|
|
|
@driver.running?
|
|
|
|
end
|
|
|
|
|
2011-02-16 02:15:24 +00:00
|
|
|
def location
|
|
|
|
@driver.location
|
|
|
|
end
|
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
def start
|
|
|
|
@driver.start
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
|
|
|
@driver.stop
|
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
|
|
|
@driver.pause
|
|
|
|
end
|
|
|
|
|
|
|
|
def suspend
|
|
|
|
@driver.suspend
|
|
|
|
end
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
def reset
|
|
|
|
@driver.reset
|
|
|
|
end
|
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
def resume
|
|
|
|
@driver.resume
|
|
|
|
end
|
|
|
|
|
2011-02-11 15:04:33 +00:00
|
|
|
def create_snapshot(snapshot)
|
|
|
|
@driver.create_snapshot(snapshot)
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-02-11 15:04:33 +00:00
|
|
|
def revert_snapshot(snapshot)
|
|
|
|
@driver.revert_snapshot(snapshot)
|
2011-02-04 09:17:11 +00:00
|
|
|
end
|
2011-02-11 15:04:33 +00:00
|
|
|
|
|
|
|
def delete_snapshot(snapshot)
|
|
|
|
@driver.delete_snapshot(snapshot)
|
|
|
|
end
|
|
|
|
|
2011-02-04 09:17:11 +00:00
|
|
|
def revert_and_start(snapshot)
|
2011-02-11 15:04:33 +00:00
|
|
|
self.revert_snapshot(snapshot)
|
2011-02-04 09:17:11 +00:00
|
|
|
self.start
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def copy_to(from,to)
|
|
|
|
@driver.copy_to(from,to)
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_from(from,to)
|
|
|
|
@driver.copy_from(from,to)
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def run_command(command)
|
|
|
|
@driver.run_command(command)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_file_exists(file)
|
|
|
|
@driver.check_file_exists(file)
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def create_directory(directory)
|
|
|
|
@driver.create_directory(directory)
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def open_uri(uri)
|
2011-05-24 15:56:32 +00:00
|
|
|
# we don't filter the uri, as it's getting tossed into a script
|
|
|
|
# by the driver
|
|
|
|
if @os == "windows"
|
|
|
|
command = "\"C:\\program files\\internet explorer\\iexplore.exe\" #{uri}"
|
|
|
|
else
|
|
|
|
command = "firefox #{uri}"
|
|
|
|
end
|
|
|
|
|
|
|
|
@driver.run_command(command)
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2011-05-24 15:56:32 +00:00
|
|
|
return "#{@vmid}: #{@location}"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_yaml
|
2011-01-17 05:58:16 +00:00
|
|
|
out = " - vmid: #{@vmid}\n"
|
2011-05-31 15:51:22 +00:00
|
|
|
out += " driver: #{@driver_type}\n"
|
2011-02-16 02:15:24 +00:00
|
|
|
out += " location: #{@driver.location}\n"
|
|
|
|
out += " type: #{@type}\n"
|
2011-01-17 05:58:16 +00:00
|
|
|
out += " tools: #{@tools}\n"
|
2011-05-24 15:56:32 +00:00
|
|
|
out += " os: #{@os}\n"
|
|
|
|
out += " arch: #{@arch}\n"
|
2011-05-31 15:51:22 +00:00
|
|
|
if @user or @host # Remote vm/drivers only
|
|
|
|
out += " user: #{@user}\n"
|
|
|
|
out += " host: #{@host}\n"
|
|
|
|
end
|
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
out += " credentials:\n"
|
|
|
|
@credentials.each do |credential|
|
|
|
|
out += " - user: #{credential['user']}\n"
|
|
|
|
out += " pass: #{credential['pass']}\n"
|
|
|
|
end
|
2011-01-17 05:58:16 +00:00
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
return out
|
2011-05-24 15:56:32 +00:00
|
|
|
end
|
|
|
|
private
|
|
|
|
|
|
|
|
def filter_input(string)
|
|
|
|
return unless string
|
|
|
|
|
|
|
|
if !(string =~ /^[\d*\w*\s*\[\]\{\}\/\\\.\-\"\(\)]*$/)
|
|
|
|
raise "WARNING! Invalid character in: #{string}"
|
|
|
|
end
|
2011-01-17 05:58:16 +00:00
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
string
|
|
|
|
end
|
|
|
|
end
|
2011-01-17 05:58:16 +00:00
|
|
|
end
|