1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-10 13:57:22 +03:00

Merge branch 'feature-595'

This commit is contained in:
Javi Fontan 2011-06-15 19:34:12 +02:00
commit bc3887d9ab
33 changed files with 1000 additions and 756 deletions

View File

@ -164,8 +164,7 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \
$ETC_LOCATION/im_xen \
$ETC_LOCATION/im_ec2 \
$ETC_LOCATION/vmm_ec2 \
$ETC_LOCATION/vmm_ssh \
$ETC_LOCATION/vmm_sh \
$ETC_LOCATION/vmm_exec \
$ETC_LOCATION/tm_nfs \
$ETC_LOCATION/tm_ssh \
$ETC_LOCATION/tm_dummy \
@ -260,12 +259,12 @@ INSTALL_FILES=(
IM_PROBES_KVM_FILES:$VAR_LOCATION/remotes/im/kvm.d
IM_PROBES_XEN_FILES:$VAR_LOCATION/remotes/im/xen.d
IM_PROBES_GANGLIA_FILES:$VAR_LOCATION/remotes/im/ganglia.d
VMM_SSH_KVM_SCRIPTS:$VAR_LOCATION/remotes/vmm/kvm
VMM_SSH_XEN_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen
VMM_SSH_XEN_KVM_POLL:$VAR_LOCATION/remotes/vmm/kvm/poll
VMM_SSH_XEN_KVM_POLL:$VAR_LOCATION/remotes/vmm/xen/poll
VMM_SSH_GANGLIA_POLL:$VAR_LOCATION/remotes/vmm/kvm/poll_local
VMM_SSH_GANGLIA_POLL:$VAR_LOCATION/remotes/vmm/xen/poll_local
VMM_EXEC_KVM_SCRIPTS:$VAR_LOCATION/remotes/vmm/kvm
VMM_EXEC_XEN_SCRIPTS:$VAR_LOCATION/remotes/vmm/xen
VMM_EXEC_XEN_KVM_POLL:$VAR_LOCATION/remotes/vmm/kvm/poll
VMM_EXEC_XEN_KVM_POLL:$VAR_LOCATION/remotes/vmm/xen/poll
VMM_EXEC_GANGLIA_POLL:$VAR_LOCATION/remotes/vmm/kvm/poll_local
VMM_EXEC_GANGLIA_POLL:$VAR_LOCATION/remotes/vmm/xen/poll_local
NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs
SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh
DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy
@ -321,8 +320,7 @@ INSTALL_SUNSTONE_FILES=(
INSTALL_ETC_FILES=(
ETC_FILES:$ETC_LOCATION
VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2
VMM_SSH_ETC_FILES:$ETC_LOCATION/vmm_ssh
VMM_SH_ETC_FILES:$ETC_LOCATION/vmm_sh
VMM_EXEC_ETC_FILES:$ETC_LOCATION/vmm_exec
IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2
TM_NFS_ETC_FILES:$ETC_LOCATION/tm_nfs
TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh
@ -414,18 +412,18 @@ MAD_RUBY_LIB_FILES="src/mad/ruby/scripts_common.rb"
MADS_LIB_FILES="src/mad/sh/madcommon.sh \
src/tm_mad/tm_common.sh \
src/vmm_mad/ssh/one_vmm_ssh.rb \
src/vmm_mad/ssh/one_vmm_ssh \
src/vmm_mad/sh/one_vmm_sh.rb \
src/vmm_mad/sh/one_vmm_sh \
src/vmm_mad/exec/one_vmm_exec.rb \
src/vmm_mad/exec/one_vmm_exec \
src/vmm_mad/exec/one_vmm_sh \
src/vmm_mad/exec/one_vmm_ssh \
src/vmm_mad/ec2/one_vmm_ec2.rb \
src/vmm_mad/ec2/one_vmm_ec2 \
src/vmm_mad/dummy/one_vmm_dummy.rb \
src/vmm_mad/dummy/one_vmm_dummy \
src/im_mad/im_ssh/one_im_ssh.rb \
src/im_mad/im_ssh/one_im_ssh \
src/im_mad/im_sh/one_im_sh.rb \
src/im_mad/im_sh/one_im_sh \
src/im_mad/im_exec/one_im_exec.rb \
src/im_mad/im_exec/one_im_exec \
src/im_mad/im_exec/one_im_ssh \
src/im_mad/im_exec/one_im_sh \
src/im_mad/ec2/one_im_ec2.rb \
src/im_mad/ec2/one_im_ec2 \
src/im_mad/dummy/one_im_dummy.rb \
@ -443,7 +441,7 @@ MADS_LIB_FILES="src/mad/sh/madcommon.sh \
# VMM SH Driver KVM scripts, to be installed under $REMOTES_LOCATION/vmm/kvm
#-------------------------------------------------------------------------------
VMM_SSH_KVM_SCRIPTS="src/vmm_mad/remotes/kvm/cancel \
VMM_EXEC_KVM_SCRIPTS="src/vmm_mad/remotes/kvm/cancel \
src/vmm_mad/remotes/kvm/deploy \
src/vmm_mad/remotes/kvm/kvmrc \
src/vmm_mad/remotes/kvm/migrate \
@ -455,7 +453,7 @@ VMM_SSH_KVM_SCRIPTS="src/vmm_mad/remotes/kvm/cancel \
# VMM SH Driver Xen scripts, to be installed under $REMOTES_LOCATION/vmm/xen
#-------------------------------------------------------------------------------
VMM_SSH_XEN_SCRIPTS="src/vmm_mad/remotes/xen/cancel \
VMM_EXEC_XEN_SCRIPTS="src/vmm_mad/remotes/xen/cancel \
src/vmm_mad/remotes/xen/deploy \
src/vmm_mad/remotes/xen/xenrc \
src/vmm_mad/remotes/xen/migrate \
@ -467,8 +465,8 @@ VMM_SSH_XEN_SCRIPTS="src/vmm_mad/remotes/xen/cancel \
# VMM SH Driver xen/kvm scripts, to be installed under $REMOTES_LOCATION/vmm/*
#-----------------------------------------------------------------------------
VMM_SSH_XEN_KVM_POLL="src/vmm_mad/remotes/poll_xen_kvm.rb"
VMM_SSH_GANGLIA_POLL="src/vmm_mad/remotes/poll_ganglia.rb"
VMM_EXEC_XEN_KVM_POLL="src/vmm_mad/remotes/poll_xen_kvm.rb"
VMM_EXEC_GANGLIA_POLL="src/vmm_mad/remotes/poll_ganglia.rb"
#-------------------------------------------------------------------------------
# Information Manager Probes, to be installed under $LIB_LOCATION/remotes
@ -548,18 +546,15 @@ ETC_FILES="share/etc/oned.conf \
#-------------------------------------------------------------------------------
# Virtualization drivers config. files, to be installed under $ETC_LOCATION
# - ec2, $ETC_LOCATION/vmm_ec2
# - sh, $ETC_LOCATION/vmm_sh
# - ssh, $ETC_LOCATION/vmm_ssh
# - ssh, $ETC_LOCATION/vmm_exec
#-------------------------------------------------------------------------------
VMM_EC2_ETC_FILES="src/vmm_mad/ec2/vmm_ec2rc \
src/vmm_mad/ec2/vmm_ec2.conf"
VMM_SSH_ETC_FILES="src/vmm_mad/ssh/vmm_sshrc \
src/vmm_mad/ssh/vmm_ssh_kvm.conf \
src/vmm_mad/ssh/vmm_ssh_xen.conf"
VMM_SH_ETC_FILES="src/vmm_mad/sh/vmm_shrc"
VMM_EXEC_ETC_FILES="src/vmm_mad/exec/vmm_execrc \
src/vmm_mad/exec/vmm_exec_kvm.conf \
src/vmm_mad/exec/vmm_exec_xen.conf"
#-------------------------------------------------------------------------------
# Information drivers config. files, to be installed under $ETC_LOCATION

View File

@ -188,9 +188,9 @@ IM_MAD = [
#-------------------------------------------------------------------------------
VM_MAD = [
name = "vmm_kvm",
executable = "one_vmm_ssh",
executable = "one_vmm_exec",
arguments = "-t 15 -r 0 kvm",
default = "vmm_ssh/vmm_ssh_kvm.conf",
default = "vmm_exec/vmm_exec_kvm.conf",
type = "kvm" ]
#-------------------------------------------------------------------------------
@ -203,9 +203,9 @@ VM_MAD = [
#-------------------------------------------------------------------------------
#VM_MAD = [
# name = "vmm_xen",
# executable = "one_vmm_ssh",
# executable = "one_vmm_exec",
# arguments = "xen",
# default = "vmm_ssh/vmm_ssh_xen.conf",
# default = "vmm_exec/vmm_exec_xen.conf",
# type = "xen" ]
#-------------------------------------------------------------------------------

View File

@ -40,7 +40,10 @@ require 'ssh_auth'
class AuthorizationManager < OpenNebulaDriver
def initialize
super(15, true)
super(
:concurrency => 15,
:threaded => true
)
config_data=File.read(ETC_LOCATION+'/auth/auth.conf')
STDERR.puts(config_data)

View File

@ -31,8 +31,14 @@ $: << RUBY_LIB_LOCATION
require 'OpenNebulaDriver'
class HookManagerDriver < OpenNebulaDriver
def initialize(num)
super(num, true, 0)
def initialize(options)
@options={
:concurrency => 15,
:threaded => true,
:retries => 0
}.merge!(options)
super('', @options)
register_action(:EXECUTE, method("action_execute"))
end
@ -57,5 +63,5 @@ class HookManagerDriver < OpenNebulaDriver
end
end
hm=HookManagerDriver.new(15)
hm=HookManagerDriver.new(:concurrency => 15)
hm.start_driver

View File

@ -31,24 +31,22 @@ $: << RUBY_LIB_LOCATION
require 'OpenNebulaDriver'
require 'CommandManager'
#-------------------------------------------------------------------------------
# The SSH Information Manager Driver
#-------------------------------------------------------------------------------
class DummyInformationManager < OpenNebulaDriver
#---------------------------------------------------------------------------
# Init the driver
#---------------------------------------------------------------------------
def initialize(num)
super(num, true)
super('',
:concurrency => num,
:threaded => true
)
# register actions
register_action(:MONITOR, method("action_monitor"))
end
#---------------------------------------------------------------------------
# Execute the sensor array in the remote host
#---------------------------------------------------------------------------
def action_monitor(number, host, not_used)
results = "HYPERVISOR=dummy,"
results << "HOSTNAME=#{host},"
@ -67,11 +65,9 @@ class DummyInformationManager < OpenNebulaDriver
end
end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Information Manager main program
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
im = DummyInformationManager.new(15)
im.start_driver

View File

@ -29,16 +29,15 @@ $: << RUBY_LIB_LOCATION
require 'pp'
require 'OpenNebulaDriver'
#-------------------------------------------------------------------------------
# The EC2 Information Manager Driver
#-------------------------------------------------------------------------------
class EC2InformationManagerDriver < OpenNebulaDriver
#---------------------------------------------------------------------------
# Init the driver, and compute the predefined maximum capacity for this
# EC2 cloud
#---------------------------------------------------------------------------
def initialize()
super(1,false)
super('',
:concurrency => 1,
:threaded => false
)
register_action(:MONITOR, method("action_monitor"))
@ -58,22 +57,18 @@ class EC2InformationManagerDriver < OpenNebulaDriver
totalmemory = smem + lmem + xlmem
totalcpu = scpu + lcpu + xlcpu
@info ="HYPERVISOR=ec2,TOTALMEMORY=#{totalmemory},TOTALCPU=#{totalcpu}," \
"CPUSPEED=1000,FREEMEMORY=#{totalmemory},FREECPU=#{totalcpu}"
@info="HYPERVISOR=ec2,TOTALMEMORY=#{totalmemory},"<<
"TOTALCPU=#{totalcpu},CPUSPEED=1000,FREEMEMORY=#{totalmemory},"<<
"FREECPU=#{totalcpu}"
end
#---------------------------------------------------------------------------
# The monitor action, just print the capacity info and hostname
#---------------------------------------------------------------------------
def action_monitor(num,host,not_used)
send_message("MONITOR",RESULT[:success],num,"HOSTNAME=#{host},#{@info}")
def action_monitor(num, host, not_used)
send_message("MONITOR", RESULT[:success], num,
"HOSTNAME=#{host},#{@info}")
end
end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# The EC2 Information Driver main program
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
im = EC2InformationManagerDriver.new
im.start_driver

View File

@ -33,64 +33,79 @@ $: << RUBY_LIB_LOCATION
require 'OpenNebulaDriver'
require 'getoptlong'
#-------------------------------------------------------------------------------
# The Local Information Manager Driver
#-------------------------------------------------------------------------------
class InformationManagerDriverSH < OpenNebulaDriver
#---------------------------------------------------------------------------
# The SSH Information Manager Driver
class InformationManagerDriver < OpenNebulaDriver
# Init the driver
#---------------------------------------------------------------------------
def initialize(hypervisor, num)
super(num, true, 0)
def initialize(hypervisor, options)
@options={
:threaded => true
}.merge!(options)
super('im', @options)
@config = read_configuration
@hypervisor = hypervisor
@cmd_path = "#{REMOTES_LOCATION}/im"
# register actions
register_action(:MONITOR, method("action_monitor"))
end
#---------------------------------------------------------------------------
# Execute the run_probes in the remote host
#---------------------------------------------------------------------------
def action_monitor(number, host, unused)
cmd_string = "#{@cmd_path}/run_probes #{@hypervisor} #{host}"
def action_monitor(number, host, do_update)
if !action_is_local?(:monitor)
if do_update == "1"
# Use SCP to sync:
sync_cmd = "scp -r #{@local_scripts_base_path}/. " \
"#{host}:#{@remote_scripts_base_path}"
local_action(cmd_string, number, "MONITOR")
# Use rsync to sync:
# sync_cmd = "rsync -Laz #{REMOTES_LOCATION}
# #{host}:#{@remote_dir}"
LocalCommand.run(sync_cmd, log_method(number))
end
end
do_action("#{@hypervisor}", number, host, :monitor,
:script_name => 'run_probes')
end
end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# IM Driver main program
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Information Manager main program
opts = GetoptLong.new(
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ]
[ '--retries', '-r', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--local', '-l', GetoptLong::NO_ARGUMENT ]
)
hypervisor = ''
threads = 15
hypervisor = ''
retries = 0
threads = 15
local_actions = {}
begin
opts.each do |opt, arg|
case opt
when '--retries'
retries = arg.to_i
when '--threads'
threads = arg.to_i
when '--local'
local_actions={ 'MONITOR' => nil }
end
end
rescue Exception => e
exit(-1)
end
end
if ARGV.length >= 1
if ARGV.length >= 1
hypervisor = ARGV.shift
end
im = InformationManagerDriverSH.new(hypervisor,threads)
im = InformationManagerDriver.new(hypervisor,
:concurrency => threads,
:retries => retries,
:local_actions => local_actions)
im.start_driver

25
src/im_mad/im_exec/one_im_sh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
if [ -z "${ONE_LOCATION}" ]; then
MAD_LOCATION=/usr/lib/one/mads
else
MAD_LOCATION=$ONE_LOCATION/lib/mads
fi
exec $MAD_LOCATION/one_im_exec -l $*

View File

@ -1,3 +1,5 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
@ -14,4 +16,10 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
if [ -z "${ONE_LOCATION}" ]; then
MAD_LOCATION=/usr/lib/one/mads
else
MAD_LOCATION=$ONE_LOCATION/lib/mads
fi
exec $MAD_LOCATION/one_im_exec $*

View File

@ -1,108 +0,0 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
ETC_LOCATION="/etc/one/"
REMOTES_LOCATION="/var/lib/one/remotes"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
ETC_LOCATION=ONE_LOCATION+"/etc/"
REMOTES_LOCATION=ONE_LOCATION+"/var/remotes/"
end
$: << RUBY_LIB_LOCATION
require 'OpenNebulaDriver'
require 'getoptlong'
#-------------------------------------------------------------------------------
# The SSH Information Manager Driver
#-------------------------------------------------------------------------------
class InformationManagerDriverSSH < OpenNebulaDriver
#---------------------------------------------------------------------------
# Init the driver
#---------------------------------------------------------------------------
def initialize(hypervisor, threads, retries)
super(threads, true, retries)
@config = read_configuration
@hypervisor = hypervisor
@remote_dir = @config['SCRIPTS_REMOTE_DIR']
# register actions
register_action(:MONITOR, method("action_monitor"))
end
#---------------------------------------------------------------------------
# Execute the run_probes in the remote host
#---------------------------------------------------------------------------
def action_monitor(number, host, do_update)
if do_update == "1"
# Use SCP to sync:
sync_cmd = "scp -r #{REMOTES_LOCATION}/. #{host}:#{@remote_dir}"
# Use rsync to sync:
# sync_cmd = "rsync -Laz #{REMOTES_LOCATION} #{host}:#{@remote_dir}"
LocalCommand.run(sync_cmd, log_method(number))
end
cmd_string = "#{@remote_dir}/im/run_probes #{@hypervisor} #{host}"
remotes_action(cmd_string, number, host, "MONITOR", @remote_dir)
end
end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Information Manager main program
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
opts = GetoptLong.new(
[ '--retries', '-r', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ]
)
hypervisor = ''
retries = 0
threads = 15
begin
opts.each do |opt, arg|
case opt
when '--retries'
retries = arg.to_i
when '--threads'
threads = arg.to_i
end
end
rescue Exception => e
exit(-1)
end
if ARGV.length >= 1
hypervisor = ARGV.shift
end
im = InformationManagerDriverSSH.new(hypervisor, threads, retries)
im.start_driver

View File

@ -33,7 +33,9 @@ GANGLIA_PORT=8649
#GANGLIA_FILE='data.xml'
host=ARGV[1]
hypervisor=ARGV[0]
host_id=ARGV[1]
host=ARGV[2]
# Gets monitoring data from ganglia or file
begin

View File

@ -15,9 +15,9 @@
# limitations under the License. */
# -------------------------------------------------------------------------- */
# ----------------------------------------------------------------------------
# Set up the environment for the driver
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Set up the environment for the driver
# ----------------------------------------------------------------------------
ONE_LOCATION = ENV["ONE_LOCATION"]
@ -35,14 +35,12 @@ require "OpenNebulaDriver"
require 'getoptlong'
# This class provides basic messaging and logging functionality
# to implement Image Repository Drivers. A image repository driver
# to implement Image Repository Drivers. A image repository driver
# is a program (or a set of) that specialize the OpenNebula behavior
# by interfacing with specific infrastructure storage solutions.
class ImageDriver < OpenNebulaDriver
# -------------------------------------------------------------------------
# Image Driver Protocol constants
# -------------------------------------------------------------------------
ACTION = {
:mv => "MV",
:cp => "CP",
@ -51,11 +49,15 @@ class ImageDriver < OpenNebulaDriver
:log => "LOG"
}
# -------------------------------------------------------------------------
# Register default actions for the protocol
# -------------------------------------------------------------------------
def initialize(fs_type, concurrency=10, threaded=true)
super(concurrency,threaded,0)
def initialize(fs_type, options={})
@options={
:concurrency => 10,
:threaded => true,
:retries => 0
}.merge!(options)
super('', @options)
@actions_path = "#{VAR_LOCATION}/remotes/image/#{fs_type}"
@ -65,9 +67,7 @@ class ImageDriver < OpenNebulaDriver
register_action(ACTION[:mkfs].to_sym, method("mkfs"))
end
# -------------------------------------------------------------------------
# Image Manager Protocol Actions (generic implementation
# -------------------------------------------------------------------------
def mv(id, src, dst)
local_action("#{@actions_path}/mv #{src} #{dst} #{id}",id,ACTION[:mv])
end
@ -85,9 +85,9 @@ class ImageDriver < OpenNebulaDriver
end
end
# ---------------------------------------------------------------------------- #
# ImageDriver Main program
# ---------------------------------------------------------------------------- #
opts = GetoptLong.new(
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ]
)
@ -104,13 +104,13 @@ begin
end
rescue Exception => e
exit(-1)
end
end
if ARGV.length >= 1
if ARGV.length >= 1
fs_type = ARGV.shift
else
exit(-1)
end
image_driver = ImageDriver.new(fs_type, threads)
image_driver = ImageDriver.new(fs_type, :concurrency => threads)
image_driver.start_driver

View File

@ -177,40 +177,6 @@ class ActionManager
private
def read_configuration
one_config=nil
if ENV['ONE_LOCATION']
one_config=ENV['ONE_LOCATION']+'/var/config'
else
one_config='/var/lib/one/config'
end
config=Hash.new
cfg=''
begin
open(one_config) do |file|
cfg=file.read
end
cfg.split(/\n/).each do |line|
m=line.match(/^([^=]+)=(.*)$/)
if m
name=m[1].strip.upcase
value=m[2].strip
config[name]=value
end
end
rescue Exception => e
STDERR.puts "Error reading config: #{e.inspect}"
STDERR.flush
end
config
end
def delete_running_action(action_id)
@action_running.delete(action_id)
end

View File

@ -180,14 +180,14 @@ class RemotesCommand < SSHCommand
cmd = self.new(cmd_string, host, logger, stdin)
cmd.run
if cmd.code == MAGIC_RC
cmd.update_remotes(host, remote_dir, logger)
@command = command
cmd.run
end
while cmd.code != 0 and retries != 0
if cmd.code == MAGIC_RC
cmd.update_remotes(host, remote_dir, logger)
@command = command
cmd.run
end
sleep 1
cmd.run
retries = retries - 1

View File

@ -1,17 +1,18 @@
# -------------------------------------------------------------------------- */
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# Licensed under the Apache License, Version 2.0 (the "License"); you may */
# not use this file except in compliance with the License. You may obtain */
# a copy of the License at */
# */
# http://www.apache.org/licenses/LICENSE-2.0 */
# */
# Unless required by applicable law or agreed to in writing, software */
# distributed under the License is distributed on an "AS IS" BASIS, */
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
# See the License for the specific language governing permissions and */
# limitations under the License. */
# -------------------------------------------------------------------------- */
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require "ActionManager"
require "CommandManager"
@ -27,27 +28,96 @@ require "CommandManager"
#
# A Driver inherits this class and only has to provide methods
# for each action it wants to receive. The method must be associated
# with the action name through the register_action func
# with the action name through the register_action function
class OpenNebulaDriver < ActionManager
# @return [String] Base path for scripts
attr_reader :local_scripts_base_path, :remote_scripts_base_path
# @return [String] Path for scripts
attr_reader :local_scripts_path, :remote_scripts_path
# 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}
#
# @param [String] str imput string to parse
# @return [Hash] parsed actions
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
# Action result strings for messages
RESULT = {
:success => "SUCCESS",
:failure => "FAILURE"
}
def initialize(concurrency=10, threaded=true, retries=0)
super(concurrency,threaded)
# Initialize OpenNebulaDriver object
#
# @param [String] directory path inside the remotes directory where the
# scripts are located
# @param [Hash] options named options to change the object's behaviour
# @option options [Number] :concurrency (10) max number of threads
# @option options [Boolean] :threaded (true) enables or disables threads
# @option options [Number] :retries (0) number of retries to copy scripts
# to the remote host
# @option options [Hash] :local_actions ({}) hash with the actions
# executed locally and the name of the script if it differs from the
# default one. This hash can be constructed using {parse_actions_list}
def initialize(directory, options={})
@options={
:concurrency => 10,
:threaded => true,
:retries => 0,
:local_actions => {}
}.merge!(options)
@retries = retries
super(@options[:concurrency], @options[:threaded])
@retries = @options[:retries]
@send_mutex=Mutex.new
@local_actions=@options[:local_actions]
# set default values
@config = read_configuration
@remote_scripts_base_path=@config['SCRIPTS_REMOTE_DIR']
if ENV['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
# -------------------------------------------------------------------------
# Sends a message to the OpenNebula core through stdout
# -------------------------------------------------------------------------
def send_message(action="-", result=RESULT[:failure], id="-", info="-")
@send_mutex.synchronize {
STDOUT.puts "#{action} #{result} #{id} #{info}"
@ -55,11 +125,86 @@ class OpenNebulaDriver < ActionManager
}
end
# -------------------------------------------------------------------------
# Execute a command associated to an action and id in a remote host.
# -------------------------------------------------------------------------
def remotes_action(command, id, host, aname, remote_dir, std_in=nil)
# Calls remotes or local action checking the action name and
# @local_actions. Optional arguments can be specified as a hash
#
# @param [String] parameters arguments passed to the script
# @param [Number, String] id action identifier
# @param [String] host hostname where the action is going to be executed
# @param [String, Symbol] aname name of the action
# @param [Hash] ops extra options for the command
# @option ops [String] :stdin text to be writen to stdin
# @option ops [String] :script_name default script name for the action,
# action name is used by defaults
def do_action(parameters, id, host, aname, ops={})
options={
:stdin => nil,
:script_name => nil
}.merge(ops)
params=parameters+" #{id} #{host}"
command=action_command_line(aname, params, options[:script_name])
if action_is_local? aname
local_action(command, id, aname)
else
remotes_action(command, id, host, aname, @remote_scripts_path,
options[:stdin])
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.
#
# @param [String, Symbol] action name of the action
# @param [String] parameters arguments for the script
# @param [String, nil] default_name alternative name for the script
# @return [String] command line needed to execute the action
def action_command_line(action, parameters, default_name=nil)
if action_is_local? action
script_path=@local_scripts_path
else
script_path=@remote_scripts_path
end
File.join(script_path, action_script_name(action, default_name))+
" "+parameters
end
# True if the action is meant to be executed locally
#
# @param [String, Symbol] action name of the action
def action_is_local?(action)
@local_actions.include? action.to_s.upcase
end
# Name of the script file for the given action
#
# @param [String, Symbol] action name of the action
# @param [String, nil] default_name alternative name for the script
def action_script_name(action, default_name=nil)
name=@local_actions[action.to_s.upcase]
if name
name
else
default_name || action.to_s.downcase
end
end
# Execute a command associated to an action and id in a remote host.
#
# @param [String] command command line to execute the script
# @param [Number, String] id action identifier
# @param [String] host hostname where the action is going to be executed
# @param [String, Symbol] aname name of the action
# @param [String] remote_dir path where the remotes reside
# @param [String, nil] std_in input of the string from the STDIN
def remotes_action(command, id, host, aname, remote_dir, std_in=nil)
command_exe = RemotesCommand.run(command,
host,
remote_dir,
@ -79,9 +224,11 @@ class OpenNebulaDriver < ActionManager
send_message(aname,result,id,info)
end
# -------------------------------------------------------------------------
# Execute a command associated to an action and id on localhost
# -------------------------------------------------------------------------
#
# @param [String] command command line to execute the script
# @param [Number, String] id action identifier
# @param [String, Symbol] aname name of the action
def local_action(command, id, aname)
command_exe = LocalCommand.run(command, log_method(id))
@ -98,10 +245,8 @@ class OpenNebulaDriver < ActionManager
send_message(aname,result,id,info)
end
# -------------------------------------------------------------------------
# Sends a log message to ONE. The +message+ can be multiline, it will
# be automatically splitted by lines.
# -------------------------------------------------------------------------
def log(number, message)
in_error_message=false
msg=message.strip
@ -138,20 +283,16 @@ class OpenNebulaDriver < ActionManager
}
end
# -------------------------------------------------------------------------
# Generates a proc with that calls log with a hardcoded number. It will
# be used to add loging to command actions
# -------------------------------------------------------------------------
def log_method(num)
lambda {|message|
log(num, message)
}
end
# -------------------------------------------------------------------------
# Start the driver. Reads from STDIN and executes methods associated with
# the messages
# -------------------------------------------------------------------------
def start_driver
loop_thread = Thread.new { loop }
start_listener
@ -190,12 +331,45 @@ private
end
end
end
def read_configuration
one_config=nil
if ENV['ONE_LOCATION']
one_config=ENV['ONE_LOCATION']+'/var/config'
else
one_config='/var/lib/one/config'
end
config=Hash.new
cfg=''
begin
open(one_config) do |file|
cfg=file.read
end
cfg.split(/\n/).each do |line|
m=line.match(/^([^=]+)=(.*)$/)
if m
name=m[1].strip.upcase
value=m[2].strip
config[name]=value
end
end
rescue Exception => e
STDERR.puts "Error reading config: #{e.inspect}"
STDERR.flush
end
config
end
end
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
################################################################
################################################################
if __FILE__ == $0
class SampleDriver < OpenNebulaDriver

View File

@ -1,22 +1,23 @@
# -------------------------------------------------------------------------- */
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# Licensed under the Apache License, Version 2.0 (the "License"); you may */
# not use this file except in compliance with the License. You may obtain */
# a copy of the License at */
# */
# http://www.apache.org/licenses/LICENSE-2.0 */
# */
# Unless required by applicable law or agreed to in writing, software */
# distributed under the License is distributed on an "AS IS" BASIS, */
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
# See the License for the specific language governing permissions and */
# limitations under the License. */
# -------------------------------------------------------------------------- */
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require "OpenNebulaDriver"
require "CommandManager"
# Author:: dsa-research.org
# Copyright:: (c) 2009 Universidad Computense de Madrid
# Copyright:: (c) 2011 Universidad Computense de Madrid
# License:: Apache License
# This class provides basic messaging and logging functionality
@ -26,13 +27,10 @@ require "CommandManager"
#
# A Driver inherits this class and only has to provide methods
# for each action it wants to receive. The method must be associated
# with the action name through the register_action func
# with the action name through the register_action function
class VirtualMachineDriver < OpenNebulaDriver
# -------------------------------------------------------------------------
# Virtual Machine Driver Protocol constants
# -------------------------------------------------------------------------
ACTION = {
:deploy => "DEPLOY",
:shutdown => "SHUTDOWN",
@ -62,29 +60,34 @@ class VirtualMachineDriver < OpenNebulaDriver
HOST_ARG = 1
# -------------------------------------------------------------------------
# Register default actions for the protocol
# -------------------------------------------------------------------------
def initialize(concurrency=10, threaded=true, retries=0)
super(concurrency,threaded,retries)
# Register default actions for the protocol.
#
# @param [String] directory path inside remotes path where the scripts
# reside
# @param [Hash] options options for OpenNebula driver (check the available
# options in {OpenNebulaDriver#initialize})
# @option options [Boolean] :threaded (true) enables or disables threads
def initialize(directory, options={})
@options={
:threaded => true
}.merge!(options)
super(directory, @options)
@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
# -------------------------------------------------------------------------
# Converts a deployment file from its remote path to the local (front-end)
# path
# -------------------------------------------------------------------------
def get_local_deployment_file(rfile)
lfile = nil
one_location = ENV["ONE_LOCATION"]
@ -104,23 +107,17 @@ class VirtualMachineDriver < OpenNebulaDriver
return lfile
end
# -------------------------------------------------------------------------
# Execute a command associated to an action and id in a remote host.
# -------------------------------------------------------------------------
def remotes_action(command, id, host, action, remote_dir, std_in=nil)
super(command,id,host,ACTION[action],remote_dir,std_in)
end
# -------------------------------------------------------------------------
# Execute a command associated to an action and id on localhost
# -------------------------------------------------------------------------
def local_action(command, id, action)
super(command,id,ACTION[action])
end
# -------------------------------------------------------------------------
# Virtual Machine Manager Protocol Actions (generic implementation
# -------------------------------------------------------------------------
# Virtual Machine Manager Protocol Actions (generic implementation)
def deploy(id, host, remote_dfile, not_used)
error = "Action not implemented by driver #{self.class}"
send_message(ACTION[:deploy],RESULT[:failure],id,error)
@ -157,9 +154,7 @@ class VirtualMachineDriver < OpenNebulaDriver
end
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]
if action
@ -207,55 +202,54 @@ private
end
end
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
################################################################
################################################################
if __FILE__ == $0
class TemplateDriver < VirtualMachineDriver
def initialize
super(15,true)
end
class TemplateDriver < VirtualMachineDriver
def initialize
super('vmm/dummy',
:concurrency => 15,
:threaded => true)
end
def deploy(id, host, remote_dfile, not_used)
#MUST return deploy_id if deployment was successfull
deploy_id = "-"
send_message(ACTION[:deploy],RESULT[:success],id,deploy_id)
end
def deploy(id, host, remote_dfile, not_used)
#MUST return deploy_id if deployment was successfull
deploy_id = "-"
send_message(ACTION[:deploy],RESULT[:success],id,deploy_id)
end
def shutdown(id, host, deploy_id, not_used)
send_message(ACTION[:shutdown],RESULT[:success],id)
end
def shutdown(id, host, deploy_id, not_used)
send_message(ACTION[:shutdown],RESULT[:success],id)
end
def cancel(id, host, deploy_id, not_used)
send_message(ACTION[:cancel],RESULT[:success],id)
end
def cancel(id, host, deploy_id, not_used)
send_message(ACTION[:cancel],RESULT[:success],id)
end
def save(id, host, deploy_id, file)
send_message(ACTION[:save],RESULT[:success],id)
end
def save(id, host, deploy_id, file)
send_message(ACTION[:save],RESULT[:success],id)
end
def restore(id, host, deploy_id , file)
send_message(ACTION[:restore],RESULT[:success],id)
end
def restore(id, host, deploy_id , file)
send_message(ACTION[:restore],RESULT[:success],id)
end
def migrate(id, host, deploy_id, dest_host)
send_message(ACTION[:migrate],RESULT[:success],id)
end
def migrate(id, host, deploy_id, dest_host)
send_message(ACTION[:migrate],RESULT[:success],id)
end
def poll(id, host, deploy_id, not_used)
# monitor_info: string in the form "VAR=VAL VAR=VAL ... VAR=VAL"
# known VAR are in POLL_ATTRIBUTES. VM states VM_STATES
monitor_info = "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]} " \
"#{POLL_ATTRIBUTE[:nettx]}=12345"
send_message(ACTION[:poll],RESULT[:success],id,monitor_info)
end
def poll(id, host, deploy_id, not_used)
# monitor_info: string in the form "VAR=VAL VAR=VAL ... VAR=VAL"
# known VAR are in POLL_ATTRIBUTES. VM states VM_STATES
monitor_info = "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]} " \
"#{POLL_ATTRIBUTE[:nettx]}=12345"
send_message(ACTION[:poll],RESULT[:success],id,monitor_info)
end
end
sd = TemplateDriver.new
sd.start_driver
end

View File

@ -0,0 +1,37 @@
class MonkeyPatcher
def self.patch(&block)
patcher=self.new
patcher.instance_eval &block
patcher.restore_all
end
def initialize
@objects=Hash.new
@klasses=Hash.new
end
def patch_class(klass, function, &block)
@klasses[klass]={} if !@klasses[klass]
@klasses[klass][function]=klass.instance_method(function)
klass.instance_eval do
define_method(function, block)
end
end
def restore_class(klass)
@klasses[klass].each do |function, method|
klass.instance_eval do
define_method(function, method)
end
end
end
def restore_all
@klasses.each do |klass, methods|
restore_class(klass)
end
end
end

View File

@ -0,0 +1,301 @@
require 'OpenNebulaDriver'
require 'test/MonkeyPatcher'
def create_driver(concurrecy, threaded, retries, directory, local_actions)
OpenNebulaDriver.new(directory,
:concurrency => concurrecy,
:threaded => threaded,
:retries => retries,
:local_actions => local_actions)
end
local_action_tests=[
['', {}],
['poll', {'POLL' => nil}],
['poll,migrate', {'POLL' => nil, 'MIGRATE' => nil}],
['deploy,shutdown,poll=poll_ganglia, cancel ',
{"POLL"=>"poll_ganglia", "DEPLOY"=>nil, "SHUTDOWN"=>nil,
"CANCEL"=>nil}]
]
# modify read configuration to get config file from fixtures dir
class OpenNebulaDriver
alias :read_configuration_old :read_configuration
def read_configuration
old_one_location=ENV['ONE_LOCATION']
ENV['ONE_LOCATION']=File.join(ENV['PWD'], 'test', 'fixtures')
result=read_configuration_old
ENV['ONE_LOCATION']=old_one_location
result
end
end
def fake_execution(stdout, stderr)
[StringIO.new(''), StringIO.new(stdout), StringIO.new(stderr)]
end
describe OpenNebulaDriver do
before(:all) do
@concurrecy=1
@threaded=false
@retries=0
@directory='vmm/dummy'
@local_actions={
'POLL' => 'local_poll',
'MIGRATE' => nil
}
@create_params=[@concurrecy, @threaded, @retries, @directory,
@local_actions]
end
before(:each) do
ENV['ONE_LOCATION']=nil
end
it 'should parse local actions' do
local_action_tests.each do |test|
OpenNebulaDriver.parse_actions_list(test[0]).should == test[1]
end
end
it 'should get correct paths' do
driver=create_driver(*@create_params)
driver.local_scripts_base_path.should == '/var/lib/one/remotes'
driver.local_scripts_path.should == '/var/lib/one/remotes/vmm/dummy'
driver.remote_scripts_base_path.should == '/var/tmp/one'
driver.remote_scripts_path.should == '/var/tmp/one/vmm/dummy'
ENV['ONE_LOCATION']='/one'
driver=create_driver(*@create_params)
driver.local_scripts_base_path.should == '/one/var/remotes'
driver.local_scripts_path.should == '/one/var/remotes/vmm/dummy'
driver.remote_scripts_base_path.should == '/var/tmp/one'
driver.remote_scripts_path.should == '/var/tmp/one/vmm/dummy'
end
it 'should distinguish local and remote actions' do
driver=create_driver(*@create_params)
driver.action_is_local?(:deploy).should == false
driver.action_is_local?('SHUTDOWN').should == false
driver.action_is_local?(:migrate).should == true
driver.action_is_local?('migrate').should == true
driver.action_is_local?(:MIGRATE).should == true
driver.action_is_local?('MIGRATE').should == true
end
it 'should call correct executable' do
driver=create_driver(*@create_params)
driver.action_command_line(:deploy, 'parameter').should ==
'/var/tmp/one/vmm/dummy/deploy parameter'
driver.action_command_line(:poll, 'parameter').should ==
'/var/lib/one/remotes/vmm/dummy/local_poll parameter'
driver.action_command_line(:migrate, 'parameter').should ==
'/var/lib/one/remotes/vmm/dummy/migrate parameter'
driver.action_command_line(:test, 'parameter', 'testscr').should ==
'/var/tmp/one/vmm/dummy/testscr parameter'
end
it 'should correctly send messages' do
result=""
driver=create_driver(*@create_params)
MonkeyPatcher.patch do
patch_class(IO, :puts) do |*args|
result=args
end
driver.send_message('action', 'SUCCESS', 15, 'some info')
end
result[0].should == "action SUCCESS 15 some info"
end
it 'should select remote or local execution correctly' do
local_action=[]
remotes_action=[]
driver=create_driver(*@create_params)
MonkeyPatcher.patch do
patch_class(OpenNebulaDriver, :local_action) do |*args|
local_action=args
end
patch_class(OpenNebulaDriver, :remotes_action) do |*args|
remotes_action=args
end
driver.do_action('some parameters', 15, 'localhost', :poll)
driver.do_action('some parameters', 15, 'localhost', :deploy,
:script_name => 'deploy_script')
end
local_action.should == [
"/var/lib/one/remotes/vmm/dummy/local_poll some parameters 15"<<
" localhost",
15,
:poll]
remotes_action.should == ["/var/tmp/one/vmm/dummy/deploy_script"<<
" some parameters 15 localhost",
15,
"localhost",
:deploy,
"/var/tmp/one/vmm/dummy",
nil]
end
it 'should execute remote actions' do
result=[] # here will be the parameters to send_message
time=0 # this will count the executions of SSHCommand
driver=create_driver(*@create_params)
MonkeyPatcher.patch do
# patch send_message
patch_class(IO, :puts) do |*args|
result<<args[0]
end
patch_class(LocalCommand, :execute) do
fake_execution('command info', 'ExitCode: 0')
end
patch_class(SSHCommand, :execute) do
time+=1
case time
when 1 # Everything goes ok (Test 1)
fake_execution('command info', 'ExitCode: 0')
when 2 # Command fails (Test 2)
fake_execution('command info', 'ExitCode: 255')
when 3 # File is not there (Test 3)
fake_execution('command info', 'ExitCode: 42')
when 4 # Command works after a good copy (Test 3)
fake_execution('command info', 'ExitCode: 0')
else
fake_execution('command info', 'ExitCode: 0')
end
end
# Time 1
driver.remotes_action('command', 0, 'localhost', :DEPLOY, '/')
#puts time
# Time 2
driver.remotes_action('command', 0, 'localhost', :DEPLOY, '/')
#puts time
# Time 3
driver.remotes_action('command', 0, 'localhost', :DEPLOY, '/')
#puts time
end
#pp result
result.should == [
# 1 - Everything ok
"LOG I 0 ExitCode: 0",
"DEPLOY SUCCESS 0 command info",
# 2 - Command fails
"LOG I 0 Command execution fail: 'if [ -x \"command\" ]; then command; else exit 42; fi'",
"LOG I 0 ExitCode: 255",
"DEPLOY FAILURE 0 -",
# 3 - File is not there, update files
"LOG I 0 Command execution fail: 'if [ -x \"command\" ]; then command; else exit 42; fi'",
"LOG I 0 ExitCode: 42",
"LOG I 0 Remote worker node files not found",
"LOG I 0 Updating remotes",
"LOG I 0 ExitCode: 0",
# 4 - Good command execution
"LOG I 0 ExitCode: 0",
"DEPLOY SUCCESS 0 command info"
]
end
it 'should execute local actions' do
result=[] # here will be the parameters to send_message
time=0 # this will count the executions of LocalCommand
driver=create_driver(*@create_params)
MonkeyPatcher.patch do
# patch send_message
patch_class(IO, :puts) do |*args|
result<<args[0]
end
patch_class(LocalCommand, :execute) do
time+=1
case time
when 1 # Everything goes ok (Test 1)
fake_execution('command info', 'ExitCode: 0')
when 2 # Command fails (Test 2)
fake_execution('', '
ERROR MESSAGE --8<------
the error message
ERROR MESSAGE ------>8--
ExitCode: 255')
else
puts "should not reach here"
fake_execution('command info', 'ExitCode: 0')
end
end
# Test 1 - OK
driver.local_action('command', 0, :DEPLOY)
# Test 2 - Error
driver.local_action('command', 0, :DEPLOY)
end
result.should == [
"LOG I 0 ExitCode: 0", "DEPLOY SUCCESS 0 command info",
"LOG I 0 Command execution fail: command",
"LOG E 0 the error message",
"LOG I 0 ExitCode: 255", "DEPLOY FAILURE 0 the error message"
]
end
it "should correctly parse log lines" do
tests=[
[
"ERROR MESSAGE --8<------\nerror message\n"<<
"ERROR MESSAGE ------>8--\n",
['LOG', 'E', 0, 'error message']
],
['ERROR: error message', ['LOG', 'E', 0, 'error message']],
['DEBUG: debug message', ['LOG', 'D', 0, 'debug message']],
['INFO: info message', ['LOG', 'I', 0, 'info message']],
['info message', ['LOG', 'I', 0, 'info message']]
]
driver=create_driver(*@create_params)
result=''
MonkeyPatcher.patch do
patch_class(OpenNebulaDriver, :send_message) do |*args|
result=args
end
tests.each do |test|
driver.log(0, test[0])
result.should == test[1]
end
end
end
end

20
src/mad/ruby/test/fixtures/var/config vendored Normal file
View File

@ -0,0 +1,20 @@
DB=BACKEND=sqlite
DEBUG_LEVEL=3
DEFAULT_DEVICE_PREFIX=hd
DEFAULT_IMAGE_TYPE=OS
HM_MAD=EXECUTABLE=one_hm
HOST_MONITORING_INTERVAL=600
IMAGE_MAD=ARGUMENTS=fs -t 15,EXECUTABLE=one_image
IMAGE_REPOSITORY_PATH=/Users/jfontan/tmp/borrar/git/one/install/var//images
IM_MAD=ARGUMENTS=-r 0 -t 15 kvm,EXECUTABLE=one_im_ssh,NAME=im_kvm
MAC_PREFIX=02:00
MANAGER_TIMER=15
NETWORK_SIZE=254
PORT=2633
SCRIPTS_REMOTE_DIR=/var/tmp/one
TM_MAD=ARGUMENTS=tm_nfs/tm_nfs.conf,EXECUTABLE=one_tm,NAME=tm_nfs
VM_DIR=/Users/jfontan/tmp/borrar/git/one/install/var/
VM_MAD=ARGUMENTS=-t 15 -r 0 kvm,DEFAULT=vmm_ssh/vmm_ssh_kvm.conf,EXECUTABLE=one_vmm_ssh,NAME=vmm_kvm,TYPE=kvm
VM_POLLING_INTERVAL=600
VNC_BASE_PORT=5900

View File

@ -36,33 +36,37 @@ require 'TMScript'
class TransferManager < OpenNebulaDriver
def initialize(plugin, num)
super(num, true)
def initialize(plugin, options={})
@options={
:threaded => true
}.merge!(options)
super('', @options)
@plugin=plugin
# register actions
register_action(:TRANSFER, method("action_transfer"))
end
def action_transfer(number, script_file)
script_text=""
if File.exist?(script_file)
open(script_file) {|f|
script_text=f.read
}
script=TMScript.new(script_text, log_method(number))
res=script.execute(@plugin)
if res[0]
send_message("TRANSFER", RESULT[:success], number)
else
send_message("TRANSFER", RESULT[:failure], number, res[1])
end
else
send_message("TRANSFER", RESULT[:failure], number,
send_message("TRANSFER", RESULT[:failure], number,
"Transfer file not found: #{script_file}")
end
end
@ -80,7 +84,9 @@ tm_conf=ETC_LOCATION+tm_conf if tm_conf[0] != ?/
plugin=TMPlugin.new(tm_conf)
tm=TransferManager.new(plugin, 15)
tm=TransferManager.new(plugin,
:concurrency => 15)
tm.start_driver

View File

@ -33,7 +33,10 @@ require "CommandManager"
class DummyDriver < VirtualMachineDriver
def initialize
super(15,true)
super('',
:concurrency => 15,
:threaded => true
)
end
def deploy(id, host, remote_dfile, not_used)

View File

@ -15,9 +15,7 @@
# limitations under the License. #
# ---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# Set up the environment for the driver #
# ---------------------------------------------------------------------------- #
# Set up the environment for the driver
EC2_LOCATION = ENV["EC2_HOME"]
@ -45,15 +43,10 @@ require "VirtualMachineDriver"
require "CommandManager"
require "rexml/document"
# ---------------------------------------------------------------------------- #
# The main class for the EC2 driver #
# ---------------------------------------------------------------------------- #
# The main class for the EC2 driver
class EC2Driver < VirtualMachineDriver
# ------------------------------------------------------------------------ #
# EC2 commands constants #
# ------------------------------------------------------------------------ #
# EC2 commands constants
EC2 = {
:run => "#{EC2_LOCATION}/bin/ec2-run-instances",
:terminate => "#{EC2_LOCATION}/bin/ec2-terminate-instances",
@ -62,18 +55,19 @@ class EC2Driver < VirtualMachineDriver
:authorize => "#{EC2_LOCATION}bin/ec2-authorize"
}
# ------------------------------------------------------------------------ #
# EC2 constructor, loads defaults for the EC2Driver #
# ------------------------------------------------------------------------ #
# EC2 constructor, loads defaults for the EC2Driver
def initialize(ec2_conf = nil)
if !EC2_JVM_CONCURRENCY
concurrency = 5
else
concurrency = EC2_JVM_CONCURRENCY.to_i
end
super(concurrency,true)
super(
:concurrency => concurrency,
:threaded => true
)
@defaults = Hash.new
@ -87,16 +81,14 @@ class EC2Driver < VirtualMachineDriver
ec2 = xml.root.elements["EC2"]
return if !ec2
@defaults["KEYPAIR"] = ec2_value(ec2,"KEYPAIR")
@defaults["AUTHORIZEDPORTS"] = ec2_value(ec2,"AUTHORIZEDPORTS")
@defaults["INSTANCETYPE"] = ec2_value(ec2,"INSTANCETYPE")
end
end
# ------------------------------------------------------------------------ #
# DEPLOY action, also sets ports and ip if needed #
# ------------------------------------------------------------------------ #
# DEPLOY action, also sets ports and ip if needed
def deploy(id, host, remote_dfile, not_used)
local_dfile = get_local_deployment_file(remote_dfile)
@ -110,12 +102,12 @@ class EC2Driver < VirtualMachineDriver
tmp = File.new(local_dfile)
xml = REXML::Document.new tmp
tmp.close()
ec2 = nil
all_ec2_elements = xml.root.get_elements("EC2")
# First, let's see if we have an EC2 site that matches
# First, let's see if we have an EC2 site that matches
# our desired host name
all_ec2_elements.each { |element|
cloud=element.elements["CLOUD"]
@ -125,14 +117,15 @@ class EC2Driver < VirtualMachineDriver
}
if !ec2
# If we don't find the EC2 site, and ONE just
# If we don't find the EC2 site, and ONE just
# knows about one EC2 site, let's use that
if all_ec2_elements.size == 1
ec2 = all_ec2_elements[0]
else
send_message(ACTION[:deploy],RESULT[:failure],id,
"Can not find EC2 element in deployment file #{local_dfile}" +
" or couldn't find any EC2 site matching one of the template.")
"Can not find EC2 element in deployment file "<<
"#{local_dfile} or couldn't find any EC2 site matching "<<
"one of the template.")
return
end
end
@ -181,23 +174,17 @@ class EC2Driver < VirtualMachineDriver
send_message(ACTION[:deploy],RESULT[:success],id,deploy_id)
end
# ------------------------------------------------------------------------ #
# Shutdown a EC2 instance #
# ------------------------------------------------------------------------ #
# Shutdown a EC2 instance
def shutdown(id, host, deploy_id, not_used)
ec2_terminate(ACTION[:shutdown], id, deploy_id)
end
# ------------------------------------------------------------------------ #
# Cancel a EC2 instance #
# ------------------------------------------------------------------------ #
# Cancel a EC2 instance
def cancel(id, host, deploy_id, not_used)
ec2_terminate(ACTION[:cancel], id, deploy_id)
end
# ------------------------------------------------------------------------ #
# Get info (IP, and state) for a EC2 instance #
# ------------------------------------------------------------------------ #
# Get info (IP, and state) for a EC2 instance
def poll(id, host, deploy_id, not_used)
info = "#{POLL_ATTRIBUTE[:usedmemory]}=0 " \
@ -224,8 +211,8 @@ class EC2Driver < VirtualMachineDriver
when "pending"
info << " #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]}"
when "running"
info << " #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]}" \
" IP=#{monitor_data[1]}"
info<<" #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:active]}"<<
" IP=#{monitor_data[1]}"
when "shutting-down","terminated"
info << " #{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:deleted]}"
end
@ -262,9 +249,7 @@ private
end
end
# ---------------------------------------------------------------------------- #
# EC2Driver Main program
# ---------------------------------------------------------------------------- #
ec2_conf = ARGV.last

View File

@ -16,29 +16,23 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
#Setup driver variables
DRIVER_NAME=`basename $0 | cut -d. -f1`
if [ -z "${ONE_LOCATION}" ]; then
DRIVERRC=/etc/one/${DRIVER_NAME}/${DRIVER_NAME}rc
DRIVERRC=/etc/one/vmm_exec/vmm_execrc
MADCOMMON=/usr/lib/one/mads/madcommon.sh
VAR_LOCATION=/var/lib/one
else
DRIVERRC=$ONE_LOCATION/etc/${DRIVER_NAME}/${DRIVER_NAME}rc
DRIVERRC=$ONE_LOCATION/etc/vmm_exec/vmm_execrc
MADCOMMON=$ONE_LOCATION/lib/mads/madcommon.sh
VAR_LOCATION=$ONE_LOCATION/var
fi
. $MADCOMMON
# Export the im_mad specific rc
# Export the vmm_mad specific rc
export_rc_vars $DRIVERRC
# Go to var directory ONE_LOCATION/var or /var/lib/one
# Go to ONE_LOCATION
cd $VAR_LOCATION
LOG_FILE=$DRIVER_NAME
# Execute the actual MAD
execute_mad $*

140
src/vmm_mad/exec/one_vmm_exec.rb Executable file
View File

@ -0,0 +1,140 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
# Set up the environment for the driver
ONE_LOCATION = ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
ETC_LOCATION = "/etc/one/"
else
RUBY_LIB_LOCATION = ONE_LOCATION + "/lib/ruby"
ETC_LOCATION = ONE_LOCATION + "/etc/"
end
$: << RUBY_LIB_LOCATION
require "VirtualMachineDriver"
require 'getoptlong'
# The main class for the Sh driver
class ExecDriver < VirtualMachineDriver
# SshDriver constructor
def initialize(hypervisor, options={})
@options={
:threaded => true
}.merge!(options)
super("vmm/#{hypervisor}", @options)
@hypervisor = hypervisor
end
# DEPLOY action, sends the deployment file to remote host
def deploy(id, host, remote_dfile, not_used)
local_dfile = get_local_deployment_file(remote_dfile)
if !local_dfile || File.zero?(local_dfile)
send_message(ACTION[:deploy],RESULT[:failure],id,
"Can not open deployment file #{local_dfile}")
return
end
tmp = File.new(local_dfile)
domain = tmp.read
tmp.close()
if action_is_local?(:deploy)
dfile=local_dfile
else
dfile=remote_dfile
end
do_action("#{dfile} #{host}", id, host, :deploy,
:stdin => domain)
end
# Basic Domain Management Operations
def shutdown(id, host, deploy_id, not_used)
do_action("#{deploy_id} #{host}", id, host, :shutdown)
end
def cancel(id, host, deploy_id, not_used)
do_action("#{deploy_id} #{host}", id, host, :cancel)
end
def save(id, host, deploy_id, file)
do_action("#{deploy_id} #{file} #{host}", id, host, :save)
end
def restore(id, host, deploy_id, file)
do_action("#{file} #{host}", id, host, :restore)
end
def migrate(id, host, deploy_id, dest_host)
do_action("#{deploy_id} #{dest_host} #{host}", id, host, :migrate)
end
def poll(id, host, deploy_id, not_used)
do_action("#{deploy_id} #{host}", id, host, :poll)
end
end
# SshDriver Main program
opts = GetoptLong.new(
[ '--retries', '-r', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--local', '-l', GetoptLong::REQUIRED_ARGUMENT ]
)
hypervisor = ''
retries = 0
threads = 15
local_actions = {}
begin
opts.each do |opt, arg|
case opt
when '--retries'
retries = arg.to_i
when '--threads'
threads = arg.to_i
when '--local'
local_actions=OpenNebulaDriver.parse_actions_list(arg)
end
end
rescue Exception => e
exit(-1)
end
if ARGV.length >= 1
hypervisor = ARGV.shift
else
exit(-1)
end
exec_driver = ExecDriver.new(hypervisor,
:concurrency => threads,
:retries => retries,
:local_actions => local_actions)
exec_driver.start_driver

View File

@ -17,22 +17,9 @@
#--------------------------------------------------------------------------- #
if [ -z "${ONE_LOCATION}" ]; then
DRIVERRC=/etc/one/vmm_sh/vmm_shrc
MADCOMMON=/usr/lib/one/mads/madcommon.sh
VAR_LOCATION=/var/lib/one
MAD_LOCATION=/usr/lib/one/mads
else
DRIVERRC=$ONE_LOCATION/etc/vmm_sh/vmm_shrc
MADCOMMON=$ONE_LOCATION/lib/mads/madcommon.sh
VAR_LOCATION=$ONE_LOCATION/var
MAD_LOCATION=$ONE_LOCATION/lib/mads
fi
. $MADCOMMON
# Export the vmm_mad specific rc
export_rc_vars $DRIVERRC
# Go to ONE_LOCATION
cd $VAR_LOCATION
# Execute the actual MAD
execute_mad $*
exec $MAD_LOCATION/one_vmm_exec -l deploy,shutdown,cancel,save,restore,migrate,poll $*

View File

@ -17,22 +17,9 @@
#--------------------------------------------------------------------------- #
if [ -z "${ONE_LOCATION}" ]; then
DRIVERRC=/etc/one/vmm_ssh/vmm_sshrc
MADCOMMON=/usr/lib/one/mads/madcommon.sh
VAR_LOCATION=/var/lib/one
MAD_LOCATION=/usr/lib/one/mads
else
DRIVERRC=$ONE_LOCATION/etc/vmm_ssh/vmm_sshrc
MADCOMMON=$ONE_LOCATION/lib/mads/madcommon.sh
VAR_LOCATION=$ONE_LOCATION/var
MAD_LOCATION=$ONE_LOCATION/lib/mads
fi
. $MADCOMMON
# Export the vmm_mad specific rc
export_rc_vars $DRIVERRC
# Go to ONE_LOCATION
cd $VAR_LOCATION
# Execute the actual MAD
execute_mad $*
exec $MAD_LOCATION/one_vmm_exec $*

View File

@ -49,8 +49,10 @@ GANGLIA_PORT=8649
#GANGLIA_FILE='data.xml'
host=ARGV[0]
domain=ARGV[1]
domain=ARGV[0]
dom_id=ARGV[1]
host=ARGV[2]
# Gets monitoring data from ganglia or file
begin

View File

@ -1,129 +0,0 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# Set up the environment for the driver #
# ---------------------------------------------------------------------------- #
ONE_LOCATION = ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
VAR_LOCATION = "/var/lib/one"
else
RUBY_LIB_LOCATION = ONE_LOCATION + "/lib/ruby"
VAR_LOCATION = ONE_LOCATION + "/var"
end
$: << RUBY_LIB_LOCATION
require "VirtualMachineDriver"
require 'getoptlong'
# ---------------------------------------------------------------------------- #
# The main class for the Sh driver #
# ---------------------------------------------------------------------------- #
class ShDriver < VirtualMachineDriver
# ------------------------------------------------------------------------ #
# ShDriver constructor #
# ------------------------------------------------------------------------ #
def initialize(hypervisor,threads)
super(threads,true)
@config = read_configuration
@hypervisor = hypervisor
@actions_path = "#{VAR_LOCATION}/remotes/vmm/#{hypervisor}"
end
# ------------------------------------------------------------------------ #
# DEPLOY action, sends the deployment file to remote host #
# ------------------------------------------------------------------------ #
def deploy(id, host, remote_dfile, not_used)
local_dfile = get_local_deployment_file(remote_dfile)
if !local_dfile || File.zero?(local_dfile)
send_message(ACTION[:deploy],RESULT[:failure],id,
"Can not open deployment file #{local_dfile}")
return
end
local_action("#{@actions_path}/deploy #{host} #{local_dfile}",id,:deploy)
end
# ------------------------------------------------------------------------ #
# Basic Domain Management Operations #
# ------------------------------------------------------------------------ #
def shutdown(id, host, deploy_id, not_used)
local_action("#{@actions_path}/shutdown #{host} #{deploy_id}", id,
:shutdown)
end
def cancel(id, host, deploy_id, not_used)
local_action("#{@actions_path}/cancel #{host} #{deploy_id}", id, :cancel)
end
def save(id, host, deploy_id, file)
local_action("#{@actions_path}/save #{host} #{deploy_id} #{file}", id,
:save)
end
def restore(id, host, deploy_id, file)
local_action("#{@actions_path}/restore #{host} #{file}", id, :restore)
end
def migrate(id, host, deploy_id, dest_host)
local_action(
"#{@actions_path}/migrate #{host} #{deploy_id} #{dest_host}", id,
:migrate)
end
def poll(id, host, deploy_id, not_used)
local_action("#{@actions_path}/poll #{host} #{deploy_id}",id,:poll)
end
end
# ---------------------------------------------------------------------------- #
# ShDriver Main program #
# ---------------------------------------------------------------------------- #
opts = GetoptLong.new(
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ]
)
hypervisor = ''
threads = 15
begin
opts.each do |opt, arg|
case opt
when '--threads'
threads = arg.to_i
end
end
rescue Exception => e
exit(-1)
end
if ARGV.length >= 1
hypervisor = ARGV.shift
else
exit(-1)
end
sh_driver = ShDriver.new(hypervisor,threads)
sh_driver.start_driver

View File

@ -1,160 +0,0 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------.- #
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#---------------------------------------------------------------------------- #
# ---------------------------------------------------------------------------- #
# Set up the environment for the driver #
# ---------------------------------------------------------------------------- #
ONE_LOCATION = ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION = "/usr/lib/one/ruby"
ETC_LOCATION = "/etc/one/"
else
RUBY_LIB_LOCATION = ONE_LOCATION + "/lib/ruby"
ETC_LOCATION = ONE_LOCATION + "/etc/"
end
$: << 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
@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
# ------------------------------------------------------------------------ #
# DEPLOY action, sends the deployment file to remote host #
# ------------------------------------------------------------------------ #
def deploy(id, host, remote_dfile, not_used)
local_dfile = get_local_deployment_file(remote_dfile)
if !local_dfile || File.zero?(local_dfile)
send_message(ACTION[:deploy],RESULT[:failure],id,
"Can not open deployment file #{local_dfile}")
return
end
tmp = File.new(local_dfile)
domain = tmp.read
tmp.close()
remotes_action("#{@remote_path}/deploy #{remote_dfile}",
id, host, :deploy, @remote_dir, 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)
end
def cancel(id, host, deploy_id, not_used)
remotes_action("#{@remote_path}/cancel #{deploy_id}",
id, host, :cancel, @remote_dir)
end
def save(id, host, deploy_id, file)
remotes_action("#{@remote_path}/save #{deploy_id} #{file}",
id, host, :save, @remote_dir)
end
def restore(id, host, deploy_id, file)
remotes_action("#{@remote_path}/restore #{file}",
id, host, :restore, @remote_dir)
end
def migrate(id, host, deploy_id, dest_host)
remotes_action("#{@remote_path}/migrate #{deploy_id} #{dest_host}",
id, host, :migrate, @remote_dir)
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
end
end
# ---------------------------------------------------------------------------- #
# SshDriver Main program
# ---------------------------------------------------------------------------- #
opts = GetoptLong.new(
[ '--retries', '-r', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--threads', '-t', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--localpoll', '-p', GetoptLong::REQUIRED_ARGUMENT ]
)
hypervisor = ''
retries = 0
threads = 15
localpoll = nil
begin
opts.each do |opt, arg|
case opt
when '--retries'
retries = arg.to_i
when '--threads'
threads = arg.to_i
when '--localpoll'
localpoll = arg
end
end
rescue Exception => e
exit(-1)
end
if ARGV.length >= 1
hypervisor = ARGV.shift
else
exit(-1)
end
ssh_driver = SshDriver.new(hypervisor, threads, retries, localpoll)
ssh_driver.start_driver