Skip to content

Commit

Permalink
updated workstation driver
Browse files Browse the repository at this point in the history
  • Loading branch information
jcran committed Mar 14, 2012
1 parent 21fc833 commit 60c7268
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
6 changes: 3 additions & 3 deletions lib/lab/driver/vm_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def remote_system_command(command)

def scp_to(local,remote)
if @vm_keyfile
puts "DEBUG: authenticating to #{@hostname} as #{@vm_user} with key #{@vm_keyfile}"
#puts "DEBUG: authenticating to #{@hostname} as #{@vm_user} with key #{@vm_keyfile}"
Net::SCP.start(@hostname, @vm_user, :keys => [@vm_keyfile]) do |scp|
puts "DEBUG: uploading #{local} to #{remote}"
scp.upload!(local,remote)
Expand All @@ -143,7 +143,7 @@ def scp_to(local,remote)
def scp_from(remote, local)
# download a file from a remote server
if @vm_keyfile
puts "DEBUG: authenticating to #{@hostname} as #{@vm_user} with key #{@vm_keyfile}"
#puts "DEBUG: authenticating to #{@hostname} as #{@vm_user} with key #{@vm_keyfile}"
Net::SCP.start(@hostname, @vm_user, :keys => [@vm_keyfile]) do |scp|
puts "DEBUG: downloading #{remote} to #{local}"
scp.download!(remote,local)
Expand All @@ -158,7 +158,7 @@ def scp_from(remote, local)

def ssh_exec(command)
if @vm_keyfile
puts "DEBUG: authenticating to #{@hostname} as #{@vm_user} with key #{@vm_keyfile}"
#puts "DEBUG: authenticating to #{@hostname} as #{@vm_user} with key #{@vm_keyfile}"
Net::SSH.start(@hostname, @vm_user, :keys => [@vm_keyfile]) do |ssh|
puts "DEBUG: running command: #{command}"
ssh.exec!(command)
Expand Down
46 changes: 21 additions & 25 deletions lib/lab/driver/workstation_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,30 @@ def run_command(command)
script_rand_name = rand(1000000)

#
# Configure paths for each OS
# Configure paths for each OS - We really can't filter command, so we're gonna
# stick it in a script
#
if @os == "windows"
local_tempfile_path = "/tmp/lab_script_#{script_rand_name}.bat"
remote_tempfile_path = "C:\\\\lab_script_#{script_rand_name}.bat"
remote_output_file = "C:\\\\lab_command_output_#{script_rand_name}"
remote_run_command = remote_tempfile_path
File.open(local_tempfile_path, 'w') {|f| f.write(command) }
else

local_tempfile_path = "/tmp/lab_script_#{script_rand_name}.sh"
remote_tempfile_path = "/tmp/lab_script_#{script_rand_name}.sh"
remote_run_command = remote_tempfile_path # TODO - do we need to append /bin/sh ?
remote_output_file = "/tmp/lab_command_output_#{script_rand_name}"
local_output_file = "/tmp/lab_command_output_#{script_rand_name}"

remote_run_command = remote_tempfile_path

File.open(local_tempfile_path, 'w') {|f| f.write("#!/bin/sh\n#{command}\n")}
end

#
# We really can't filter command, so we're gonna stick it in a script
#

if @tools

puts "DEBUG: Running w/ tools"
#puts "DEBUG: Running w/ tools"

#
# Copy our local tempfile to the guest
Expand All @@ -92,19 +95,20 @@ def run_command(command)

if @os == "linux"
#
# Now run the command directly on the guest
# Now run the command directly on the guest (linux - call w/ /bin/sh)
#
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
"runProgramInGuest \'#{@location}\' /bin/sh #{remote_tempfile_path}"
"runProgramInGuest \'#{@location}\' /bin/sh #{remote_tempfile_path} > #{remote_output_file}"
system_command(vmrunstr)
else
#
# Now run the command directly on the guest
# Now run the command directly on the guest (windows)
#
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
"runProgramInGuest \'#{@location}\' #{remote_tempfile_path}"
"runProgramInGuest \'#{@location}\' #{remote_tempfile_path} > #{remote_output_file}"
system_command(vmrunstr)
end

#
# Cleanup. Delete it on the guest
#
Expand All @@ -124,11 +128,6 @@ def run_command(command)
#

if @os == "linux"
#
# Set up our paths
#
remote_output_file = "/tmp/lab_command_output_#{rand(1000000)}"
local_output_file = "/tmp/lab_command_output_#{rand(1000000)}"

#
# Copy it over
Expand All @@ -145,26 +144,23 @@ def run_command(command)
#
scp_from(remote_output_file, local_output_file)

#
# And clean up after yourself on the remote system
#
ssh_exec("rm #{remote_output_file}")
ssh_exec("rm #{remote_tempfile_path}")

# Now, let's look at the output of the command
string = File.open(local_output_file,"r").read
output_string = File.open(local_output_file,"r").read

#
# And clean that up too
# And clean up
#
ssh_exec("rm #{remote_output_file}")
ssh_exec("rm #{remote_tempfile_path}")

`rm #{local_output_file}`

else
raise "Hey, no tools, and windows? can't do nuttin for ya man."
end

end
return string
output_string
end

def copy_from(from, to)
Expand Down

0 comments on commit 60c7268

Please sign in to comment.