mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-16 17:53:08 +09:00
modified IM ssh mad according to new MONITOR protocol
This commit is contained in:
1 parent
f05fb71f13
commit
4288175ad1
11 files changed
+84
-172
No files matched your search
+33
-21
@@ -164,7 +164,11 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \
|
||||
$ETC_LOCATION/ec2query_templates \
|
||||
$ETC_LOCATION/occi_templates"
|
||||
|
||||
LIB_DIRS="$LIB_LOCATION/im_probes \
|
||||
LIB_DIRS="$LIB_LOCATION/remotes \
|
||||
$LIB_LOCATION/remotes/im \
|
||||
$LIB_LOCATION/remotes/im/common.d \
|
||||
$LIB_LOCATION/remotes/im/kvm.d \
|
||||
$LIB_LOCATION/remotes/im/xen.d \
|
||||
$LIB_LOCATION/ruby \
|
||||
$LIB_LOCATION/ruby/OpenNebula \
|
||||
$LIB_LOCATION/ruby/cloud/ \
|
||||
@@ -207,20 +211,23 @@ INSTALL_FILES[2]="LIB_FILES:$LIB_LOCATION"
|
||||
INSTALL_FILES[3]="RUBY_LIB_FILES:$LIB_LOCATION/ruby"
|
||||
INSTALL_FILES[4]="RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula"
|
||||
INSTALL_FILES[5]="MADS_LIB_FILES:$LIB_LOCATION/mads"
|
||||
INSTALL_FILES[6]="IM_PROBES_LIB_FILES:$LIB_LOCATION/im_probes"
|
||||
INSTALL_FILES[7]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs"
|
||||
INSTALL_FILES[8]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh"
|
||||
INSTALL_FILES[9]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy"
|
||||
INSTALL_FILES[10]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm"
|
||||
INSTALL_FILES[11]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples"
|
||||
INSTALL_FILES[12]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm"
|
||||
INSTALL_FILES[13]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks"
|
||||
INSTALL_FILES[14]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud"
|
||||
INSTALL_FILES[15]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe"
|
||||
INSTALL_FILES[16]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views"
|
||||
INSTALL_FILES[17]="ECO_BIN_FILES:$BIN_LOCATION"
|
||||
INSTALL_FILES[18]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi"
|
||||
INSTALL_FILES[19]="OCCI_BIN_FILES:$BIN_LOCATION"
|
||||
INSTALL_FILES[6]="IM_PROBES_FILES:$LIB_LOCATION/remotes/im"
|
||||
INSTALL_FILES[7]="IM_PROBES_COMMON_FILES:$LIB_LOCATION/remotes/im/common.d"
|
||||
INSTALL_FILES[8]="IM_PROBES_KVM_FILES:$LIB_LOCATION/remotes/im/kvm.d"
|
||||
INSTALL_FILES[9]="IM_PROBES_XEN_FILES:$LIB_LOCATION/remotes/im/xen.d"
|
||||
INSTALL_FILES[10]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs"
|
||||
INSTALL_FILES[11]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh"
|
||||
INSTALL_FILES[12]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy"
|
||||
INSTALL_FILES[13]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm"
|
||||
INSTALL_FILES[14]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples"
|
||||
INSTALL_FILES[15]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm"
|
||||
INSTALL_FILES[16]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks"
|
||||
INSTALL_FILES[17]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud"
|
||||
INSTALL_FILES[18]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe"
|
||||
INSTALL_FILES[19]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views"
|
||||
INSTALL_FILES[20]="ECO_BIN_FILES:$BIN_LOCATION"
|
||||
INSTALL_FILES[21]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi"
|
||||
INSTALL_FILES[22]="OCCI_BIN_FILES:$BIN_LOCATION"
|
||||
|
||||
INSTALL_ECO_CLIENT_FILES[0]="COMMON_CLOUD_CLIENT_LIB_FILES:$LIB_LOCATION/ruby/cloud"
|
||||
INSTALL_ECO_CLIENT_FILES[1]="ECO_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/econe"
|
||||
@@ -338,14 +345,19 @@ MADS_LIB_FILES="src/mad/sh/madcommon.sh \
|
||||
src/authm_mad/one_auth_mad"
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Information Manager Probes, to be installed under $LIB_LOCATION/im_probes
|
||||
# Information Manager Probes, to be installed under $LIB_LOCATION/remotes
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
IM_PROBES_LIB_FILES="src/im_mad/xen/xen.rb \
|
||||
src/im_mad/kvm/kvm.rb \
|
||||
src/im_mad/host_probes/architecture.sh \
|
||||
src/im_mad/host_probes/cpu.sh \
|
||||
src/im_mad/host_probes/name.sh"
|
||||
IM_PROBES_FILES="share/scripts/im/run_probes"
|
||||
|
||||
IM_PROBES_COMMON_FILES="share/scripts/im/common.d/architecture.sh \
|
||||
share/scripts/im/common.d/cpu.sh \
|
||||
share/scripts/im/common.d/name.sh"
|
||||
|
||||
IM_PROBES_XEN_FILES="share/scripts/im/xen.d/xen.rb"
|
||||
|
||||
IM_PROBES_KVM_FILES="share/scripts/im/kvm.d/kvm.rb"
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Transfer Manager commands, to be installed under $LIB_LOCATION/tm_commands
|
||||
|
||||
+2
-2
@@ -106,7 +106,7 @@ DEFAULT_DEVICE_PREFIX = "hd"
|
||||
#IM_MAD = [
|
||||
# name = "im_xen",
|
||||
# executable = "one_im_ssh",
|
||||
# arguments = "im_xen/im_xen.conf" ]
|
||||
# arguments = "xen" ]
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# KVM Information Driver Manager sample configuration
|
||||
@@ -114,7 +114,7 @@ DEFAULT_DEVICE_PREFIX = "hd"
|
||||
IM_MAD = [
|
||||
name = "im_kvm",
|
||||
executable = "one_im_ssh",
|
||||
arguments = "im_kvm/im_kvm.conf" ]
|
||||
arguments = "kvm" ]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
HYPERVISOR_DIR=$1.d
|
||||
|
||||
SCRIPTS_DIR=`dirname $0`
|
||||
cd $SCRIPTS_DIR
|
||||
|
||||
|
||||
function run_dir {
|
||||
(
|
||||
DIR=$1
|
||||
cd $DIR
|
||||
for i in `ls *`;do
|
||||
if [ -x "$i" ]; then
|
||||
./$i
|
||||
fi
|
||||
done
|
||||
)
|
||||
}
|
||||
|
||||
data=$(
|
||||
run_dir 'common.d'
|
||||
if [ -d "$HYPERVISOR_DIR" ]; then
|
||||
run_dir $HYPERVISOR_DIR
|
||||
fi
|
||||
)
|
||||
|
||||
echo $data | tr '\n' ' '
|
||||
File renamed without changes.
+21
-133
@@ -22,127 +22,19 @@ if !ONE_LOCATION
|
||||
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
|
||||
ETC_LOCATION="/etc/one/"
|
||||
PROBE_LOCATION="/usr/lib/one/im_probes/"
|
||||
REMOTES_LOCATION="/usr/lib/one/remotes"
|
||||
else
|
||||
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
|
||||
ETC_LOCATION=ONE_LOCATION+"/etc/"
|
||||
PROBE_LOCATION=ONE_LOCATION+"/lib/im_probes/"
|
||||
REMOTES_LOCATION=ONE_LOCATION+"/lib/remotes/"
|
||||
end
|
||||
|
||||
$: << RUBY_LIB_LOCATION
|
||||
|
||||
|
||||
require 'pp'
|
||||
require 'digest/md5'
|
||||
require 'fileutils'
|
||||
require 'OpenNebulaDriver'
|
||||
require 'CommandManager'
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class holds the information of a IM probe and the methods to copy the
|
||||
# script to the remote hosts and run it
|
||||
#-------------------------------------------------------------------------------
|
||||
class Sensor
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Class constructor init the remote script name and working directory
|
||||
#---------------------------------------------------------------------------
|
||||
def initialize(name, script, remote_dir)
|
||||
id = Digest::MD5.hexdigest("#{name}#{script}")
|
||||
|
||||
@script = script
|
||||
@remote_script = "#{remote_dir}/one_im-#{id}"
|
||||
@remote_dir = remote_dir
|
||||
end
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Sends the monitor probe script to the remote host and execute it
|
||||
#---------------------------------------------------------------------------
|
||||
def execute(host, log_proc)
|
||||
script_text = File.read @script
|
||||
|
||||
src = "'mkdir -p #{@remote_dir}; cat > #{@remote_script};" \
|
||||
" if [ \"x$?\" != \"x0\" ]; then exit -1; fi;" \
|
||||
" chmod +x #{@remote_script}; #{@remote_script}'"
|
||||
|
||||
cmd = SSHCommand.run(src, host, log_proc, script_text)
|
||||
|
||||
case cmd.code
|
||||
when 0
|
||||
# Splits the output by lines, strips each line and gets only
|
||||
# lines that have something
|
||||
value = cmd.stdout.split("\n").collect {|v|
|
||||
v2 = v.strip
|
||||
if v2 == ""
|
||||
nil
|
||||
else
|
||||
v2
|
||||
end
|
||||
}.compact.join(",")
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# This class is an array of sensor probes to be executed by the information
|
||||
# driver. The class is built on top of the Sensor class
|
||||
#-------------------------------------------------------------------------------
|
||||
class SensorList < Array
|
||||
#---------------------------------------------------------------------------
|
||||
# Initialize the class
|
||||
#---------------------------------------------------------------------------
|
||||
def initialize(config_file, remote_dir)
|
||||
super(0)
|
||||
|
||||
@remote_dir = remote_dir
|
||||
|
||||
load_sensors(config_file)
|
||||
end
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Execute all sensors in the list in the given host
|
||||
#---------------------------------------------------------------------------
|
||||
def execute_sensors(host, log_proc)
|
||||
results = Array.new
|
||||
|
||||
self.each {|sensor|
|
||||
results << sensor.execute(host, log_proc)
|
||||
}
|
||||
results
|
||||
end
|
||||
|
||||
private
|
||||
#---------------------------------------------------------------------------
|
||||
# Load sensors from a configuration file
|
||||
#---------------------------------------------------------------------------
|
||||
def load_sensors(file)
|
||||
f = open(file, "r")
|
||||
|
||||
f.each_line {|line|
|
||||
l = line.strip.gsub(/#.*$/, "")
|
||||
|
||||
case l
|
||||
when ""
|
||||
when /^[^=]+=[^=]+$/
|
||||
(name, script)=l.split("=")
|
||||
|
||||
name.strip!
|
||||
script.strip!
|
||||
|
||||
script = "#{PROBE_LOCATION}#{script}" if script[0] != ?/
|
||||
|
||||
self << Sensor.new(name, script, @remote_dir)
|
||||
else
|
||||
STDERR.puts "Malformed line in configuration file: #{line}"
|
||||
end
|
||||
}
|
||||
|
||||
f.close
|
||||
end
|
||||
end
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# The SSH Information Manager Driver
|
||||
#-------------------------------------------------------------------------------
|
||||
@@ -151,26 +43,33 @@ class InformationManager < OpenNebulaDriver
|
||||
#---------------------------------------------------------------------------
|
||||
# Init the driver
|
||||
#---------------------------------------------------------------------------
|
||||
def initialize(config_file, remote_dir, num)
|
||||
def initialize(remote_dir, hypervisor, num)
|
||||
super(num, true)
|
||||
|
||||
@sensor_list=SensorList.new(config_file, remote_dir)
|
||||
@hypervisor = hypervisor
|
||||
@remote_dir = remote_dir
|
||||
|
||||
# register actions
|
||||
register_action(:MONITOR, method("action_monitor"))
|
||||
end
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Execute the sensor array in the remote host
|
||||
# Execute the run_probes in the remote host
|
||||
#---------------------------------------------------------------------------
|
||||
def action_monitor(number, host)
|
||||
def action_monitor(number, host, do_update)
|
||||
STDERR.puts Time.now.to_s + ": do_update=" +do_update.inspect
|
||||
if do_update == "1"
|
||||
STDERR.puts Time.now.to_s + ": Doing rsync"
|
||||
sync_cmd = "rsync -Laz #{REMOTES_LOCATION} #{host}:#{@remote_dir}"
|
||||
LocalCommand.run(sync_cmd)
|
||||
else
|
||||
end
|
||||
|
||||
results = @sensor_list.execute_sensors(host, log_method(number))
|
||||
cmd = SSHCommand.run("#{@remote_dir}/im/run_probes #{@hypervisor}",
|
||||
host)
|
||||
|
||||
information=results.select{|res| res && !res.empty? }.join(",")
|
||||
|
||||
if information and !information.empty?
|
||||
send_message("MONITOR", RESULT[:success], number, information)
|
||||
if cmd.code == 0
|
||||
send_message("MONITOR", RESULT[:success], number, cmd.stdout)
|
||||
else
|
||||
send_message("MONITOR", RESULT[:failure], number,
|
||||
"Could not monitor host #{host}.")
|
||||
@@ -184,22 +83,11 @@ end
|
||||
# Information Manager main program
|
||||
#-------------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------------------
|
||||
im_conf = ARGV.last
|
||||
|
||||
if !im_conf || File.exists?(im_conf)
|
||||
puts "You need to specify config file."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
im_conf = "#{ETC_LOCATION}#{im_conf}" if im_conf[0] != ?/
|
||||
|
||||
if !File.exists?(im_conf)
|
||||
puts "Configuration file #{im_conf} does not exists."
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
remote_dir = ENV["IM_REMOTE_DIR"]
|
||||
remote_dir = "/tmp/one-im" if !remote_dir
|
||||
|
||||
im = InformationManager.new(im_conf, "#{remote_dir}/", 15)
|
||||
hypervisor = ARGV[0]||''
|
||||
|
||||
im = InformationManager.new(remote_dir, hypervisor, 15)
|
||||
im.start_driver
|
||||
@@ -1,8 +0,0 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Probes for KVM hosts add as many monitorization sensors as you need
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
cpuarchitecture=architecture.sh
|
||||
nodename=name.sh
|
||||
cpu=cpu.sh
|
||||
kvm=kvm.rb
|
||||
@@ -1,8 +0,0 @@
|
||||
#-------------------------------------------------------------------------------
|
||||
# Probes for Xen hosts add as many monitorization sensors as you need
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
cpuarchitecture=architecture.sh
|
||||
nodename=name.sh
|
||||
cpu=cpu.sh
|
||||
xen=xen.rb
|
||||
Reference in new issue
Block a user