2011-05-24 15:56:32 +00:00
|
|
|
require 'vm_driver'
|
|
|
|
##
|
|
|
|
## $Id: workstation_driver.rb 11753 2011-02-16 02:15:24Z jcran $
|
|
|
|
##
|
|
|
|
|
|
|
|
# This requires rhythmx's vixr driver from https://github.com/rhythmx/vixr
|
|
|
|
# and below that, the VIX api from vmware http://www.vmware.com/support/developer/vix-api/
|
|
|
|
|
|
|
|
module Lab
|
|
|
|
module Drivers
|
|
|
|
|
|
|
|
class WorkstationVixrDriver < VmDriver
|
|
|
|
|
|
|
|
attr_accessor :type
|
|
|
|
attr_accessor :location
|
|
|
|
|
2011-06-04 05:57:09 +00:00
|
|
|
def initialize(vmid, location, os=nil, tools=false, credentials=nil)
|
2011-05-24 15:56:32 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
require 'vixr'
|
|
|
|
rescue
|
|
|
|
raise "Oops, no vixr installed. Consider using the regular workstation driver."
|
|
|
|
end
|
|
|
|
|
|
|
|
@vmid = filter_input(vmid)
|
|
|
|
@location = filter_input(location)
|
|
|
|
if !File.exist?(@location)
|
|
|
|
raise ArgumentError,"Couldn't find: " + location
|
|
|
|
end
|
|
|
|
|
|
|
|
@credentials = credentials
|
2011-06-04 05:57:09 +00:00
|
|
|
@tools = tools # not used in command lines, no filter
|
|
|
|
@os = os # not used in command lines, no filter
|
2011-05-24 15:56:32 +00:00
|
|
|
|
|
|
|
# TODO - Currently only implemented for the first set
|
|
|
|
if @credentials.count > 0
|
2011-06-04 03:11:49 +00:00
|
|
|
@vm_user = filter_input(@credentials[0]['user']) || "\'\'"
|
|
|
|
@vm_pass = filter_input(@credentials[0]['pass']) || "\'\'"
|
2011-05-24 15:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
host = VixR.connect()
|
2011-06-06 19:29:15 +00:00
|
|
|
vm = host.open_vmx(@location)
|
2011-05-24 15:56:32 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
|
|
|
vm.power_on
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
|
|
|
vm.power_off
|
|
|
|
end
|
|
|
|
|
|
|
|
def suspend
|
|
|
|
vm.suspend
|
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
|
|
|
vm.pause
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset
|
|
|
|
vm.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_snapshot(snapshot)
|
|
|
|
snapshot = filter_input(snapshot)
|
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws snapshot \\\'#{@location}\\\' #{snapshot} nogui")
|
|
|
|
end
|
|
|
|
|
|
|
|
def revert_snapshot(snapshot)
|
|
|
|
snapshot = filter_input(snapshot)
|
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws revertToSnapshot \\\'#{@location}\\\' #{snapshot} nogui")
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_snapshot(snapshot)
|
|
|
|
snapshot = filter_input(snapshot)
|
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws deleteSnapshot \\\'#{@location}\\\' #{snapshot} nogui" )
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def run_command(command)
|
|
|
|
command = filter_input(command)
|
|
|
|
if vm.login(@vm_user,@vm_pass)
|
|
|
|
vm.run_prog(command)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_from(from, to)
|
|
|
|
from = filter_input(from)
|
|
|
|
to = filter_input(to)
|
|
|
|
cp_from_host(from,to)
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_to(from, to)
|
|
|
|
from = filter_input(from)
|
|
|
|
to = filter_input(to)
|
|
|
|
vm.cp_to_guest(from,to)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_file_exists(file)
|
|
|
|
file = filter_input(file)
|
|
|
|
file_exists?(file)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_directory(directory)
|
|
|
|
directory = filter_input(directory)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cleanup
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def running?
|
|
|
|
vm.running?
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|