2010-12-28 19:47:33 +00:00
|
|
|
##
|
|
|
|
## $Id$
|
|
|
|
##
|
2011-05-24 15:56:32 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# !!WARNING!! - All drivers are expected to filter input before running
|
|
|
|
# anything based on it. This is particularly important in the case
|
|
|
|
# of the drivers which wrap a command line program to provide
|
|
|
|
# functionality.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
2011-01-17 05:58:16 +00:00
|
|
|
module Lab
|
|
|
|
module Drivers
|
2010-12-28 19:47:33 +00:00
|
|
|
class VmDriver
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def register # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command not Implemented"
|
2011-01-17 05:58:16 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def unregister # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def start # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def stop # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def suspend # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def pause # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def reset # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def create_snapshot(snapshot) # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def revert_snapshot(snapshot) # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def delete_snapshot(snapshot) # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def run_command(command) # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def copy_from(from, to) # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def copy_to(from, to) # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def check_file_exists(file) # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def create_directory(directory) # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def cleanup # Must be implemented in a child *_driver class
|
|
|
|
raise Exception, "Command Not Implemented"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
private
|
|
|
|
def scp_to(from,to)
|
|
|
|
gem 'net-ssh'
|
|
|
|
require 'net/ssh'
|
|
|
|
|
|
|
|
gem 'net-scp'
|
|
|
|
require 'net/scp'
|
|
|
|
|
2011-06-05 06:57:24 +00:00
|
|
|
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
|
2011-01-17 05:58:16 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def scp_from(from,to)
|
|
|
|
gem 'net-ssh'
|
|
|
|
require 'net/ssh'
|
2011-02-16 02:15:24 +00:00
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
gem 'net-scp'
|
|
|
|
require 'net/scp'
|
2011-01-17 05:58:16 +00:00
|
|
|
|
2011-06-05 06:57:24 +00:00
|
|
|
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
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def ssh_exec(command)
|
|
|
|
gem 'net-ssh'
|
|
|
|
require 'net/ssh'
|
2011-06-05 06:57:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
Net::SSH.start(@vmid, @vm_user, :password => @vm_pass) do |ssh|
|
|
|
|
result = ssh.exec!(command)
|
|
|
|
end
|
|
|
|
rescue Exception => e
|
|
|
|
return false
|
2011-01-17 05:58:16 +00:00
|
|
|
end
|
2011-06-05 06:57:24 +00:00
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
end
|
2010-12-28 19:47:33 +00:00
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
def filter_input(string)
|
|
|
|
return unless string
|
|
|
|
|
2011-05-25 06:26:26 +00:00
|
|
|
if !(string =~ /^[\w\s\[\]\{\}\/\\\.\-\"\(\):]*$/)
|
2011-05-24 15:56:32 +00:00
|
|
|
raise "WARNING! Invalid character in: #{string}"
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
|
|
|
|
2011-05-24 15:56:32 +00:00
|
|
|
string
|
|
|
|
end
|
|
|
|
|
|
|
|
def system_command(command)
|
2011-06-04 03:34:37 +00:00
|
|
|
begin
|
2011-06-05 06:57:24 +00:00
|
|
|
#puts "DEBUG: running command #{command}"
|
2011-06-04 03:34:37 +00:00
|
|
|
system(command)
|
|
|
|
rescue Exception => e
|
|
|
|
return false
|
|
|
|
end
|
2011-05-24 15:56:32 +00:00
|
|
|
end
|
2010-12-28 19:47:33 +00:00
|
|
|
end
|
2011-01-17 05:58:16 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|