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

Merge branch 'feature-575'

This commit is contained in:
Ruben S. Montero 2011-04-28 13:39:00 +02:00
commit fd20b21081
68 changed files with 674 additions and 471 deletions

View File

@ -26,6 +26,8 @@
#include <unistd.h>
#include "Log.h"
using namespace std;
/**
@ -68,12 +70,11 @@ protected:
{
string str;
const char * cstr;
size_t retval;
str = os.str();
cstr = str.c_str();
retval = ::write(nebula_mad_pipe, cstr, str.size());
::write(nebula_mad_pipe, cstr, str.size());
};
/**
@ -89,6 +90,32 @@ protected:
write(os);
};
/**
* Sets the log message type as specify by the driver.
* @param first character of the type string
* @return the message type
*/
Log::MessageType log_type(const char r)
{
Log::MessageType lt;
switch (r)
{
case 'E':
lt = Log::ERROR;
break;
case 'I':
lt = Log::INFO;
break;
case 'D':
lt = Log::DEBUG;
break;
default:
lt = Log::INFO;
}
return lt;
}
private:
friend class MadManager;
@ -141,7 +168,7 @@ private:
* @return 0 on success
*/
int reload();
/**
* Implements the driver specific protocol, this function should trigger
* actions on the associated manager.

View File

@ -217,6 +217,13 @@ public:
return obj_template->erase(name);
}
/**
* Sets an error message for the VM in the template
* @param message
* @return 0 on success
*/
void set_template_error_message(const string& message);
protected:
/**
@ -318,6 +325,11 @@ private:
* Pointer to the SQL table for the PoolObjectSQL
*/
const char * table;
/**
* Name for the error messages attribute
*/
static const char * error_attribute_name;
};
#endif /*POOL_OBJECT_SQL_H_*/

View File

@ -544,7 +544,6 @@ public:
// ------------------------------------------------------------------------
// States
// ------------------------------------------------------------------------
/**
* Returns the VM state (Dispatch Manager)
* @return the VM state
@ -819,7 +818,6 @@ private:
return -1;
};
// -------------------------------------------------------------------------
// Attribute Parser
// -------------------------------------------------------------------------

View File

@ -195,7 +195,8 @@ LIB_DIRS="$LIB_LOCATION/ruby \
$LIB_LOCATION/remotes/vmm/xen \
$LIB_LOCATION/remotes/vmm/kvm \
$LIB_LOCATION/remotes/image \
$LIB_LOCATION/remotes/image/fs"
$LIB_LOCATION/remotes/image/fs \
$LIB_LOCATION/sh"
VAR_DIRS="$VAR_LOCATION/remotes \
$VAR_LOCATION/remotes/im \
@ -257,6 +258,9 @@ INSTALL_FILES=(
LIB_FILES:$LIB_LOCATION
RUBY_LIB_FILES:$LIB_LOCATION/ruby
RUBY_OPENNEBULA_LIB_FILES:$LIB_LOCATION/ruby/OpenNebula
MAD_SH_LIB_FILES:$LIB_LOCATION/sh
MAD_SH_LIB_FILES:$LIB_LOCATION/remotes
MAD_SH_LIB_FILES:$VAR_LOCATION/remotes
MADS_LIB_FILES:$LIB_LOCATION/mads
IM_PROBES_FILES:$VAR_LOCATION/remotes/im
IM_PROBES_KVM_FILES:$VAR_LOCATION/remotes/im/kvm.d
@ -409,6 +413,14 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \
src/oca/ruby/OpenNebula/TemplatePool.rb \
src/oca/ruby/OpenNebula/XMLUtils.rb"
#-----------------------------------------------------------------------------
# MAD ShellScript library files, to be installed under $LIB_LOCATION/sh
# and remotes directory
#-----------------------------------------------------------------------------
MAD_SH_LIB_FILES="src/mad/sh/scripts_common.sh"
#-------------------------------------------------------------------------------
# Driver executable files, to be installed under $LIB_LOCATION/mads
#-------------------------------------------------------------------------------

View File

@ -69,24 +69,24 @@ main(int argc, char **) {
vector<xmlrpc_c::value> const paramArrayValue(resultArray.vectorValueValue());
//check posible Errors:
xmlrpc_c::value * firstvalue;
firstvalue = &(static_cast<xmlrpc_c::value>(paramArrayValue[0]));
xmlrpc_c::value_boolean * status = &(static_cast<xmlrpc_c::value_boolean>(*firstvalue));
xmlrpc_c::value firstvalue;
firstvalue = static_cast<xmlrpc_c::value>(paramArrayValue[0]);
xmlrpc_c::value_boolean status = static_cast<xmlrpc_c::value_boolean>(firstvalue);
xmlrpc_c::value * secondvalue;
secondvalue = &(static_cast<xmlrpc_c::value>(paramArrayValue[1]));
xmlrpc_c::value_string * valueS = &(static_cast<xmlrpc_c::value_string>(*secondvalue));
xmlrpc_c::value secondvalue;
secondvalue = static_cast<xmlrpc_c::value>(paramArrayValue[1]);
xmlrpc_c::value_string valueS = static_cast<xmlrpc_c::value_string>(secondvalue);
if(static_cast<bool>(*status)) {
if(static_cast<bool>(status)) {
//Success, returns the id assigned to the VM:
cout << "vmid returned: " << static_cast<string>(*valueS) << endl;
cout << "vmid returned: " << static_cast<string>(valueS) << endl;
return 0;
}
else{ //Failure:
string error_value=static_cast<string>(*valueS);
string error_value=static_cast<string>(valueS);
if (error_value.find("Error inserting",0)!=string::npos ) cout << "Error inserting VM in the database" << endl;
else if (error_value.find("Error parsing",0)!=string::npos ) cout << "Error parsing VM template" << endl;
else cout << "Unknown error " << static_cast<string>(*valueS) << endl;
else cout << "Unknown error " << static_cast<string>(valueS) << endl;
};
} catch (girerr::error const error) {
cerr << "Client threw error: " << error.what() << endl;

View File

@ -91,7 +91,7 @@ void AuthManagerDriver::protocol(
{
is.clear();
getline(is,info);
NebulaLog::log("AuM",Log::INFO, info.c_str());
NebulaLog::log("AuM", log_type(result[0]), info.c_str());
}
return;

View File

@ -125,7 +125,7 @@ void HookManagerDriver::protocol(
is.clear();
getline(is,info);
NebulaLog::log("HKM",Log::INFO, info.c_str());
NebulaLog::log("HKM", log_type(result[0]), info.c_str());
}
return;
@ -156,19 +156,26 @@ void HookManagerDriver::protocol(
if ( is.good() )
{
is >> hook_name >> ws;
getline(is,hook_name);
}
getline (is,info);
if (result == "SUCCESS")
{
oss << "Hook " << hook_name << " successfully executed. " << info;
oss << "Success executing Hook: " << hook_name << ". " << info;
vm->log("HKM",Log::INFO,oss);
}
else
{
oss << "Error executing Hook: " << hook_name << ". " << info;
if ( !info.empty() && info[0] != '-' )
{
vm->set_template_error_message(oss.str());
vmpool->update(vm);
}
vm->log("HKM",Log::ERROR,oss);
}
}
@ -177,7 +184,7 @@ void HookManagerDriver::protocol(
string info;
getline(is,info);
vm->log("HKM",Log::INFO,info.c_str());
vm->log("HKM",log_type(result[0]),info.c_str());
}
vm->unlock();

View File

@ -28,14 +28,11 @@ end
$: << RUBY_LIB_LOCATION
require 'pp'
require 'OpenNebulaDriver'
require 'CommandManager'
class HookManagerDriver < OpenNebulaDriver
def initialize(num)
super(num, true)
super(num, true, 0)
register_action(:EXECUTE, method("action_execute"))
end
@ -51,13 +48,14 @@ class HookManagerDriver < OpenNebulaDriver
end
if cmd.code==0
send_message("EXECUTE", RESULT[:success], number, hook_name)
message = "#{hook_name}: #{cmd.stdout}"
send_message("EXECUTE", RESULT[:success], number, message)
else
send_message("EXECUTE", RESULT[:failure], number, hook_name)
message = "#{hook_name}: #{cmd.get_error_message}"
send_message("EXECUTE", RESULT[:failure], number, message)
end
end
end
hm=HookManagerDriver.new(15)
hm.start_driver

View File

@ -386,7 +386,7 @@ public:
void scale_test()
{
time_t the_time, the_time2;
int oid,i,j,rc;
int oid,i,j;
ostringstream oss,ossdump;
string err;
@ -419,7 +419,7 @@ public:
the_time = time(0);
rc = hp->dump(ossdump, "");
hp->dump(ossdump, "");
cout <<"\t"<<i<<"\t"<<the_time2<<"\t"<<time(0)-the_time<< endl;

View File

@ -110,7 +110,7 @@ void InformationManagerDriver::protocol(
hinfo += "\n";
oss << "Host " << id << " successfully monitored."; //, info: "<< hinfo;
oss << "Host " << id << " successfully monitored.";
NebulaLog::log("InM",Log::DEBUG,oss);
rc = host->update_info(hinfo);
@ -136,22 +136,23 @@ void InformationManagerDriver::protocol(
string info;
getline(is,info);
NebulaLog::log("InM",Log::INFO,info.c_str());
NebulaLog::log("InM",log_type(result[0]),info.c_str());
}
return;
error_driver_info:
ess << "Error monitoring host " << id << " : " << is.str();
NebulaLog::log("InM", Log::ERROR, ess);
goto error_common_info;
error_parse_info:
ess << "Error parsing host information: " << hinfo;
NebulaLog::log("InM",Log::ERROR,ess);
goto error_common_info;
error_common_info:
NebulaLog::log("InM",Log::ERROR,ess);
host->set_template_error_message(ess.str());
host->touch(false);

View File

@ -31,18 +31,18 @@ end
$: << RUBY_LIB_LOCATION
require 'OpenNebulaDriver'
require 'CommandManager'
require 'getoptlong'
#-------------------------------------------------------------------------------
# The Local Information Manager Driver
#-------------------------------------------------------------------------------
class InformationManager < OpenNebulaDriver
class InformationManagerDriverSH < OpenNebulaDriver
#---------------------------------------------------------------------------
# Init the driver
#---------------------------------------------------------------------------
def initialize(hypervisor, num)
super(num, true)
super(num, true, 0)
@config = read_configuration
@hypervisor = hypervisor
@ -57,29 +57,40 @@ class InformationManager < OpenNebulaDriver
# Execute the run_probes in the remote host
#---------------------------------------------------------------------------
def action_monitor(number, host, unused)
log_lambda=lambda do |message|
log(number, message)
end
cmd_string = "#{@cmd_path}/run_probes #{@hypervisor} #{host}"
monitor_exe = LocalCommand.run(cmd_string, log_lambda)
if monitor_exe.code == 0
send_message("MONITOR", RESULT[:success], number, monitor_exe.stdout)
else
send_message("MONITOR", RESULT[:failure], number,
"Could not monitor host #{host}.")
end
local_action(cmd_string, number, "MONITOR")
end
end
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Information Manager main program
# IM Driver main program
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
hypervisor = ARGV[0]
im = InformationManager.new(hypervisor, 15)
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
end
im = InformationManagerDriverSH.new(hypervisor,threads)
im.start_driver

View File

@ -31,25 +31,23 @@ end
$: << RUBY_LIB_LOCATION
require 'OpenNebulaDriver'
require 'CommandManager'
require 'getoptlong'
#-------------------------------------------------------------------------------
# The SSH Information Manager Driver
#-------------------------------------------------------------------------------
class InformationManager < OpenNebulaDriver
class InformationManagerDriverSSH < OpenNebulaDriver
#---------------------------------------------------------------------------
# Init the driver
#---------------------------------------------------------------------------
def initialize(hypervisor, threads, retries)
super(threads, true)
super(threads, true, retries)
@config = read_configuration
@hypervisor = hypervisor
@remote_dir = @config['SCRIPTS_REMOTE_DIR']
@retries = retries
# register actions
register_action(:MONITOR, method("action_monitor"))
@ -59,34 +57,19 @@ class InformationManager < OpenNebulaDriver
# Execute the run_probes in the remote host
#---------------------------------------------------------------------------
def action_monitor(number, host, do_update)
log_lambda=lambda do |message|
log(number, message)
end
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_lambda)
LocalCommand.run(sync_cmd, log_method(number))
end
cmd_string = "#{@remote_dir}/im/run_probes #{@hypervisor} #{host}"
cmd = RemotesCommand.run(cmd_string,
host,
@remote_dir,
log_lambda,
@retries)
if cmd.code == 0
send_message("MONITOR", RESULT[:success], number, cmd.stdout)
else
send_message("MONITOR", RESULT[:failure], number,
"Could not monitor host #{host}.")
end
remotes_action(cmd_string, number, host, "MONITOR", @remote_dir)
end
end
#-------------------------------------------------------------------------------
@ -121,5 +104,5 @@ if ARGV.length >= 1
hypervisor = ARGV.shift
end
im = InformationManager.new(hypervisor, threads, retries)
im = InformationManagerDriverSSH.new(hypervisor, threads, retries)
im.start_driver

View File

@ -16,6 +16,8 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/../scripts_common.sh
export LANG=C
HYPERVISOR_DIR=$1.d
@ -29,12 +31,7 @@ function run_dir {
cd $1
for i in `ls *`;do
if [ -x "$i" ]; then
./$i $ARGUMENTS
EXIT_CODE=$?
if [ "x$EXIT_CODE" != "x0" ]; then
echo "Error executing $i" 1>&2
exit $EXIT_CODE
fi
exec_and_log "./$i $ARGUMENTS" "Error executing $i"
fi
done
)

View File

@ -93,6 +93,7 @@ void ImageManagerDriver::protocol(
int id;
Image * image;
string source;
string info;
@ -123,7 +124,7 @@ void ImageManagerDriver::protocol(
is.clear();
getline(is,info);
NebulaLog::log("ImG",Log::INFO, info.c_str());
NebulaLog::log("ImG",log_type(result[0]), info.c_str());
}
return;
@ -148,8 +149,6 @@ void ImageManagerDriver::protocol(
image->set_state(Image::READY);
ipool->update(image);
image->unlock();
NebulaLog::log("ImM", Log::INFO, "Image copied and ready to use.");
}
else
@ -164,8 +163,6 @@ void ImageManagerDriver::protocol(
image->set_state(Image::READY);
ipool->update(image);
image->unlock();
NebulaLog::log("ImM", Log::INFO, "Image saved and ready to use.");
}
else
@ -180,8 +177,6 @@ void ImageManagerDriver::protocol(
image->set_state(Image::READY);
ipool->update(image);
image->unlock();
NebulaLog::log("ImM", Log::INFO, "Image created and ready to use");
}
else
@ -192,14 +187,11 @@ void ImageManagerDriver::protocol(
else if ( action == "RM" )
{
int rc;
string source;
source = image->get_source();
rc = ipool->drop(image);
image->unlock();
if ( rc < 0 )
{
NebulaLog::log("ImM",Log::ERROR,"Image could not be removed from DB");
@ -211,20 +203,17 @@ void ImageManagerDriver::protocol(
}
else
{
ostringstream oss;
oss <<"Error removing image from repository. Remove file " << source
<<" to completely delete image.";
NebulaLog::log("ImM",Log::ERROR,oss);
goto error_rm;
}
}
else if (action == "LOG")
{
getline(is,info);
NebulaLog::log("ImM", Log::INFO, info.c_str());
NebulaLog::log("ImM", log_type(result[0]), info.c_str());
}
image->unlock();
return;
error_cp:
@ -240,6 +229,12 @@ error_mv:
error_mkfs:
os.str("");
os << "Error creating datablock";
goto error_common;
error_rm:
os.str("");
os << "Error removing image from repository. Remove file " << source
<< " to completely delete image.";
error_common:
getline(is,info);
@ -247,6 +242,7 @@ error_common:
if (!info.empty() && (info[0] != '-'))
{
os << ": " << info;
image->set_template_error_message(os.str());
}
NebulaLog::log("ImM", Log::ERROR, os);

View File

@ -32,7 +32,6 @@ end
$: << RUBY_LIB_LOCATION
require "OpenNebulaDriver"
require "CommandManager"
require 'getoptlong'
# This class provides basic messaging and logging functionality
@ -56,7 +55,7 @@ class ImageDriver < OpenNebulaDriver
# Register default actions for the protocol
# -------------------------------------------------------------------------
def initialize(fs_type, concurrency=10, threaded=true)
super(concurrency,threaded)
super(concurrency,threaded,0)
@actions_path = "#{VAR_LOCATION}/remotes/image/#{fs_type}"
@ -66,25 +65,6 @@ class ImageDriver < OpenNebulaDriver
register_action(ACTION[:mkfs].to_sym, method("mkfs"))
end
# -------------------------------------------------------------------------
# Execute a command associated to an action and id on localhost
# -------------------------------------------------------------------------
def local_action(command, id, action)
command_exe = LocalCommand.run(command)
if command_exe.code == 0
result = :success
info = "-"
else
result = :failure
info = command_exe.stderr
end
info = "-" if info == nil || info.empty?
send_message(ACTION[action],RESULT[result],id,info)
end
# -------------------------------------------------------------------------
# Image Manager Protocol Actions (generic implementation
# -------------------------------------------------------------------------

View File

@ -24,14 +24,12 @@
# ------------ Set up the environment to source common tools ------------
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/usr/lib/one/mads/tm_common.sh
VAR_LOCATION=/var/lib/one/
LIB_LOCATION=/usr/lib/one
else
TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
VAR_LOCATION=$ONE_LOCATION/var/
LIB_LOCATION=$ONE_LOCATION/lib
fi
. $TMCOMMON
. $LIB_LOCATION/sh/scripts_common.sh
# ------------ Copy the image to the repository ------------
@ -41,12 +39,14 @@ DST=$2
case $SRC in
http://*)
log "Downloading $SRC to the image repository"
exec_and_log "$WGET -O $DST $SRC"
exec_and_log "$WGET -O $DST $SRC" \
"Error downloading $SRC"
;;
*)
log "Copying local image $SRC to the image repository"
exec_and_log "cp -f $SRC $DST"
exec_and_log "cp -f $SRC $DST" \
"Error copying $SRC to $DST"
;;
esac

View File

@ -24,12 +24,12 @@
# ------------ Set up the environment to source common tools ------------
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/usr/lib/one/mads/tm_common.sh
LIB_LOCATION=/usr/lib/one
else
TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
LIB_LOCATION=$ONE_LOCATION/lib
fi
. $TMCOMMON
. $LIB_LOCATION/sh/scripts_common.sh
# ------------ Create the image to the repository ------------
@ -37,6 +37,8 @@ DST=$1
FSTYPE=$2
SIZE=$3
exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M"
exec_and_log "$MKFS -t $FSTYPE -F $DST"
exec_and_log "$DD if=/dev/zero of=$DST bs=1 count=1 seek=${SIZE}M" \
"Could not create image $DST"
exec_and_log "$MKFS -t $FSTYPE -F $DST" \
"Unable to create filesystem $FSTYPE in $DST"
exec_and_log "chmod 0660 $DST"

View File

@ -24,14 +24,12 @@
# ------------ Set up the environment to source common tools ------------
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/usr/lib/one/mads/tm_common.sh
VAR_LOCATION=/var/lib/one/
LIB_LOCATION=/usr/lib/one
else
TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
VAR_LOCATION=$ONE_LOCATION/var/
LIB_LOCATION=$ONE_LOCATION/lib
fi
. $TMCOMMON
. $LIB_LOCATION/sh/scripts_common.sh
# ------------ Move the image to the repository ------------
@ -41,12 +39,14 @@ DST=$2
case $SRC in
http://*)
log "Downloading $SRC to the image repository"
exec_and_log "$WGET -O $DST $SRC"
exec_and_log "$WGET -O $DST $SRC" \
"Error downloading $SRC"
;;
*)
log "Moving local image $SRC to the image repository"
exec_and_log "mv -f $SRC $DST"
exec_and_log "mv -f $SRC $DST" \
"Could not move $SRC to $DST"
;;
esac

View File

@ -23,14 +23,12 @@
# ------------ Set up the environment to source common tools ------------
if [ -z "${ONE_LOCATION}" ]; then
TMCOMMON=/usr/lib/one/mads/tm_common.sh
VAR_LOCATION=/var/lib/one/
LIB_LOCATION=/usr/lib/one
else
TMCOMMON=$ONE_LOCATION/lib/mads/tm_common.sh
VAR_LOCATION=$ONE_LOCATION/var/
LIB_LOCATION=$ONE_LOCATION/lib
fi
. $TMCOMMON
. $LIB_LOCATION/sh/scripts_common.sh
# ------------ Remove the image to the repository ------------
@ -38,5 +36,6 @@ SRC=$1
if [ -e $SRC ] ; then
log "Removing $SRC from the image repository"
exec_and_log "rm $SRC"
exec_and_log "rm $SRC" \
"Error deleting $SRC"
fi

View File

@ -39,7 +39,6 @@ Mad::~Mad()
char buf[]="FINALIZE\n";
int status;
pid_t rp;
size_t retval;
if ( pid==-1)
{
@ -47,7 +46,7 @@ Mad::~Mad()
}
// Finish the driver
retval = ::write(nebula_mad_pipe, buf, strlen(buf));
::write(nebula_mad_pipe, buf, strlen(buf));
close(mad_nebula_pipe);
close(nebula_mad_pipe);
@ -68,7 +67,6 @@ int Mad::start()
{
int ne_mad_pipe[2];
int mad_ne_pipe[2];
size_t retval;
map<string,string>::iterator it;
@ -191,7 +189,7 @@ int Mad::start()
fcntl(nebula_mad_pipe, F_SETFD, FD_CLOEXEC);
fcntl(mad_nebula_pipe, F_SETFD, FD_CLOEXEC);
retval = ::write(nebula_mad_pipe, buf, strlen(buf));
::write(nebula_mad_pipe, buf, strlen(buf));
do
{
@ -291,11 +289,9 @@ int Mad::reload()
int status;
int rc;
pid_t rp;
size_t retval;
// Finish the driver
retval = ::write(nebula_mad_pipe, buf, strlen(buf));
::write(nebula_mad_pipe, buf, strlen(buf));
close(nebula_mad_pipe);
close(mad_nebula_pipe);

View File

@ -147,7 +147,6 @@ int MadManager::add(Mad *mad)
{
char buf = 'A';
int rc;
size_t retval;
if ( mad == 0 )
{
@ -167,7 +166,7 @@ int MadManager::add(Mad *mad)
mads.push_back(mad);
retval = write(pipe_w, &buf, sizeof(char));
write(pipe_w, &buf, sizeof(char));
unlock();
@ -216,7 +215,6 @@ void MadManager::listener()
int greater;
unsigned int i,j;
int rc,mrc;
size_t retval;
char c;
@ -264,7 +262,7 @@ void MadManager::listener()
{
if ( fd == pipe_r ) // Driver added, update the fd vector
{
retval = read(fd, (void *) &c, sizeof(char));
read(fd, (void *) &c, sizeof(char));
lock();

View File

@ -27,6 +27,20 @@ require 'stringio'
# * +stdout+: string of the standard output. Read-only
# * +stderr+: string of the standard error. Read-only
# * +command+: command to execute. Read-only
#
# The protocol for scripts to log is as follows:
#
# * Log messages will be sent to STDOUT
# * The script will return 0 if it succeded or any other value
# if there was a failure
# * In case of failure the cause of the error will be written to STDERR
# wrapped by start and end marks as follows:
#
# ERROR MESSAGE --8<------
# error message for the failure
# ERROR MESSAGE ------>8--
class GenericCommand
attr_reader :code, :stdout, :stderr, :command
@ -72,13 +86,20 @@ class GenericCommand
if @code!=0
log("Command execution fail: #{command}")
log("STDERR follows.")
log(@stderr)
end
log(@stderr)
return @code
end
# Parses error message from +stderr+ output
def get_error_message
tmp=@stderr.scan(/^ERROR MESSAGE --8<------\n(.*?)ERROR MESSAGE ------>8--$/m)
return "-" if !tmp[0]
tmp[0].join(' ').strip
end
private
# Gets exit code from STDERR
@ -158,14 +179,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
sleep 1
cmd.run

View File

@ -12,10 +12,12 @@
# See the License for the specific language governing permissions and */
# limitations under the License. */
# -------------------------------------------------------------------------- */
require "ActionManager"
require "CommandManager"
# Author:: dsa-research.org
# Copyright:: (c) 2009 Universidad Computense de Madrid
# Copyright:: (c) OpenNebula Project Leads (OpenNebula.org)
# License:: Apache License
# This class provides basic messaging and logging functionality
@ -34,14 +36,18 @@ class OpenNebulaDriver < ActionManager
:failure => "FAILURE"
}
def initialize(concurrency=10, threaded=true)
def initialize(concurrency=10, threaded=true, retries=0)
super(concurrency,threaded)
register_action(:INIT, method("init"))
@retries = retries
@send_mutex=Mutex.new
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}"
@ -49,25 +55,103 @@ 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)
command_exe = RemotesCommand.run(command,
host,
remote_dir,
log_method(id),
std_in,
@retries)
if command_exe.code == 0
result = RESULT[:success]
info = command_exe.stdout
else
result = RESULT[:failure]
info = command_exe.get_error_message
end
info = "-" if info == nil || info.empty?
send_message(aname,result,id,info)
end
# -------------------------------------------------------------------------
# Execute a command associated to an action and id on localhost
# -------------------------------------------------------------------------
def local_action(command, id, aname)
command_exe = LocalCommand.run(command, log_method(id))
if command_exe.code == 0
result = RESULT[:success]
info = command_exe.stdout
else
result = RESULT[:failure]
info = command_exe.get_error_message
end
info = "-" if info == nil || info.empty?
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
msg.each_line {|line|
send_message("LOG", "-", number, line.strip)
severity='I'
l=line.strip
if l=='ERROR MESSAGE --8<------'
in_error_message=true
next
elsif l=='ERROR MESSAGE ------>8--'
in_error_message=false
next
else
if in_error_message
severity='E'
elsif line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
line=$2
case $1
when 'ERROR'
severity='E'
when 'DEBUG'
severity='D'
when 'INFO'
severity='I'
else
severity='I'
end
end
end
send_message("LOG", severity, number, line.strip)
}
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
@ -101,13 +185,17 @@ private
if action == :DRIVER_CANCEL
cancel_action(action_id)
log(action_id,"Driver command for #{action_id} cancelled")
else
else
trigger_action(action,action_id,*args)
end
end
end
end
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if __FILE__ == $0
class SampleDriver < OpenNebulaDriver

View File

@ -66,10 +66,9 @@ class VirtualMachineDriver < OpenNebulaDriver
# Register default actions for the protocol
# -------------------------------------------------------------------------
def initialize(concurrency=10, threaded=true, retries=0)
super(concurrency,threaded)
super(concurrency,threaded,retries)
@hosts = Array.new
@retries = retries
register_action(ACTION[:deploy].to_sym, method("deploy"))
register_action(ACTION[:shutdown].to_sym, method("shutdown"))
@ -109,43 +108,14 @@ class VirtualMachineDriver < OpenNebulaDriver
# 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)
command_exe = RemotesCommand.run(command,
host,
remote_dir,
log_method(id),
std_in,
@retries)
if command_exe.code == 0
result = :success
info = command_exe.stdout
else
result = :failure
info = command_exe.stderr
end
info = "-" if info == nil || info.empty?
send_message(ACTION[action],RESULT[result],id,info)
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)
command_exe = LocalCommand.run(command)
if command_exe.code == 0
result = :success
info = command_exe.stdout
else
result = :failure
info = command_exe.stderr
end
info = "-" if info == nil || info.empty?
send_message(ACTION[action],RESULT[result],id,info)
super(command,id,ACTION[action])
end
# -------------------------------------------------------------------------
@ -187,7 +157,9 @@ class VirtualMachineDriver < OpenNebulaDriver
end
private
# -------------------------------------------------------------------------
# Interface to handle the pending events from the ActionManager Interface
# -------------------------------------------------------------------------
def delete_running_action(action_id)
action=@action_running[action_id]
if action
@ -227,11 +199,6 @@ private
@action_queue.delete_at(action_index)
end
STDERR.puts "action: #{action.inspect}"
STDERR.puts "queue: #{@action_queue.inspect}"
STDERR.puts "hosts: #{@hosts.inspect}"
STDERR.flush
return action
end
@ -240,6 +207,10 @@ private
end
end
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if __FILE__ == $0
class TemplateDriver < VirtualMachineDriver

147
src/mad/sh/scripts_common.sh Executable file
View File

@ -0,0 +1,147 @@
# -------------------------------------------------------------------------- #
# 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. #
#--------------------------------------------------------------------------- #
# Paths for utilities
AWK=awk
BASH=/bin/bash
CUT=cut
DATE=/bin/date
DD=/bin/dd
LVCREATE=/sbin/lvcreate
LVREMOVE=/sbin/lvremove
LVS=/sbin/lvs
MD5SUM=/usr/bin/md5sum
MKFS=/sbin/mkfs
MKISOFS=/usr/bin/mkisofs
MKSWAP=/sbin/mkswap
SCP=/usr/bin/scp
SED=/bin/sed
SSH=/usr/bin/ssh
SUDO=/usr/bin/sudo
WGET=/usr/bin/wget
# Used for log messages
SCRIPT_NAME=`basename $0`
# Formats date for logs
function log_date
{
$DATE +"%a %b %d %T %Y"
}
# Logs a message, alias to log_info
function log
{
log_info $1
}
# Log function that knows how to deal with severities and adds the
# script name
function log_function
{
echo "$1: $SCRIPT_NAME: $2" 1>&2
}
# Logs an info message
function log_info
{
log_function "INFO" "$1"
}
# Logs an error message
function log_error
{
log_function "ERROR" "$1"
}
# Logs a debug message
function log_debug
{
log_function "DEBUG" "$1"
}
# This function is used to pass error message to the mad
function error_message
{
(
echo "ERROR MESSAGE --8<------"
echo "$1"
echo "ERROR MESSAGE ------>8--"
) 1>&2
}
# Executes a command, if it fails returns error message and exits
# If a second parameter is present it is used as the error message when
# the command fails
function exec_and_log
{
message=$2
output=`$1 2>&1 1>/dev/null`
code=$?
if [ "x$code" != "x0" ]; then
log_error "Command \"$1\" failed."
log_error "$output"
if [ -n "$message" ]; then
error_message "$output"
else
error_message "$message"
fi
exit $code
fi
log "Executed \"$1\"."
}
# Like exec_and_log but the first argument is the number of seconds
# before here is timeout and kills the command
#
# NOTE: if the command is killed because a timeout the exit code
# will be 143 = 128+15 (SIGHUP)
function timeout_exec_and_log
{
TIMEOUT=$1
shift
CMD="$1"
exec_and_log "$CMD" &
CMD_PID=$!
# timeout process
(
sleep $TIMEOUT
kill $CMD_PID 2>/dev/null
log_error "Timeout executing $CMD"
error_message "Timeout executing $CMD"
exit -1
) &
TIMEOUT_PID=$!
# stops the execution until the command finalizes
wait $CMD_PID 2>/dev/null
CMD_CODE=$?
# if the script reaches here the command finished before it
# consumes timeout seconds so we can kill timeout process
kill $TIMEOUT_PID 2>/dev/null 1>/dev/null
wait $TIMEOUT_PID 2>/dev/null
# checks the exit code of the command and exits if it is not 0
if [ "x$CMD_CODE" != "x0" ]; then
exit $CMD_CODE
fi
}

View File

@ -108,3 +108,38 @@ int PoolObjectSQL::drop(SqlDB *db)
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
const char * PoolObjectSQL::error_attribute_name = "ERROR";
void PoolObjectSQL::set_template_error_message(const string& message)
{
VectorAttribute * attr;
map<string,string> error_value;
char str[26];
time_t the_time;
the_time = time(NULL);
#ifdef SOLARIS
ctime_r(&(the_time),str,sizeof(char)*26);
#else
ctime_r(&(the_time),str);
#endif
str[24] = '\0'; // Get rid of final enter character
error_value.insert(make_pair("TIMESTAMP",str));
error_value.insert(make_pair("MESSAGE",message));
attr = new VectorAttribute(error_attribute_name,error_value);
obj_template->set(attr);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -29,7 +29,6 @@ void RequestManager::ImageInfo::execute(
string session;
int iid;
int uid; // Image owner user id
int rc; // Requesting user id
Image * image;
@ -47,16 +46,6 @@ void RequestManager::ImageInfo::execute(
session = xmlrpc_c::value_string(paramList.getString(0));
iid = xmlrpc_c::value_int (paramList.getInt(1));
// Get image from the ImagePool
image = ImageInfo::ipool->get(iid,true);
if ( image == 0 )
{
goto error_image_get;
}
uid = image->get_uid();
// Check if it is a valid user
rc = ImageInfo::upool->authenticate(session);
@ -64,6 +53,14 @@ void RequestManager::ImageInfo::execute(
{
goto error_authenticate;
}
// Get image from the ImagePool
image = ImageInfo::ipool->get(iid,true);
if ( image == 0 )
{
goto error_image_get;
}
oss << *image;
@ -87,7 +84,6 @@ error_image_get:
error_authenticate:
oss.str(authenticate_error(method_name));
image->unlock();
goto error_common;
error_common:

View File

@ -30,7 +30,6 @@ void RequestManager::VirtualNetworkDelete::execute(
string name;
int nid;
int uid;
VirtualNetwork * vn;
@ -99,8 +98,6 @@ void RequestManager::VirtualNetworkDelete::execute(
goto error_vn_get;
}
uid = vn->get_uid();
rc = vnpool->drop(vn);
vn->unlock();

View File

@ -39,7 +39,7 @@ public:
*/
HostXML * get(int oid) const
{
return static_cast<const HostXML *>(PoolXML::get(oid));
return static_cast<HostXML *>(PoolXML::get(oid));
};
protected:

View File

@ -87,9 +87,8 @@ public:
update_from_str(message);
vector<xmlNodePtr> nodes;
int num_objs;
num_objs = get_suitable_nodes(nodes);
get_suitable_nodes(nodes);
for (unsigned int i=0 ;
i < nodes.size() && ( pool_limit <= 0 || i < pool_limit ) ;

View File

@ -68,16 +68,9 @@ int MySqlDB::exec(ostringstream& cmd, Callbackable* obj)
const char * c_str;
string str;
int (*callback)(void*,int,char**,char**);
void * arg;
str = cmd.str();
c_str = str.c_str();
callback = 0;
arg = 0;
lock();
rc = mysql_query(db, c_str);

View File

@ -79,7 +79,7 @@ void TransferManagerDriver::protocol(
is.clear();
getline(is,info);
NebulaLog::log("TM",Log::INFO, info.c_str());
NebulaLog::log("TM",log_type(result[0]), info.c_str());
}
return;
@ -142,8 +142,16 @@ void TransferManagerDriver::protocol(
getline(is,info);
os.str("");
os << "Error excuting image transfer script: " << info;
os << "Error excuting image transfer script";
if (!info.empty() && info[0] != '-')
{
os << ": " << info;
vm->set_template_error_message(os.str());
vmpool->update(vm);
}
vm->log("TM",Log::ERROR,os);
switch (vm->get_lcm_state())
@ -171,7 +179,7 @@ void TransferManagerDriver::protocol(
string info;
getline(is,info);
vm->log("TM",Log::INFO,info.c_str());
vm->log("TM",log_type(result[0]),info.c_str());
}
vm->unlock();

View File

@ -27,18 +27,7 @@ are the names of the commands (uppercase) and contain the path of
the script that will be executed for that command.
It also contains some methods to execute the scripts, get the output
of the script (success/failure, error and log messages). The protocol
for scripts to do so is as follows:
* Log messages will be sent to STDOUT
* The script will return 0 if it succeded or any other value
if there was a failure
* In case of failure the cause of the error will be written to STDERR
wrapped by start and end marks as follows:
ERROR MESSAGE --8<------
error message for the failure
ERROR MESSAGE ------>8--
of the script (success/failure, error and log messages).
=end
class TMPlugin < Hash
@ -150,7 +139,7 @@ class TMScript
if res.code == 0
res = [true, ""]
else
res = [false, get_error_message(res.stderr)]
res = [false, res.get_error_message]
end
end
@ -176,13 +165,6 @@ class TMScript
@lines<< command
}
end
# Parses error message from +stderr+ output
def get_error_message(str)
tmp=str.scan(/^ERROR MESSAGE --8<------\n(.*?)ERROR MESSAGE ------>8--$/m)
return "Error message not available" if !tmp[0]
tmp[0][0].strip
end
end

View File

@ -34,8 +34,8 @@ DST_PATH=`arg_path $DST`
fix_paths
log "$1 $2"
log "DST: $DST_PATH"
log_debug "$1 $2"
log_debug "DST: $DST_PATH"
DST_DIR=`dirname $DST_PATH`
@ -46,12 +46,14 @@ exec_and_log "chmod a+w $DST_DIR"
case $SRC in
http://*)
log "Downloading $SRC"
exec_and_log "$WGET -O $DST_PATH $SRC"
exec_and_log "$WGET -O $DST_PATH $SRC" \
"Error downloading $SRC"
;;
*)
log "Cloning $SRC_PATH"
exec_and_log "cp -r $SRC_PATH $DST_PATH"
exec_and_log "cp -r $SRC_PATH $DST_PATH" \
"Error copying $SRC to $DST"
;;
esac

View File

@ -48,16 +48,19 @@ exec_and_log "mkdir -p $ISO_DIR"
for f in $SRC; do
case $f in
http://*)
exec_and_log "$WGET -O $ISO_DIR $f"
exec_and_log "$WGET -O $ISO_DIR $f" \
"Error downloading $f"
;;
*)
exec_and_log "cp -R $f $ISO_DIR"
exec_and_log "cp -R $f $ISO_DIR" \
"Error copying $f to $ISO_DIR"
;;
esac
done
exec_and_log "$MKISOFS -o $DST_PATH -J -R $ISO_DIR"
exec_and_log "$MKISOFS -o $DST_PATH -J -R $ISO_DIR" \
"Error creating iso fs"
exec_and_log "rm -rf $ISO_DIR"

View File

@ -34,4 +34,5 @@ SRC_PATH=`arg_path $SRC`
fix_src_path
log "Deleting $SRC_PATH"
exec_and_log "rm -rf $SRC_PATH"
exec_and_log "rm -rf $SRC_PATH" \
"Error deleting $SRC_PATH"

View File

@ -37,7 +37,8 @@ fix_dst_path
DST_DIR=`dirname $DST_PATH`
log "Creating directory $DST_DIR"
exec_and_log "mkdir -p $DST_DIR"
exec_and_log "mkdir -p $DST_DIR" \
"Could not create directory $DST_DIR"
exec_and_log "chmod a+w $DST_DIR"
log "Link $SRC_PATH"

View File

@ -36,8 +36,11 @@ fix_dst_path
DST_DIR=`dirname $DST_PATH`
exec_and_log "mkdir -p $DST_DIR"
exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "$MKFS -t $FSTYPE -F $DST_PATH"
exec_and_log "mkdir -p $DST_DIR" \
"Error creating directory $DST_DIR"
exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
"Could not create image $DST_PATH"
exec_and_log "$MKFS -t $FSTYPE -F $DST_PATH" \
"Unable to create filesystem $FSTYPE in $DST_PATH"
exec_and_log "chmod a+rw $DST_PATH"

View File

@ -35,15 +35,17 @@ fix_dst_path
DST_DIR=`dirname $DST_PATH`
log "Creating directory $DST_DIR"
log_debug "Creating directory $DST_DIR"
exec_and_log "mkdir -p $DST_DIR"
exec_and_log "chmod a+w $DST_DIR"
log "Creating ${SIZE}Mb image in $DST_PATH"
exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
log_debug "Creating ${SIZE}Mb image in $DST_PATH"
exec_and_log "$DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
"Could not create image file $DST_PATH"
log "Initializing swap space"
exec_and_log "$MKSWAP $DST_PATH"
log_debug "Initializing swap space"
exec_and_log "$MKSWAP $DST_PATH" \
"Could not create swap on $DST_PATH"
exec_and_log "chmod a+w $DST_PATH"

View File

@ -43,7 +43,8 @@ else
log "Will not move, is not saving image"
else
log "Moving $SRC_PATH"
exec_and_log "mv $SRC_PATH $DST_PATH"
exec_and_log "mv $SRC_PATH $DST_PATH" \
"Could not move $SRC_PATH to $DST_PATH"
fi
fi

View File

@ -34,23 +34,26 @@ SRC_HOST=`arg_host $SRC`
DST_HOST=`arg_host $DST`
log "$1 $2"
log "DST: $DST_PATH"
log_debug "$1 $2"
log_debug "DST: $DST_PATH"
DST_DIR=`dirname $DST_PATH`
log "Creating directory $DST_DIR"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \
"Error creating directory $DST_DIR"
case $SRC in
http://*)
log "Downloading $SRC"
exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC"
exec_and_log "$SSH $DST_HOST $WGET -O $DST_PATH $SRC" \
"Error downloading $SRC"
;;
*)
log "Cloning $SRC"
exec_and_log "$SCP $SRC $DST"
exec_and_log "$SCP $SRC $DST" \
"Error copying $SRC to $DST"
;;
esac

View File

@ -47,21 +47,27 @@ fi
ISO_DIR="$TMP_DIR/isofiles"
exec_and_log "mkdir -p $ISO_DIR"
exec_and_log "mkdir -p $ISO_DIR" \
"Error creating directory $ISO_DIR"
for f in $SRC; do
case $f in
http://*)
exec_and_log "$WGET -O $ISO_DIR $f"
exec_and_log "$WGET -O $ISO_DIR $f" \
"Error downloading $f"
;;
*)
exec_and_log "cp -R $f $ISO_DIR"
exec_and_log "cp -R $f $ISO_DIR" \
"Error copying $f to $ISO_DIR"
;;
esac
done
exec_and_log "$MKISOFS -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR"
exec_and_log "$SCP $TMP_DIR/$DST_FILE $DST"
exec_and_log "rm -rf $TMP_DIR"
exec_and_log "$MKISOFS -o $TMP_DIR/$DST_FILE -J -R $ISO_DIR" \
"Error creating iso fs"
exec_and_log "$SCP $TMP_DIR/$DST_FILE $DST" \
"Error copying $TMP_DIR/$DST_FILE to $DST"
exec_and_log "rm -rf $TMP_DIR" \
"Error deleting $TMP_DIR"

View File

@ -31,4 +31,5 @@ SRC_PATH=`arg_path $SRC`
SRC_HOST=`arg_host $SRC`
log "Deleting $SRC_PATH"
exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"
exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH" \
"Error deleting $SRC_PATH"

View File

@ -32,7 +32,10 @@ DST_PATH=`arg_path $DST`
DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "$SSH $DST_HOST $MKFS -t $FSTYPE -F $DST_PATH"
exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \
"Error creating directory $DST_DIR"
exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
"Could not create image $DST_PATH"
exec_and_log "$SSH $DST_HOST $MKFS -t $FSTYPE -F $DST_PATH" \
"Unable to create filesystem $FSTYPE in $DST_PATH"
exec_and_log "$SSH $DST_HOST chmod a+rw $DST_PATH"

View File

@ -34,10 +34,12 @@ DST_DIR=`dirname $DST_PATH`
log "Creating ${SIZE}Mb image in $DST_PATH"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M"
exec_and_log "$SSH $DST_HOST $DD if=/dev/zero of=$DST_PATH bs=1 count=1 seek=${SIZE}M" \
"Could not create image file $DST_PATH"
log "Initializing swap space"
exec_and_log "$SSH $DST_HOST $MKSWAP $DST_PATH"
exec_and_log "$SSH $DST_HOST $MKSWAP $DST_PATH" \
"Could not create swap on $DST_PATH"
exec_and_log "$SSH $DST_HOST chmod a+w $DST_PATH"

View File

@ -36,6 +36,8 @@ DST_HOST=`arg_host $DST`
DST_DIR=`dirname $DST_PATH`
log "Moving $SRC_PATH"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR"
exec_and_log "$SCP -r $SRC $DST"
exec_and_log "$SSH $DST_HOST mkdir -p $DST_DIR" \
"Unable to create directory $DST_DIR"
exec_and_log "$SCP -r $SRC $DST" \
"Could not copy $SRC to $DST"
exec_and_log "$SSH $SRC_HOST rm -rf $SRC_PATH"

View File

@ -18,28 +18,17 @@ export LANG=C
if [ -z "$ONE_LOCATION" ]; then
ONE_LOCAL_VAR=/var/lib/one
ONE_LIB=/usr/lib/one
else
ONE_LOCAL_VAR=$ONE_LOCATION/var
ONE_LIB=$ONE_LOCATION/lib
fi
# Paths for utilities
AWK=awk
BASH=/bin/bash
CUT=cut
DATE=/bin/date
DD=/bin/dd
LVCREATE=/sbin/lvcreate
LVREMOVE=/sbin/lvremove
LVS=/sbin/lvs
MD5SUM=/usr/bin/md5sum
MKFS=/sbin/mkfs
MKISOFS=/usr/bin/mkisofs
MKSWAP=/sbin/mkswap
SCP=/usr/bin/scp
SED=/bin/sed
SSH=/usr/bin/ssh
SUDO=/usr/bin/sudo
WGET=/usr/bin/wget
ONE_SH=$ONE_LIB/sh
. $ONE_SH/scripts_common.sh
if [ "x$(uname -s)" = "xLinux" ]; then
SED="$SED -r"
@ -92,37 +81,6 @@ function fix_dst_path
fi
}
# Used for log messages
SCRIPT_NAME=`basename $0`
# Formats date for logs
function log_date
{
$DATE +"%a %b %d %T %Y"
}
# Logs a message
function log
{
echo "$SCRIPT_NAME: $1"
}
# Logs an error message
function log_error
{
log "ERROR: $1"
}
# This function is used to pass error message to the mad
function error_message
{
(
echo "ERROR MESSAGE --8<------"
echo "$1"
echo "ERROR MESSAGE ------>8--"
) 1>&2
}
# Gets the host from an argument
function arg_host
{
@ -135,57 +93,5 @@ function arg_path
echo $1 | $SED 's/^[^:]*:(.*)$/\1/'
}
# Executes a command, if it fails return error message and exits
function exec_and_log
{
output=`$1 2>&1 1>/dev/null`
code=$?
if [ "x$code" != "x0" ]; then
log_error "Command \"$1\" failed."
log_error "$output"
error_message "$output"
exit $code
fi
log "Executed \"$1\"."
}
# Like exec_and_log but the first argument is the number of seconds
# before here is timeout and kills the command
#
# NOTE: if the command is killed because a timeout the exit code
# will be 143 = 128+15 (SIGHUP)
function timeout_exec_and_log
{
TIMEOUT=$1
shift
CMD="$1"
exec_and_log "$CMD" &
CMD_PID=$!
# timeout process
(
sleep $TIMEOUT
kill $CMD_PID 2>/dev/null
log_error "Timeout executing $CMD"
error_message "Timeout executing $CMD"
exit -1
) &
TIMEOUT_PID=$!
# stops the execution until the command finalizes
wait $CMD_PID 2>/dev/null
CMD_CODE=$?
# if the script reaches here the command finished before it
# consumes timeout seconds so we can kill timeout process
kill $TIMEOUT_PID 2>/dev/null 1>/dev/null
wait $TIMEOUT_PID 2>/dev/null
# checks the exit code of the command and exits if it is not 0
if [ "x$CMD_CODE" != "x0" ]; then
exit $CMD_CODE
fi
}

View File

@ -175,11 +175,11 @@ public:
void get_using_name()
{
int oid_0, oid_1;
int oid_0;
// Allocate two objects
oid_0 = allocate(0);
oid_1 = allocate(1);
allocate(1);
// ---------------------------------
// Get first object and check its integrity

View File

@ -227,17 +227,46 @@ void VirtualMachineManagerDriver::poll (
/* MAD Interface */
/* ************************************************************************** */
/* -------------------------------------------------------------------------- */
/* Helpers for the protocol function */
/* -------------------------------------------------------------------------- */
static void log_error(VirtualMachine* vm,
ostringstream& os,
istringstream& is,
const char * msg)
{
string info;
getline(is,info);
os.str("");
os << msg;
if (!info.empty() && info[0] != '-')
{
os << ": " << info;
vm->set_template_error_message(os.str());
}
vm->log("VMM",Log::ERROR,os);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::protocol(
string& message)
{
istringstream is(message);
ostringstream os;
istringstream is(message);
ostringstream os;
string action;
string result;
string action;
string result;
int id;
VirtualMachine * vm;
int id;
VirtualMachine * vm;
os << "Message received: " << message;
NebulaLog::log("VMM", Log::DEBUG, os);
@ -265,7 +294,7 @@ void VirtualMachineManagerDriver::protocol(
is.clear();
getline(is,info);
NebulaLog::log("VMM",Log::INFO, info.c_str());
NebulaLog::log("VMM", log_type(result[0]), info.c_str());
}
return;
@ -316,17 +345,8 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error deploying virtual machine";
if (info[0] != '-')
os << ": " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error deploying virtual machine");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
}
@ -342,14 +362,8 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error shuting down VM, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error shuting down VM");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::SHUTDOWN_FAILURE, id);
}
@ -365,14 +379,8 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error canceling VM, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error canceling VM");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::CANCEL_FAILURE, id);
}
@ -388,14 +396,8 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error saving VM state, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error saving VM state");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::SAVE_FAILURE, id);
}
@ -411,14 +413,8 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error restoring VM, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error restoring VM");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
}
@ -434,14 +430,8 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error live-migrating VM, " << info;
vm->log("VMM",Log::ERROR,os);
log_error(vm,os,is,"Error live migrating VM");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::DEPLOY_FAILURE, id);
}
@ -507,7 +497,7 @@ void VirtualMachineManagerDriver::protocol(
{
tiss >> state;
}
else
else if (!var.empty())
{
string val;
@ -580,12 +570,8 @@ void VirtualMachineManagerDriver::protocol(
}
else
{
string info;
getline(is,info);
os.str("");
os << "Error monitoring VM, " << info;
log_error(vm,os,is,"Error monitoring VM");
vmpool->update(vm);
vm->log("VMM",Log::ERROR,os);
}
@ -595,7 +581,7 @@ void VirtualMachineManagerDriver::protocol(
string info;
getline(is,info);
vm->log("VMM",Log::INFO,info.c_str());
vm->log("VMM",log_type(result[0]),info.c_str());
}
vm->unlock();

View File

@ -17,7 +17,9 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
virsh --connect $LIBVIRT_URI destroy $deploy_id
exec_and_log "virsh --connect $LIBVIRT_URI destroy $deploy_id" \
"Could not destroy $deploy_id"

View File

@ -17,6 +17,7 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
source $(dirname $0)/../../scripts_common.sh
domain=$1
@ -28,5 +29,6 @@ data=`virsh --connect $LIBVIRT_URI create $domain`
if [ "x$?" = "x0" ]; then
echo $data | sed 's/Domain //' | sed 's/ created from .*$//'
else
error_message "Could not create domain from $domain"
exit -1
fi

View File

@ -17,8 +17,10 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
dest_host=$2
virsh --connect $LIBVIRT_URI migrate --live $deploy_id $QEMU_PROTOCOL://$dest_host/system
exec_and_log "virsh --connect $LIBVIRT_URI migrate --live $deploy_id $QEMU_PROTOCOL://$dest_host/system" \
"Could not migrate $deploy_id to $dest_host"

View File

@ -17,7 +17,9 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
source $(dirname $0)/../../scripts_common.sh
file=$1
virsh --connect $LIBVIRT_URI restore $file
exec_and_log "virsh --connect $LIBVIRT_URI restore $file" \
"Could not restore from $file"

View File

@ -17,6 +17,7 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
file=$2
@ -26,4 +27,5 @@ if [ ! -f $file ]; then
chmod 666 $file
fi
virsh --connect $LIBVIRT_URI save $deploy_id $file
exec_and_log "virsh --connect $LIBVIRT_URI save $deploy_id $file" \
"Could not save $deploy_id to $file"

View File

@ -17,6 +17,7 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
source $(dirname $0)/../../scripts_common.sh
#------------------------------------------------------------------------------
# Wait the VM to shutdown TIMEOUT (xPOLL_INTERVAL) seconds.
@ -32,6 +33,7 @@ virsh --connect $LIBVIRT_URI shutdown $deploy_id
exit_code=$?
if [ "$exit_code" != "0" ]; then
error_message "Could not shutdown $deploy_id"
exit $exit_code
fi
@ -41,6 +43,7 @@ do
sleep $POLL_INTERVAL
if [ "$count" -gt "$TIMEOUT" ]
then
error_message "Timeout reached and VM $deploy_id is still alive"
echo "Timeout reached" >&2
exit 1
fi

View File

@ -17,7 +17,9 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
$XM_CANCEL $deploy_id
exec_and_log "$XM_CANCEL $deploy_id" \
"Could not destroy $deploy_id"

View File

@ -17,10 +17,13 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
function error_exit() {
exit_code=$1
message=$2
if [ "x$exit_code" != "x0" ]; then
error_message $message
exit $exit_code
fi
}
@ -32,7 +35,7 @@ cat > $domain
output=`$XM_CREATE $domain`
error_exit $?
error_exit $? "Unable to create domain"
domain_name=`echo $output | grep 'Started domain' | sed 's/^.*Started domain //' | tr -d '\n'`
@ -41,11 +44,13 @@ out=`grep -e '^\#O CPU_CREDITS =' < $domain`
if [ "x$?" = "x0" ]; then
credits=`echo $out | cut -d= -f2 | tr -d ' '`
log_debug "Credits set to $credits"
name=`grep -e '^name =' < $domain | cut -d= -f2 | tr -d ' ' | tr -d "\'"`
$XM_CREDITS -d $name -w $credits
error_exit $?
error_exit $? "Unable to set VM credits"
fi
echo $domain_name

View File

@ -17,8 +17,10 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
dest_host=$2
$XM_MIGRATE $deploy_id $dest_host
exec_and_log "$XM_MIGRATE $deploy_id $dest_host" \
"Could not migrate $deploy_id to $dest_host"

View File

@ -17,8 +17,10 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
file=$1
$XM_RESTORE $file
exec_and_log "$XM_RESTORE $file" \
"Could not restore from $file"

View File

@ -17,9 +17,10 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
file=$2
$XM_SAVE $deploy_id $file
exec_and_log "$XM_SAVE $deploy_id $file" \
"Could not save $deploy_id to $file"

View File

@ -17,6 +17,7 @@
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
source $(dirname $0)/../../scripts_common.sh
deploy_id=$1
@ -24,7 +25,8 @@ function gdm {
$XM_LIST | grep "$deploy_id "
}
$XM_SHUTDOWN $deploy_id || exit -1
exec_and_log "$XM_SHUTDOWN $deploy_id" \
"Could not shutdown $deploy_id"
OUT=$(gdm)