2011-01-17 05:58:16 +00:00
|
|
|
require 'vm_driver'
|
|
|
|
|
|
|
|
##
|
|
|
|
## $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
module Lab
|
|
|
|
module Drivers
|
|
|
|
|
|
|
|
class RemoteWorkstationDriver < VmDriver
|
|
|
|
|
|
|
|
attr_accessor :type
|
|
|
|
attr_accessor :location
|
|
|
|
|
|
|
|
def initialize(location, user=nil, host=nil, credentials=nil)
|
|
|
|
|
2011-02-16 02:15:24 +00:00
|
|
|
## TODO - Should proabably check file existence?
|
2011-01-17 05:58:16 +00:00
|
|
|
|
|
|
|
unless user then raise ArgumentError, "Must provide a username" end
|
|
|
|
unless host then raise ArgumentError, "Must provide a hostname" end
|
|
|
|
|
2011-02-08 07:26:18 +00:00
|
|
|
@location = filter_input(location)
|
|
|
|
@user = filter_input(user)
|
2011-02-16 02:15:24 +00:00
|
|
|
@host = filter_input(host)
|
2011-02-08 07:26:18 +00:00
|
|
|
@credentials = filter_input_credentials(credentials)
|
2011-02-16 02:15:24 +00:00
|
|
|
@type = "remote_workstation"
|
2011-01-17 05:58:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws start \\\'#{@location}\\\' nogui")
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws stop \\\'#{@location}\\\' nogui")
|
|
|
|
end
|
|
|
|
|
|
|
|
def suspend
|
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws suspend \\\'#{@location}\\\' nogui")
|
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws pause \\\'#{@location}\\\' nogui")
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset
|
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws reset \\\'#{@location}\\\' nogui")
|
|
|
|
end
|
|
|
|
|
2011-02-11 15:04:33 +00:00
|
|
|
def create_snapshot(snapshot)
|
2011-02-16 02:15:24 +00:00
|
|
|
snapshot = filter_input(snapshot)
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws snapshot \\\'#{@location}\\\' #{snapshot} nogui")
|
|
|
|
end
|
|
|
|
|
2011-02-11 15:04:33 +00:00
|
|
|
def revert_snapshot(snapshot)
|
2011-02-16 02:15:24 +00:00
|
|
|
snapshot = filter_input(snapshot)
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws revertToSnapshot \\\'#{@location}\\\' #{snapshot} nogui")
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_snapshot(snapshot)
|
2011-02-16 02:15:24 +00:00
|
|
|
snapshot = filter_input(snapshot)
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("ssh #{@user}@#{@host} vmrun -T ws deleteSnapshot \\\'#{@location}\\\' #{snapshot} nogui" )
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def run_command(command, named_user=nil)
|
|
|
|
|
2011-02-08 07:37:06 +00:00
|
|
|
command = filter_input(command)
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
2011-02-16 02:15:24 +00:00
|
|
|
cred = get_best_creds(named_user)
|
2011-01-17 05:58:16 +00:00
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
vmrunstr = "ssh #{@user}@#{@host} vmrun -T ws -gu \\\'{user}\\\' -gp \\\'{pass}\\\' runProgramInGuest \\\'#{@location}\\\' \\\'{command}\\\' -noWait -activeWindow nogui"
|
|
|
|
|
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_from(from, to, named_user=nil)
|
|
|
|
|
2011-02-08 07:37:06 +00:00
|
|
|
from = filter_input(from)
|
|
|
|
to = filter_input(to)
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
2011-02-16 02:15:24 +00:00
|
|
|
cred = get_best_creds(named_user)
|
2011-01-17 05:58:16 +00:00
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
vmrunstr = "ssh #{@user}@#{@host} vmrun -T ws -gu {user} -gp {pass} copyFileFromGuestToHost \\\'#{@location}\\\' \\\'{from}\\\' \\\'{to}\\\' nogui"
|
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy_to(from, to, named_user=nil)
|
|
|
|
|
2011-02-08 07:37:06 +00:00
|
|
|
from = filter_input(from)
|
|
|
|
to = filter_input(to)
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
2011-02-16 02:15:24 +00:00
|
|
|
cred = get_best_creds(named_user)
|
2011-01-17 05:58:16 +00:00
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
|
|
|
|
vmrunstr = "ssh #{@user}@#{@host} vmrun -T ws -gu {user} -gp {pass} copyFileFromHostToGuest \\\'#{@location}\\\' \\\'{from}\\\' \\\'{to}\\\' nogui"
|
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_file_exists(file, named_user=nil)
|
|
|
|
|
2011-02-08 07:37:06 +00:00
|
|
|
file = filter_input(file)
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
2011-02-16 02:15:24 +00:00
|
|
|
cred = get_best_creds(named_user)
|
2011-01-17 05:58:16 +00:00
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
|
|
|
|
vmrunstr = "ssh #{@user}@#{@host} vmrun -T ws -gu {user} -gp {pass} fileExistsInGuest \\\'#{@location}\\\' \\\'{file}\\\' nogui"
|
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_directory(directory, named_user=nil)
|
|
|
|
|
2011-02-08 07:37:06 +00:00
|
|
|
directory = filter_input(directory)
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
2011-02-16 02:15:24 +00:00
|
|
|
cred = get_best_creds(named_user)
|
2011-01-17 05:58:16 +00:00
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
vmrunstr = "ssh #{@user}@#{@host} vmrun -T ws -gu {user} -gp {pass} createDirectoryInGuest \\\'#{@location}\\\' \\\'#{directory}\\\' nogui"
|
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def cleanup
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def running?
|
|
|
|
## Get running Vms
|
|
|
|
running = `ssh #{@user}@#{@host} vmrun list nogui`
|
|
|
|
running_array = running.split("\n")
|
|
|
|
running_array.shift
|
|
|
|
|
|
|
|
running_array.each do |vmx|
|
|
|
|
if vmx.to_s == @location.to_s
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-04 09:17:11 +00:00
|
|
|
false
|
2011-01-17 05:58:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|