add in the modifier stuff from AHA! demo.
git-svn-id: file:///home/svn/framework3/trunk@13408 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
parent
486241cc99
commit
ded8008470
|
@ -0,0 +1,10 @@
|
|||
require 'controller/workstation_controller'
|
||||
require 'controller/workstation_vixr_controller'
|
||||
require 'controller/remote_workstation_controller'
|
||||
require 'controller/virtualbox_controller'
|
||||
require 'controller/dynagen_controller'
|
||||
require 'controller/remote_esx_controller'
|
||||
#require 'controller/qemu_controller'
|
||||
#require 'controller/qemudo_controller'
|
||||
#require 'controller/amazon_controller'
|
||||
#require 'controller/fog_controller'
|
|
@ -1,27 +1,23 @@
|
|||
require 'vm_driver'
|
||||
|
||||
##
|
||||
## $Id: remote_esx_driver.rb 12713 2011-05-25 07:30:22Z jcran $
|
||||
## $Id$
|
||||
##
|
||||
|
||||
# This driver was built against:
|
||||
# VMware ESX Host Agent 4.1.0 build-348481
|
||||
|
||||
|
||||
module Lab
|
||||
module Drivers
|
||||
|
||||
class RemoteEsxDriver < VmDriver
|
||||
|
||||
attr_accessor :location # among other things
|
||||
|
||||
def initialize(vmid, location, os=nil, tools=false, user=nil, host=nil, credentials=nil)
|
||||
def initialize(vmid,os=nil, tools=false, user=nil, host=nil, credentials=nil)
|
||||
|
||||
unless user then raise ArgumentError, "Must provide a username" end
|
||||
unless host then raise ArgumentError, "Must provide a hostname" end
|
||||
|
||||
@vmid = filter_command(vmid)
|
||||
@location = filter_command(location)
|
||||
@vmid = vmid
|
||||
@user = filter_command(user)
|
||||
@host = filter_command(host)
|
||||
@credentials = credentials # individually filtered
|
|
@ -9,7 +9,6 @@
|
|||
# functionality.
|
||||
#
|
||||
|
||||
|
||||
module Lab
|
||||
module Drivers
|
||||
class VmDriver
|
||||
|
@ -95,14 +94,14 @@ private
|
|||
gem 'net-scp'
|
||||
require 'net/scp'
|
||||
|
||||
begin
|
||||
#begin
|
||||
# upload a file to a remote server
|
||||
Net::SCP.start(@vmid, @vm_user, :password => @vm_pass) do |scp|
|
||||
scp.upload!(from,to)
|
||||
end
|
||||
rescue Exception => e
|
||||
return false
|
||||
end
|
||||
Net::SCP.start(@vmid, @vm_user, :password => @vm_pass) do |scp|
|
||||
scp.upload!(from,to)
|
||||
end
|
||||
#rescue Exception => e
|
||||
# return false
|
||||
#end
|
||||
end
|
||||
|
||||
def scp_from(from,to)
|
||||
|
@ -112,14 +111,14 @@ private
|
|||
gem 'net-scp'
|
||||
require 'net/scp'
|
||||
|
||||
begin
|
||||
# download a file from a remote server
|
||||
Net::SCP.start(@vmid, @vm_user, :password => @vm_pass) do |scp|
|
||||
scp.download!(from,to)
|
||||
end
|
||||
rescue Exception => e
|
||||
return false
|
||||
end
|
||||
#begin
|
||||
# download a file from a remote server
|
||||
Net::SCP.start(@vmid, @vm_user, :password => @vm_pass) do |scp|
|
||||
scp.download!(from,to)
|
||||
end
|
||||
#rescue Exception => e
|
||||
# return false
|
||||
#end
|
||||
|
||||
end
|
||||
|
||||
|
@ -127,20 +126,20 @@ private
|
|||
gem 'net-ssh'
|
||||
require 'net/ssh'
|
||||
|
||||
begin
|
||||
Net::SSH.start(@vmid, @vm_user, :password => @vm_pass) do |ssh|
|
||||
result = ssh.exec!(command)
|
||||
end
|
||||
rescue Exception => e
|
||||
return false
|
||||
#begin
|
||||
Net::SSH.start(@vmid, @vm_user, :password => @vm_pass) do |ssh|
|
||||
result = ssh.exec!(command)
|
||||
end
|
||||
#rescue Exception => e
|
||||
# return false
|
||||
#end
|
||||
|
||||
end
|
||||
|
||||
def filter_input(string)
|
||||
return "" unless string
|
||||
|
||||
if !(string =~ /^[\w\s\[\]\{\}\/\\\.\-\"\(\):!]*$/)
|
||||
if !(string =~ /^[0-9\w\s\[\]\{\}\/\\\.\-\"\(\):!]*$/)
|
||||
raise "WARNING! Invalid character in: #{string}"
|
||||
end
|
||||
|
||||
|
@ -150,7 +149,7 @@ private
|
|||
def filter_command(string)
|
||||
return "" unless string
|
||||
|
||||
if !(string =~ /^[\w\s\[\]\{\}\/\\\.\-\"\(\)]*$/)
|
||||
if !(string =~ /^[0-9\w\s\[\]\{\}\/\\\.\-\"\(\)]*$/)
|
||||
raise "WARNING! Invalid character in: #{string}"
|
||||
end
|
||||
|
||||
|
@ -158,11 +157,11 @@ private
|
|||
end
|
||||
|
||||
def system_command(command)
|
||||
begin
|
||||
system(command)
|
||||
rescue Exception => e
|
||||
return false
|
||||
end
|
||||
#begin
|
||||
system(command)
|
||||
#rescue Exception => e
|
||||
# return false
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
@ -100,21 +100,33 @@ class WorkstationDriver < VmDriver
|
|||
# delete it on the guest
|
||||
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
|
||||
"deleteFileInGuest \'#{@location}\' \'#{remote_tempfile_path}\'"
|
||||
#system_command(vmrunstr)
|
||||
system_command(vmrunstr)
|
||||
|
||||
# delete it locally
|
||||
local_delete_command = "rm #{local_tempfile_path}"
|
||||
#system_command(local_delete_command)
|
||||
system_command(local_delete_command)
|
||||
else
|
||||
# since we can't copy easily w/o tools, let's just run it directly :/
|
||||
if @os == "linux"
|
||||
|
||||
output_file = "/tmp/lab_command_output_#{rand(1000000)}"
|
||||
|
||||
scp_to(local_tempfile_path, remote_tempfile_path)
|
||||
ssh_exec(remote_run_command)
|
||||
ssh_exec(remote_run_command + "> #{output_file}")
|
||||
scp_from(output_file, output_file)
|
||||
|
||||
ssh_exec("rm #{output_file}")
|
||||
ssh_exec("rm #{remote_tempfile_path}")
|
||||
|
||||
# Ghettohack!
|
||||
string = File.open(output_file,"r").read
|
||||
`rm #{output_file}`
|
||||
|
||||
else
|
||||
raise "zomgwtfbbqnotools"
|
||||
end
|
||||
end
|
||||
return string
|
||||
end
|
||||
|
||||
def copy_from(from, to)
|
|
@ -16,10 +16,14 @@ class WorkstationVixrDriver < VmDriver
|
|||
|
||||
def initialize(vmid, location, os=nil, tools=false, credentials=nil)
|
||||
|
||||
begin
|
||||
# We have to treat this differently, as it's not in the same tree
|
||||
begin
|
||||
require 'vixr'
|
||||
rescue
|
||||
raise "Oops, no vixr installed. Consider using the regular workstation driver."
|
||||
rescue LoadError
|
||||
puts "WARNING: Library pro_vixr not found. To resolve this error, please\n" +
|
||||
" install the vixr gem. Latest is available here:\n" +
|
||||
"https://github.com/rhythmx/vixr ."
|
||||
raise "Unable to create vixr driver"
|
||||
end
|
||||
|
||||
@vmid = filter_command(vmid)
|
|
@ -0,0 +1,10 @@
|
|||
require 'driver/workstation_driver'
|
||||
require 'driver/workstation_vixr_driver'
|
||||
require 'driver/remote_workstation_driver'
|
||||
require 'driver/virtualbox_driver'
|
||||
require 'driver/dynagen_driver'
|
||||
require 'driver/remote_esx_driver'
|
||||
#require 'driver/qemu_driver'
|
||||
#require 'driver/qemudo_driver'
|
||||
#require 'driver/amazon_driver'
|
||||
#require 'driver/fog_driver'
|
|
@ -0,0 +1 @@
|
|||
require 'modifier/test_modifier'
|
|
@ -2,16 +2,6 @@
|
|||
## $Id$
|
||||
##
|
||||
|
||||
require 'workstation_driver'
|
||||
require 'workstation_vixr_driver'
|
||||
require 'remote_workstation_driver'
|
||||
require 'virtualbox_driver'
|
||||
require 'dynagen_driver'
|
||||
require 'remote_esx_driver'
|
||||
#require 'qemu_driver'
|
||||
#require 'qemudo_driver'
|
||||
#require 'amazon_driver'
|
||||
|
||||
module Lab
|
||||
class Vm
|
||||
|
||||
|
@ -38,6 +28,7 @@ class Vm
|
|||
## credentials (of the form [ {'user'=>"user",'pass'=>"pass", 'admin' => false}, ... ])
|
||||
## os (currently only linux / windows)
|
||||
## arch (currently only 32 / 64
|
||||
|
||||
def initialize(config = {})
|
||||
|
||||
# Mandatory
|
||||
|
@ -53,9 +44,14 @@ class Vm
|
|||
@tools = config['tools'] || false # don't filter this, not used in cmdlines
|
||||
@os = config['os'] || nil
|
||||
@arch = config['arch'] || nil
|
||||
|
||||
@type = filter_input(config['type']) || "unspecified"
|
||||
@credentials = config['credentials'] || []
|
||||
|
||||
# Load in a list of modifiers. These provide additional methods
|
||||
# TODO - currently it is up to the user to verify that
|
||||
# modifiers are properly used with the correct VM image. If not,
|
||||
# the results are likely to be disasterous.
|
||||
@modifiers = config['modifiers']
|
||||
|
||||
# Optional for virtualbox
|
||||
@location = filter_input(config['location'])
|
||||
|
@ -70,6 +66,7 @@ class Vm
|
|||
#Only dynagen
|
||||
@platform = config['platform']
|
||||
|
||||
# Process the correct driver
|
||||
if @driver_type == "workstation"
|
||||
@driver = Lab::Drivers::WorkstationDriver.new(@vmid, @location, @os, @tools, @credentials)
|
||||
elsif @driver_type == "workstation_vixr"
|
||||
|
@ -81,16 +78,20 @@ class Vm
|
|||
elsif @driver_type == "dynagen"
|
||||
@driver = Lab::Drivers::DynagenDriver.new(@vmid, @location,@platform)
|
||||
elsif @driver_type == "remote_esx"
|
||||
@driver = Lab::Drivers::RemoteEsxDriver.new(@vmid, @location, @os, @tools, @user, @host, @credentials)
|
||||
@driver = Lab::Drivers::RemoteEsxDriver.new(@vmid, @os, @tools, @user, @host, @credentials)
|
||||
#elsif @driver_type == "qemu"
|
||||
# @driver = Lab::Drivers::QemuDriver.new
|
||||
#elsif @driver_type == "qemudo"
|
||||
# @driver = Lab::Drivers::QemudoDriver.new
|
||||
#elsif @driver_type == "amazon"
|
||||
# @driver = Lab::Drivers::AmazonDriver.new
|
||||
#elsif @driver_type == "fog"
|
||||
# @driver = Lab::Drivers::FogDriver.new
|
||||
else
|
||||
raise "Unknown Driver Type"
|
||||
end
|
||||
|
||||
# Now handle the modifiers - for now, just eval'm
|
||||
@modifiers.each { |modifier| self.class.send(:include, eval("Lab::Modifier::#{modifier}"))}
|
||||
|
||||
end
|
||||
|
||||
def running?
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
##
|
||||
## $Id$
|
||||
##
|
||||
## This is the main lab controller.
|
||||
## This is the main lab controller. Require this controller to get all
|
||||
## lab functionality.
|
||||
##
|
||||
##
|
||||
|
||||
$:.unshift(File.expand_path(File.dirname(__FILE__)))
|
||||
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'driver')))
|
||||
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'controller')))
|
||||
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), 'modifier')))
|
||||
|
||||
require 'find'
|
||||
require 'enumerator'
|
||||
require 'vm'
|
||||
require 'yaml'
|
||||
require 'workstation_controller'
|
||||
require 'workstation_vixr_controller'
|
||||
require 'remote_workstation_controller'
|
||||
require 'virtualbox_controller'
|
||||
require 'dynagen_controller'
|
||||
require 'remote_esx_controller'
|
||||
#require 'qemu_controller'
|
||||
#require 'qemudo_controller'
|
||||
#require 'amazon_controller'
|
||||
require 'enumerator'
|
||||
require 'fileutils'
|
||||
|
||||
require 'vm'
|
||||
require 'controllers'
|
||||
require 'drivers'
|
||||
require 'modifiers'
|
||||
|
||||
module Lab
|
||||
module Controllers
|
||||
|
@ -34,7 +34,8 @@ module Controllers
|
|||
include Lab::Controllers::RemoteEsxController
|
||||
#include Lab::Controllers::QemuController
|
||||
#include Lab::Controllers::QemudoController
|
||||
#include Lab::Controllers::AmazonController
|
||||
#include Lab::Controllers::AmazonController
|
||||
#include Lab::Controllers::FogController
|
||||
|
||||
|
||||
def initialize (labdef=nil)
|
||||
|
@ -65,6 +66,7 @@ module Controllers
|
|||
end
|
||||
|
||||
def add_vm(vmid, type,location,credentials=nil,user=nil,host=nil)
|
||||
|
||||
@vms << Vm.new( { 'vmid' => vmid,
|
||||
'driver' => type,
|
||||
'location' => location,
|
||||
|
@ -132,8 +134,8 @@ module Controllers
|
|||
vm_list =::Lab::Controllers::RemoteEsxController::dir_list(dir)
|
||||
#elsif driver_type.downcase == "esxi_vixr"
|
||||
# vm_list =::Lab::Controllers::EsxiVixrController::dir_list(dir)
|
||||
#elsif driver_type.downcase == "fog_amazon"
|
||||
# vm_list = ::Lab::Controllers::FogAmazonController::dir_list(dir)
|
||||
#elsif driver_type.downcase == "fog"
|
||||
# vm_list = ::Lab::Controllers::FogController::dir_list(dir)
|
||||
else
|
||||
raise TypeError, "Unsupported VM Type"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue