mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-23 22:50:09 +03:00
feature #595: vmm changes to support local exec
Added support code to driver libraries so they support both local and remote scripts execution. one_vmm_ssh driver was modified to test these changes.
This commit is contained in:
parent
b4f3a29e3e
commit
e5734fbc74
@ -30,17 +30,62 @@ require "CommandManager"
|
||||
# with the action name through the register_action func
|
||||
|
||||
class OpenNebulaDriver < ActionManager
|
||||
# This function parses a string with this form:
|
||||
#
|
||||
# 'deploy,shutdown,poll=poll_ganglia, cancel '
|
||||
#
|
||||
# and returns a hash:
|
||||
#
|
||||
# {"POLL"=>"poll_ganglia", "DEPLOY"=>nil, "SHUTDOWN"=>nil,
|
||||
# "CANCEL"=>nil}
|
||||
def self.parse_actions_list(str)
|
||||
actions=Hash.new
|
||||
str_splitted=str.split(/\s*,\s*/).map {|s| s.strip }
|
||||
|
||||
str_splitted.each do |a|
|
||||
m=a.match(/([^=]+)(=(.*))?/)
|
||||
next if !m
|
||||
|
||||
action=m[1].upcase
|
||||
|
||||
if m[2]
|
||||
script=m[3]
|
||||
script.strip! if script
|
||||
else
|
||||
script=nil
|
||||
end
|
||||
|
||||
actions[action]=script
|
||||
end
|
||||
|
||||
actions
|
||||
end
|
||||
|
||||
RESULT = {
|
||||
:success => "SUCCESS",
|
||||
:failure => "FAILURE"
|
||||
}
|
||||
|
||||
def initialize(concurrency=10, threaded=true, retries=0)
|
||||
super(concurrency,threaded)
|
||||
def initialize(concurrency=10, threaded=true, retries=0,
|
||||
directory='subsystem', local_actions={})
|
||||
super(concurrency, threaded)
|
||||
|
||||
@retries = retries
|
||||
@send_mutex=Mutex.new
|
||||
@local_actions=local_actions
|
||||
|
||||
# set default values
|
||||
@config = read_configuration
|
||||
@remote_scripts_base_path=@config['SCRIPTS_REMOTE_DIR']
|
||||
if ONE_LOCATION == nil
|
||||
@local_scripts_base_path = "/var/lib/one/remotes"
|
||||
else
|
||||
@local_scripts_base_path = "#{ENV['ONE_LOCATION']}/var/remotes"
|
||||
end
|
||||
|
||||
# dummy paths
|
||||
@remote_scripts_path=File.join(@remote_scripts_base_path, directory)
|
||||
@local_scripts_path=File.join(@local_scripts_base_path, directory)
|
||||
|
||||
register_action(:INIT, method("init"))
|
||||
end
|
||||
@ -55,6 +100,57 @@ class OpenNebulaDriver < ActionManager
|
||||
}
|
||||
end
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Calls remotes or local action checking the action name and @local_actions
|
||||
# -------------------------------------------------------------------------
|
||||
def do_action(parameters, id, host, aname, std_in=nil)
|
||||
command=action_command_line(aname, parameters)
|
||||
|
||||
if @local_actions.include? aname.to_s.upcase
|
||||
local_action(command, id, aname)
|
||||
else
|
||||
remotes_action(command, id, host, aname, @remote_scripts_path,
|
||||
std_in)
|
||||
end
|
||||
end
|
||||
|
||||
# Given the action name and the parameter returns full path of the script
|
||||
# and appends its parameters. It uses @local_actions hash to know if the
|
||||
# actions is remote or local. If the local actions has defined an special
|
||||
# script name this is used, otherwise the action name in downcase is
|
||||
# used as the script name.
|
||||
def action_command_line(action, parameters)
|
||||
action_name=action.to_s.upcase
|
||||
action_script=action.to_s.downcase
|
||||
|
||||
if @local_actions.include? action_name
|
||||
if @local_actions[action_name]
|
||||
action_script=@local_actions[action_name]
|
||||
end
|
||||
action_script_path=File.join(@local_scripts_path, action_script)
|
||||
else
|
||||
action_script_path=File.join(@remote_scripts_path, action_script)
|
||||
end
|
||||
|
||||
action_script_path+" "+parameters
|
||||
end
|
||||
|
||||
# True if the action is meant to be executed locally
|
||||
def action_is_local?(action)
|
||||
@local_actions.include? action.to_s.upcase
|
||||
end
|
||||
|
||||
# Name of the script file for the given action
|
||||
def action_script_name(action)
|
||||
name=@local_actions[action.to_s.upcase]
|
||||
|
||||
if name
|
||||
name
|
||||
else
|
||||
action.to_s.downcase
|
||||
end
|
||||
end
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
# Execute a command associated to an action and id in a remote host.
|
||||
# -------------------------------------------------------------------------
|
||||
|
@ -65,18 +65,19 @@ class VirtualMachineDriver < OpenNebulaDriver
|
||||
# -------------------------------------------------------------------------
|
||||
# Register default actions for the protocol
|
||||
# -------------------------------------------------------------------------
|
||||
def initialize(concurrency=10, threaded=true, retries=0)
|
||||
super(concurrency,threaded,retries)
|
||||
def initialize(concurrency=10, threaded=true, retries=0,
|
||||
directory='vmm', local_actions={})
|
||||
super(concurrency, threaded, retries, directory, local_actions)
|
||||
|
||||
@hosts = Array.new
|
||||
|
||||
register_action(ACTION[:deploy].to_sym, method("deploy"))
|
||||
register_action(ACTION[:shutdown].to_sym, method("shutdown"))
|
||||
register_action(ACTION[:cancel].to_sym, method("cancel"))
|
||||
register_action(ACTION[:save].to_sym, method("save"))
|
||||
register_action(ACTION[:restore].to_sym, method("restore"))
|
||||
register_action(ACTION[:migrate].to_sym, method("migrate"))
|
||||
register_action(ACTION[:poll].to_sym, method("poll"))
|
||||
register_action(ACTION[:deploy].to_sym, method("deploy"))
|
||||
register_action(ACTION[:shutdown].to_sym, method("shutdown"))
|
||||
register_action(ACTION[:cancel].to_sym, method("cancel"))
|
||||
register_action(ACTION[:save].to_sym, method("save"))
|
||||
register_action(ACTION[:restore].to_sym, method("restore"))
|
||||
register_action(ACTION[:migrate].to_sym, method("migrate"))
|
||||
register_action(ACTION[:poll].to_sym, method("poll"))
|
||||
end
|
||||
|
||||
# -------------------------------------------------------------------------
|
||||
@ -158,7 +159,7 @@ class VirtualMachineDriver < OpenNebulaDriver
|
||||
|
||||
private
|
||||
# -------------------------------------------------------------------------
|
||||
# Interface to handle the pending events from the ActionManager Interface
|
||||
# Interface to handle the pending events from the ActionManager Interface
|
||||
# -------------------------------------------------------------------------
|
||||
def delete_running_action(action_id)
|
||||
action=@action_running[action_id]
|
||||
|
@ -35,31 +35,17 @@ $: << RUBY_LIB_LOCATION
|
||||
require "VirtualMachineDriver"
|
||||
require 'getoptlong'
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# ----------------------------------------------------------------------------
|
||||
# The main class for the Sh driver
|
||||
# ----------------------------------------------------------------------------
|
||||
# ----------------------------------------------------------------------------
|
||||
class SshDriver < VirtualMachineDriver
|
||||
# ------------------------------------------------------------------------
|
||||
# SshDriver constructor
|
||||
# ------------------------------------------------------------------------
|
||||
def initialize(hypervisor, threads, retries, localpoll)
|
||||
super(threads,true,retries)
|
||||
|
||||
@config = read_configuration
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
# SshDriver constructor
|
||||
# ------------------------------------------------------------------------
|
||||
def initialize(hypervisor, threads, retries, local_actions)
|
||||
super(threads, true, retries, "vmm/#{hypervisor}", local_actions)
|
||||
|
||||
@hypervisor = hypervisor
|
||||
@remote_dir = @config['SCRIPTS_REMOTE_DIR']
|
||||
@remote_path = "#{@config['SCRIPTS_REMOTE_DIR']}/vmm/#{@hypervisor}"
|
||||
|
||||
if ONE_LOCATION == nil
|
||||
@actions_path = "/usr/lib/one"
|
||||
else
|
||||
@actions_path = "#{ENV['ONE_LOCATION']}/lib"
|
||||
end
|
||||
|
||||
@actions_path << "/remotes/vmm/#{hypervisor}"
|
||||
|
||||
@local_poll = localpoll
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------------ #
|
||||
@ -78,46 +64,40 @@ class SshDriver < VirtualMachineDriver
|
||||
domain = tmp.read
|
||||
tmp.close()
|
||||
|
||||
remotes_action("#{@remote_path}/deploy #{remote_dfile}",
|
||||
id, host, :deploy, @remote_dir, domain)
|
||||
if action_is_local?(:deploy)
|
||||
dfile=local_dfile
|
||||
else
|
||||
dfile=remote_dfile
|
||||
end
|
||||
|
||||
do_action("#{dfile} #{host}", id, host, :deploy, domain)
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------------ #
|
||||
# Basic Domain Management Operations #
|
||||
# ------------------------------------------------------------------------ #
|
||||
def shutdown(id, host, deploy_id, not_used)
|
||||
remotes_action("#{@remote_path}/shutdown #{deploy_id}",
|
||||
id, host, :shutdown, @remote_dir)
|
||||
do_action("#{deploy_id} #{host}", id, host, :shutdown)
|
||||
end
|
||||
|
||||
def cancel(id, host, deploy_id, not_used)
|
||||
remotes_action("#{@remote_path}/cancel #{deploy_id}",
|
||||
id, host, :cancel, @remote_dir)
|
||||
do_action("#{deploy_id} #{host}", id, host, :cancel)
|
||||
end
|
||||
|
||||
def save(id, host, deploy_id, file)
|
||||
remotes_action("#{@remote_path}/save #{deploy_id} #{file}",
|
||||
id, host, :save, @remote_dir)
|
||||
do_action("#{deploy_id} #{file} #{host}", id, host, :save)
|
||||
end
|
||||
|
||||
def restore(id, host, deploy_id, file)
|
||||
remotes_action("#{@remote_path}/restore #{file}",
|
||||
id, host, :restore, @remote_dir)
|
||||
do_action("#{file} #{host}", id, host, :restore)
|
||||
end
|
||||
|
||||
def migrate(id, host, deploy_id, dest_host)
|
||||
remotes_action("#{@remote_path}/migrate #{deploy_id} #{dest_host}",
|
||||
id, host, :migrate, @remote_dir)
|
||||
do_action("#{deploy_id} #{dest_host} #{host}", id, host, :migrate)
|
||||
end
|
||||
|
||||
def poll(id, host, deploy_id, not_used)
|
||||
if @local_poll != nil
|
||||
local_action("#{@actions_path}/#{@local_poll} #{host} #{deploy_id}",
|
||||
id, :poll)
|
||||
else
|
||||
remotes_action("#{@remote_path}/poll #{deploy_id}",
|
||||
id, host, :poll, @remote_dir)
|
||||
end
|
||||
do_action("#{deploy_id} #{host}", id, host, :poll)
|
||||
end
|
||||
end
|
||||
|
||||
@ -127,13 +107,13 @@ end
|
||||
opts = GetoptLong.new(
|
||||
[ '--retries', '-r', GetoptLong::OPTIONAL_ARGUMENT ],
|
||||
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ],
|
||||
[ '--localpoll', '-p', GetoptLong::REQUIRED_ARGUMENT ]
|
||||
[ '--local', '-l', GetoptLong::REQUIRED_ARGUMENT ]
|
||||
)
|
||||
|
||||
hypervisor = ''
|
||||
retries = 0
|
||||
threads = 15
|
||||
localpoll = nil
|
||||
hypervisor = ''
|
||||
retries = 0
|
||||
threads = 15
|
||||
local_actions = {}
|
||||
|
||||
begin
|
||||
opts.each do |opt, arg|
|
||||
@ -142,19 +122,19 @@ begin
|
||||
retries = arg.to_i
|
||||
when '--threads'
|
||||
threads = arg.to_i
|
||||
when '--localpoll'
|
||||
localpoll = arg
|
||||
when '--local'
|
||||
local_actions=OpenNebulaDriver.parse_actions_list(arg)
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
if ARGV.length >= 1
|
||||
if ARGV.length >= 1
|
||||
hypervisor = ARGV.shift
|
||||
else
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
ssh_driver = SshDriver.new(hypervisor, threads, retries, localpoll)
|
||||
ssh_driver = SshDriver.new(hypervisor, threads, retries, local_actions)
|
||||
ssh_driver.start_driver
|
||||
|
Loading…
x
Reference in New Issue
Block a user