2010-12-28 19:47:33 +00:00
|
|
|
require 'vm_driver'
|
|
|
|
|
|
|
|
##
|
|
|
|
## $Id$
|
|
|
|
##
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
module Lab
|
|
|
|
module Drivers
|
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
class WorkstationDriver < VmDriver
|
|
|
|
|
|
|
|
attr_accessor :type
|
|
|
|
attr_accessor :location
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
def initialize(location, credentials=nil)
|
2011-02-08 07:26:18 +00:00
|
|
|
@location = filter_input(location)
|
|
|
|
|
|
|
|
if !File.exist?(@location)
|
2010-12-28 19:47:33 +00:00
|
|
|
raise ArgumentError,"Couldn't find: " + location
|
|
|
|
end
|
|
|
|
|
2011-02-08 07:26:18 +00:00
|
|
|
@credentials = filter_input_credentials(credentials)
|
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
@type = "Workstation"
|
2011-01-17 05:58:16 +00:00
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("vmrun -T ws start " + "\"#{@location}\"")
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("vmrun -T ws stop " + "\"#{@location}\"")
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def suspend
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("vmrun -T ws suspend " + "\"#{@location}\"")
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("vmrun -T ws pause " + "\"#{@location}\"")
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def reset
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("vmrun -T ws reset " + "\"#{@location}\"")
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create(snapshot)
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("vmrun -T ws snapshot " + "\"#{@location}\" \"#{@snapshot}\"")
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def revert(snapshot)
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("vmrun -T ws revertToSnapshot " + "\"#{@location}\" \"#{@snapshot}\"")
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def delete_snapshot(snapshot)
|
2011-01-17 05:58:16 +00:00
|
|
|
system_command("vmrun -T ws deleteSnapshot " + "\"#{@location}\" \"#{@snapshot}\"" )
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
def run_command(command, named_user=nil)
|
|
|
|
|
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
|
|
|
cred = get_best_credentials(named_user)
|
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
vmrunstr = "vmrun -T ws -gu \"{user}\" -gp \"{pass}\" runProgramInGuest \"#{@location}\" \"{command}\" -noWait -activeWindow"
|
2010-12-28 19:47:33 +00:00
|
|
|
|
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
def copy_from(from, to, named_user=nil)
|
|
|
|
|
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
|
|
|
cred = get_best_credentials(named_user)
|
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
vmrunstr = "vmrun -T ws -gu {user} -gp {pass} copyFileFromGuestToHost \"#{@location}\" \"{from}\" \"{to}\""
|
2010-12-28 19:47:33 +00:00
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
def copy_to(from, to, named_user=nil)
|
|
|
|
|
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
|
|
|
cred = get_best_credentials(named_user)
|
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
|
|
|
|
vmrunstr = "vmrun -T ws -gu {user} -gp {pass} copyFileFromHostToGuest \"#{@location}\" \"{from}\" \"{to}\""
|
2010-12-28 19:47:33 +00:00
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
def check_file_exists(file, named_user=nil)
|
|
|
|
|
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
|
|
|
cred = get_best_credentials(named_user)
|
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
|
|
|
|
vmrunstr = "vmrun -T ws -gu {user} -gp {pass} fileExistsInGuest \"#{@location}\" \"{file}\" "
|
2010-12-28 19:47:33 +00:00
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
def create_directory(directory, named_user=nil)
|
|
|
|
|
|
|
|
## this will return the first user if named_user doesn't exist
|
|
|
|
## -- that may not be entirely obvious...
|
|
|
|
cred = get_best_credentials(named_user)
|
|
|
|
|
|
|
|
user = cred['user']
|
|
|
|
pass = cred['pass']
|
|
|
|
admin = cred['admin']
|
|
|
|
|
|
|
|
vmrunstr = "vmrun -T ws -gu {user} -gp {pass} createDirectoryInGuest \"#{@location}\" \"#{directory}\" "
|
2010-12-28 19:47:33 +00:00
|
|
|
system_command(vmrunstr)
|
|
|
|
end
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
def cleanup
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-12-28 19:47:33 +00:00
|
|
|
def running?
|
|
|
|
## Get running Vms
|
|
|
|
running = `vmrun list`
|
|
|
|
running_array = running.split("\n")
|
|
|
|
running_array.shift
|
|
|
|
|
|
|
|
running_array.each do |vmx|
|
|
|
|
if vmx.to_s == @location.to_s
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2011-01-17 05:58:16 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|