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

Merge branch 'feature-307' into one-2.0

This commit is contained in:
Jaime Melis 2010-08-31 13:09:08 +02:00
commit b87eec2102
46 changed files with 940 additions and 793 deletions

View File

@ -34,11 +34,13 @@ public:
HostPool * _hpool,
time_t _timer_period,
time_t _monitor_period,
const string& _remotes_location,
vector<const Attribute*>& _mads)
:MadManager(_mads),
hpool(_hpool),
timer_period(_timer_period),
monitor_period(_monitor_period)
monitor_period(_monitor_period),
remotes_location(_remotes_location)
{
am.addListener(this);
};
@ -46,7 +48,7 @@ public:
~InformationManager(){};
/**
* This functions starts the associated listener thread, and creates a
* This functions starts the associated listener thread, and creates a
* new thread for the Information Manager. This thread will wait in
* an action loop till it receives ACTION_FINALIZE.
* @return 0 on success.
@ -63,12 +65,12 @@ public:
};
/**
*
*
*/
void load_mads(int uid=0);
/**
*
*
*/
void finalize()
{
@ -90,28 +92,33 @@ private:
* Timer period for the Virtual Machine Manager.
*/
time_t timer_period;
/**
* Host monitoring interval
*/
time_t monitor_period;
/**
* Path for the remote action programs
*/
string remotes_location;
/**
* Action engine for the Manager
*/
ActionManager am;
/**
* Function to execute the Manager action loop method within a new pthread
* Function to execute the Manager action loop method within a new pthread
* (requires C linkage)
*/
friend void * im_action_loop(void *arg);
/**
* Returns a pointer to a Information Manager MAD. The driver is
* Returns a pointer to a Information Manager MAD. The driver is
* searched by its name and owned by gwadmin with uid=0.
* @param name of the driver
* @return the VM driver owned by uid 0, with attribute "NAME" equal to
* @return the VM driver owned by uid 0, with attribute "NAME" equal to
* name or 0 in not found
*/
const InformationManagerDriver * get(

View File

@ -30,7 +30,7 @@ using namespace std;
/**
* InformationManagerDriver provides a base class to implement IM
* Drivers. This class implements the protocol and recover functions
* from the Mad interface. This class may be used to further specialize
* from the Mad interface. This class may be used to further specialize
* the IM driver.
*/
class InformationManagerDriver : public Mad
@ -42,35 +42,28 @@ public:
const map<string,string>& attrs,
bool sudo,
HostPool * pool):
Mad(userid,attrs,sudo),hpool(pool)
{}
;
Mad(userid,attrs,sudo),hpool(pool){};
virtual ~InformationManagerDriver()
{}
;
virtual ~InformationManagerDriver(){};
/**
* Implements the IM driver protocol.
* @param message the string read from the driver
*/
void protocol(
string& message);
void protocol(string& message);
/**
* TODO: What do we need here? just poll the Hosts to recover..
*/
void recover();
/**
* Sends a monitor request to the MAD: "MONITOR ID HOSTNAME -"
* @param oid the virtual machine id.
* @param host the hostname
* @param conf the filename of the deployment file
* @param update the remotes directory in host
*/
void monitor (
int oid,
const string& host) const;
void monitor(int oid, const string& host, bool update) const;
private:
/**
@ -78,8 +71,7 @@ private:
*/
HostPool * hpool;
friend class InformationManager;
friend class InformationManager;
};
/* -------------------------------------------------------------------------- */

View File

@ -232,11 +232,12 @@ private:
{
nebula_location = "/";
mad_location = "/usr/lib/one/mads/";
etc_location = "/etc/one/";
log_location = "/var/log/one/";
var_location = "/var/lib/one/";
hook_location= "/usr/share/one/hooks/";
mad_location = "/usr/lib/one/mads/";
etc_location = "/etc/one/";
log_location = "/var/log/one/";
var_location = "/var/lib/one/";
hook_location = "/usr/share/one/hooks/";
remotes_location = "/usr/lib/one/remotes/";
}
else
{
@ -247,11 +248,12 @@ private:
nebula_location += "/";
}
mad_location = nebula_location + "lib/mads/";
etc_location = nebula_location + "etc/";
log_location = nebula_location + "var/";
var_location = nebula_location + "var/";
hook_location= nebula_location + "share/hooks/";
mad_location = nebula_location + "lib/mads/";
etc_location = nebula_location + "etc/";
log_location = nebula_location + "var/";
var_location = nebula_location + "var/";
hook_location = nebula_location + "share/hooks/";
remotes_location = nebula_location + "lib/remotes/";
}
};
@ -348,6 +350,8 @@ private:
string log_location;
string var_location;
string hook_location;
string remotes_location;
string hostname;
// ---------------------------------------------------------------

View File

@ -151,10 +151,9 @@ ETC_DIRS="$ETC_LOCATION/im_kvm \
$ETC_LOCATION/im_xen \
$ETC_LOCATION/im_ec2 \
$ETC_LOCATION/im_eh \
$ETC_LOCATION/vmm_kvm \
$ETC_LOCATION/vmm_xen \
$ETC_LOCATION/vmm_ec2 \
$ETC_LOCATION/vmm_eh \
$ETC_LOCATION/vmm_sh \
$ETC_LOCATION/tm_nfs \
$ETC_LOCATION/tm_ssh \
$ETC_LOCATION/tm_dummy \
@ -164,7 +163,13 @@ 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/remotes/vmm/xen \
$LIB_LOCATION/remotes/vmm/kvm \
$LIB_LOCATION/ruby \
$LIB_LOCATION/ruby/OpenNebula \
$LIB_LOCATION/ruby/cloud/ \
@ -207,20 +212,25 @@ 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]="VMM_SH_KVM_SCRIPTS:$LIB_LOCATION/remotes/vmm/kvm"
INSTALL_FILES[11]="VMM_SH_XEN_SCRIPTS:$LIB_LOCATION/remotes/vmm/xen"
INSTALL_FILES[12]="NFS_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/nfs"
INSTALL_FILES[13]="SSH_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/ssh"
INSTALL_FILES[14]="DUMMY_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/dummy"
INSTALL_FILES[15]="LVM_TM_COMMANDS_LIB_FILES:$LIB_LOCATION/tm_commands/lvm"
INSTALL_FILES[16]="EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples"
INSTALL_FILES[17]="TM_EXAMPLE_SHARE_FILES:$SHARE_LOCATION/examples/tm"
INSTALL_FILES[18]="HOOK_SHARE_FILES:$SHARE_LOCATION/hooks"
INSTALL_FILES[19]="COMMON_CLOUD_LIB_FILES:$LIB_LOCATION/ruby/cloud"
INSTALL_FILES[20]="ECO_LIB_FILES:$LIB_LOCATION/ruby/cloud/econe"
INSTALL_FILES[21]="ECO_LIB_VIEW_FILES:$LIB_LOCATION/ruby/cloud/econe/views"
INSTALL_FILES[22]="ECO_BIN_FILES:$BIN_LOCATION"
INSTALL_FILES[23]="OCCI_LIB_FILES:$LIB_LOCATION/ruby/cloud/occi"
INSTALL_FILES[24]="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"
@ -231,24 +241,21 @@ INSTALL_OCCI_CLIENT_FILES[1]="OCCI_LIB_CLIENT_FILES:$LIB_LOCATION/ruby/cloud/occ
INSTALL_OCCI_CLIENT_FILES[2]="OCCI_BIN_CLIENT_FILES:$BIN_LOCATION"
INSTALL_ETC_FILES[0]="ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[1]="VMM_XEN_ETC_FILES:$ETC_LOCATION/vmm_xen"
INSTALL_ETC_FILES[2]="VMM_KVM_ETC_FILES:$ETC_LOCATION/vmm_kvm"
INSTALL_ETC_FILES[3]="VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2"
INSTALL_ETC_FILES[4]="VMM_EH_ETC_FILES:$ETC_LOCATION/vmm_eh"
INSTALL_ETC_FILES[5]="IM_XEN_ETC_FILES:$ETC_LOCATION/im_xen"
INSTALL_ETC_FILES[6]="IM_KVM_ETC_FILES:$ETC_LOCATION/im_kvm"
INSTALL_ETC_FILES[7]="IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2"
INSTALL_ETC_FILES[8]="IM_EH_ETC_FILES:$ETC_LOCATION/im_eh"
INSTALL_ETC_FILES[9]="TM_NFS_ETC_FILES:$ETC_LOCATION/tm_nfs"
INSTALL_ETC_FILES[10]="TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh"
INSTALL_ETC_FILES[11]="TM_DUMMY_ETC_FILES:$ETC_LOCATION/tm_dummy"
INSTALL_ETC_FILES[12]="TM_LVM_ETC_FILES:$ETC_LOCATION/tm_lvm"
INSTALL_ETC_FILES[13]="HM_ETC_FILES:$ETC_LOCATION/hm"
INSTALL_ETC_FILES[14]="AUTH_ETC_FILES:$ETC_LOCATION/auth"
INSTALL_ETC_FILES[15]="ECO_ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[16]="ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates"
INSTALL_ETC_FILES[17]="OCCI_ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[18]="OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates"
INSTALL_ETC_FILES[1]="VMM_EC2_ETC_FILES:$ETC_LOCATION/vmm_ec2"
INSTALL_ETC_FILES[2]="VMM_EH_ETC_FILES:$ETC_LOCATION/vmm_eh"
INSTALL_ETC_FILES[3]="VMM_SH_ETC_FILES:$ETC_LOCATION/vmm_sh"
INSTALL_ETC_FILES[4]="IM_EC2_ETC_FILES:$ETC_LOCATION/im_ec2"
INSTALL_ETC_FILES[5]="IM_EH_ETC_FILES:$ETC_LOCATION/im_eh"
INSTALL_ETC_FILES[6]="TM_NFS_ETC_FILES:$ETC_LOCATION/tm_nfs"
INSTALL_ETC_FILES[7]="TM_SSH_ETC_FILES:$ETC_LOCATION/tm_ssh"
INSTALL_ETC_FILES[8]="TM_DUMMY_ETC_FILES:$ETC_LOCATION/tm_dummy"
INSTALL_ETC_FILES[9]="TM_LVM_ETC_FILES:$ETC_LOCATION/tm_lvm"
INSTALL_ETC_FILES[10]="HM_ETC_FILES:$ETC_LOCATION/hm"
INSTALL_ETC_FILES[11]="AUTH_ETC_FILES:$ETC_LOCATION/auth"
INSTALL_ETC_FILES[14]="ECO_ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[15]="ECO_ETC_TEMPLATE_FILES:$ETC_LOCATION/ec2query_templates"
INSTALL_ETC_FILES[16]="OCCI_ETC_FILES:$ETC_LOCATION"
INSTALL_ETC_FILES[17]="OCCI_ETC_TEMPLATE_FILES:$ETC_LOCATION/occi_templates"
#-------------------------------------------------------------------------------
# Binary files, to be installed under $BIN_LOCATION
@ -310,16 +317,15 @@ RUBY_OPENNEBULA_LIB_FILES="src/oca/ruby/OpenNebula/Host.rb \
src/oca/ruby/OpenNebula/Cluster.rb \
src/oca/ruby/OpenNebula/ClusterPool.rb \
src/oca/ruby/OpenNebula/XMLUtils.rb"
#-------------------------------------------------------------------------------
# Driver executable files, to be installed under $LIB_LOCATION/mads
#-------------------------------------------------------------------------------
MADS_LIB_FILES="src/mad/sh/madcommon.sh \
src/tm_mad/tm_common.sh \
src/vmm_mad/xen/one_vmm_xen.rb \
src/vmm_mad/xen/one_vmm_xen \
src/vmm_mad/kvm/one_vmm_kvm.rb \
src/vmm_mad/kvm/one_vmm_kvm \
src/vmm_mad/sh/one_vmm_sh.rb \
src/vmm_mad/sh/one_vmm_sh \
src/vmm_mad/ec2/one_vmm_ec2.rb \
src/vmm_mad/ec2/one_vmm_ec2 \
src/vmm_mad/eh/one_vmm_eh.rb \
@ -338,14 +344,45 @@ 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
# VMM SH Driver KVM scripts, to be installed under $REMOTES_LOCATION/vmm/kvm
#-------------------------------------------------------------------------------
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"
VMM_SH_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 \
src/vmm_mad/remotes/kvm/poll \
src/vmm_mad/remotes/kvm/restore \
src/vmm_mad/remotes/kvm/save \
src/vmm_mad/remotes/kvm/shutdown"
#-------------------------------------------------------------------------------
# VMM SH Driver Xen scripts, to be installed under $REMOTES_LOCATION/vmm/xen
#-------------------------------------------------------------------------------
VMM_SH_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 \
src/vmm_mad/remotes/xen/poll \
src/vmm_mad/remotes/xen/restore \
src/vmm_mad/remotes/xen/save \
src/vmm_mad/remotes/xen/shutdown"
#-------------------------------------------------------------------------------
# Information Manager Probes, to be installed under $LIB_LOCATION/remotes
#-------------------------------------------------------------------------------
IM_PROBES_FILES="src/im_mad/remotes/run_probes"
IM_PROBES_COMMON_FILES="src/im_mad/remotes/common.d/architecture.sh \
src/im_mad/remotes/common.d/cpu.sh \
src/im_mad/remotes/common.d/name.sh"
IM_PROBES_XEN_FILES="src/im_mad/remotes/xen.d/xen.rb"
IM_PROBES_KVM_FILES="src/im_mad/remotes/kvm.d/kvm.rb"
#-------------------------------------------------------------------------------
# Transfer Manager commands, to be installed under $LIB_LOCATION/tm_commands
@ -390,37 +427,27 @@ ETC_FILES="share/etc/oned.conf \
#-------------------------------------------------------------------------------
# Virtualization drivers config. files, to be installed under $ETC_LOCATION
# - xen, $ETC_LOCATION/vmm_xen
# - kvm, $ETC_LOCATION/vmm_kvm
# - ec2, $ETC_LOCATION/vmm_ec2
# - eh, $ETC_LOCATION/vmm_eh
# - sh, $ETC_LOCATION/vmm_sh
#-------------------------------------------------------------------------------
VMM_XEN_ETC_FILES="src/vmm_mad/xen/vmm_xenrc \
src/vmm_mad/xen/vmm_xen.conf"
VMM_KVM_ETC_FILES="src/vmm_mad/kvm/vmm_kvmrc \
src/vmm_mad/kvm/vmm_kvm.conf"
VMM_EC2_ETC_FILES="src/vmm_mad/ec2/vmm_ec2rc \
src/vmm_mad/ec2/vmm_ec2.conf"
VMM_EH_ETC_FILES="src/vmm_mad/eh/vmm_ehrc \
src/vmm_mad/eh/vmm_eh.conf"
VMM_SH_ETC_FILES="src/vmm_mad/sh/vmm_shrc \
src/vmm_mad/sh/vmm_sh_kvm.conf \
src/vmm_mad/sh/vmm_sh_xen.conf"
#-------------------------------------------------------------------------------
# Information drivers config. files, to be installed under $ETC_LOCATION
# - xen, $ETC_LOCATION/im_xen
# - kvm, $ETC_LOCATION/im_kvm
# - ec2, $ETC_LOCATION/im_ec2
#-------------------------------------------------------------------------------
IM_XEN_ETC_FILES="src/im_mad/xen/im_xenrc \
src/im_mad/xen/im_xen.conf"
IM_KVM_ETC_FILES="src/im_mad/kvm/im_kvmrc \
src/im_mad/kvm/im_kvm.conf"
IM_EC2_ETC_FILES="src/im_mad/ec2/im_ec2rc \
src/im_mad/ec2/im_ec2.conf"

View File

@ -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" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
@ -147,20 +147,24 @@ IM_MAD = [
# type : driver type, supported drivers: xen, kvm, xml
#*******************************************************************************
#VM_MAD = [
# name = "vmm_xen",
# executable = "one_vmm_xen",
# default = "vmm_xen/vmm_xen.conf",
# type = "xen" ]
#-------------------------------------------------------------------------------
# KVM Virtualization Driver Manager sample configuration
#-------------------------------------------------------------------------------
VM_MAD = [
name = "vmm_kvm",
executable = "one_vmm_kvm",
default = "vmm_kvm/vmm_kvm.conf",
executable = "one_vmm_sh",
arguments = "kvm",
default = "vmm_sh/vmm_sh_kvm.conf",
type = "kvm" ]
#VM_MAD = [
# name = "vmm_xen",
# executable = "one_vmm_sh",
# arguments = "xen",
# default = "vmm_sh/vmm_sh_xen.conf",
# type = "xen" ]
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------

View File

@ -187,6 +187,9 @@ Commands:
* top (Lists hosts continuously)
onehost top
* sync (synchronizes probes with remote hosts)
onehost sync
EOT
def text_commands
@ -357,6 +360,14 @@ when "disable"
end
end
when "sync"
check_parameters("sync", 0)
if ONE_LOCATION
FileUtils.touch "#{ONE_LOCATION}/lib/remotes"
else
FileUtils.touch "/var/lib/one/remotes"
end
else
onehost_opts.print_help
exit -1

View File

@ -17,6 +17,9 @@
#include "InformationManager.h"
#include "NebulaLog.h"
#include <sys/types.h>
#include <sys/stat.h>
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -145,7 +148,7 @@ void InformationManager::timer_action()
istringstream iss;
// -------------- Max. number of hosts to monitor. ---------------------
int host_limit = 10;
int host_limit = 15;
mark = mark + timer_period;
@ -164,6 +167,16 @@ void InformationManager::timer_action()
thetime = time(0);
struct stat sb;
if (stat(remotes_location.c_str(), &sb) == -1)
{
sb.st_mtime = 0;
NebulaLog::log("InM",Log::ERROR,"Could not stat remotes directory, "
"will not update remotes.");
}
for(it=discovered_hosts.begin();it!=discovered_hosts.end();it++)
{
host = hpool->get(it->first,true);
@ -204,7 +217,15 @@ void InformationManager::timer_action()
}
else
{
imd->monitor(it->first,host->get_hostname());
bool update_remotes = false;
if ((sb.st_mtime != 0) &&
(sb.st_mtime > host->get_last_monitored()))
{
update_remotes = true;
}
imd->monitor(it->first,host->get_hostname(),update_remotes);
host->set_state(Host::MONITORING);
}

View File

@ -23,13 +23,13 @@
/* Driver ASCII Protocol Implementation */
/* ************************************************************************** */
void InformationManagerDriver::monitor (
const int oid,
const string& host) const
void InformationManagerDriver::monitor(int oid,
const string& host,
bool update) const
{
ostringstream os;
os << "MONITOR " << oid << " " << host << endl;
os << "MONITOR " << oid << " " << host << " " << update << endl;
write(os);
};
@ -39,8 +39,8 @@ void InformationManagerDriver::monitor (
void InformationManagerDriver::protocol(
string& message)
{
istringstream is(message);
{
istringstream is(message);
//stores the action name
string action;
//stores the action result
@ -51,7 +51,7 @@ void InformationManagerDriver::protocol(
ostringstream ess;
string hinfo;
Host * host;
// Parse the driver message
if ( is.good() )
@ -84,61 +84,61 @@ void InformationManagerDriver::protocol(
// -----------------------
// Protocol implementation
// -----------------------
if ( action == "MONITOR" )
{
host = hpool->get(id,true);
if ( host == 0 )
{
goto error_host;
}
if (result == "SUCCESS")
{
size_t pos;
{
size_t pos;
int rc;
ostringstream oss;
getline (is,hinfo);
for (pos=hinfo.find(',');pos!=string::npos;pos=hinfo.find(','))
{
hinfo.replace(pos,1,"\n");
}
hinfo += "\n";
oss << "Host " << id << " successfully monitored."; //, info: "<< hinfo;
NebulaLog::log("InM",Log::DEBUG,oss);
rc = host->update_info(hinfo);
if (rc != 0)
{
goto error_parse_info;
}
}
}
else
{
goto error_driver_info;
goto error_driver_info;
}
host->touch(true);
hpool->update(host);
host->unlock();
host->unlock();
}
else if (action == "LOG")
{
string info;
getline(is,info);
NebulaLog::log("InM",Log::INFO,info.c_str());
}
return;
error_driver_info:
@ -146,27 +146,27 @@ error_driver_info:
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);
error_common_info:
host->touch(false);
hpool->update(host);
host->unlock();
return;
error_host:
ess << "Could not get host " << id;
NebulaLog::log("InM",Log::ERROR,ess);
return;
error_parse:
ess << "Error while parsing driver message: " << message;

View File

@ -1,3 +0,0 @@
#!/bin/sh
echo ARCH=`uname -m`

View File

@ -1,9 +0,0 @@
#!/bin/sh
if [ -f /proc/cpuinfo ]; then
echo -n "MODELNAME=\""
grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | sed -e 's/^ *//' | sed -e 's/$/"/'
fi

View File

@ -1,5 +0,0 @@
#!/bin/sh
echo HOSTNAME=`uname -n`

View File

@ -47,7 +47,7 @@ export_rc_vars $DRIVERRC
# Go to var directory ONE_LOCATION/var or /var/lib/one
cd $VAR_LOCATION
LOG_FILE=$DRIVER_NAME
LOG_FILE=one_im_ssh_$DRIVER_NAME
# Execute the actual MAD
execute_mad $*

View File

@ -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,35 @@ 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)
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)
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 +85,10 @@ 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
remote_dir = "/tmp/one" if !remote_dir
im = InformationManager.new(im_conf, "#{remote_dir}/", 15)
hypervisor = ARGV[0]||''
im = InformationManager.new(remote_dir, hypervisor, 15)
im.start_driver

View File

@ -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

View File

@ -1,3 +1,5 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
@ -13,5 +15,5 @@
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
LIBVIRT_DEFAULT_URI="qemu:///system"
echo ARCH=`uname -m`

View File

@ -1,3 +1,5 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
@ -14,10 +16,10 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
#---------------------------------------------------------------------------
# Path to Xen utilities
#---------------------------------------------------------------------------
if [ -f /proc/cpuinfo ]; then
XENTOP_PATH="/usr/sbin/xentop"
echo -n "MODELNAME=\""
grep -m 1 "model name" /proc/cpuinfo | cut -d: -f2 | sed -e 's/^ *//' | sed -e 's/$/"/'
fi
XM_PATH="/usr/sbin/xm"

View File

@ -1,3 +1,5 @@
#!/bin/sh
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
# #
@ -14,9 +16,6 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
# To change the directory where the IM probes are copied on the remote node
# uncomment and change the path of IM_REMOTE_DIR
#
#IM_REMOTE_DIR=/tmp/ne_im_scripts
echo HOSTNAME=`uname -n`

44
src/im_mad/remotes/run_probes Executable file
View File

@ -0,0 +1,44 @@
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
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' ' '

View File

@ -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

View File

@ -64,6 +64,15 @@ void Nebula::start()
throw runtime_error("Could not load nebula configuration file.");
}
string config_fname = log_location + "config";
ofstream config_file(config_fname.c_str(), ios_base::trunc & ios_base::out);
if (config_file.fail() == false)
{
config_file << *nebula_configuration << endl;
config_file.close();
}
// -----------------------------------------------------------
// Log system
// -----------------------------------------------------------
@ -109,10 +118,9 @@ void Nebula::start()
NebulaLog::log("ONE",Log::INFO,"----------------------------------------");
os.str("");
os << "\n--------------------------------------------";
os << "\n----------------------------------\n";
os << *nebula_configuration;
os << "\n--------------------------------------------";
os << "----------------------------------";
NebulaLog::log("ONE",Log::INFO,os);
@ -345,7 +353,11 @@ void Nebula::start()
nebula_configuration->get("IM_MAD", im_mads);
im = new InformationManager(hpool,timer_period,monitor_period,im_mads);
im = new InformationManager(hpool,
timer_period,
monitor_period,
remotes_location,
im_mads);
}
catch (bad_alloc&)
{

View File

@ -367,7 +367,7 @@ string& Template::to_str(string& str) const
{
s = it->second->marshall(",");
os << endl << "\t" << it->first << separator << *s;
os << it->first << separator << *s << endl;
delete s;
}

View File

@ -1,221 +0,0 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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
if ENV["LIBVIRT_DEFAULT_URI"]
LIBVIRT_URI = ENV["LIBVIRT_DEFAULT_URI"]
else
LIBVIRT_URI = "qemu:///system"
end
$: << RUBY_LIB_LOCATION
require 'pp'
require "VirtualMachineDriver"
require 'rexml/document'
# ---------------------------------------------------------------------------- #
# The main class for the LibVirt driver #
# ---------------------------------------------------------------------------- #
class LibVirtDriver < VirtualMachineDriver
# ------------------------------------------------------------------------ #
# Libvirt commands constants #
# ------------------------------------------------------------------------ #
QEMU_PROTOCOL = "qemu+ssh"
LIBVIRT = {
:create => "virsh --connect #{LIBVIRT_URI} create",
:shutdown => "virsh --connect #{LIBVIRT_URI} shutdown",
:cancel => "virsh --connect #{LIBVIRT_URI} destroy",
:save => "virsh --connect #{LIBVIRT_URI} save",
:restore => "virsh --connect #{LIBVIRT_URI} restore",
:migrate => "virsh --connect #{LIBVIRT_URI} migrate --live",
:poll => "virsh --connect #{LIBVIRT_URI} dominfo",
:netstats => "virsh --connect #{LIBVIRT_URI} domifstat",
:dumpxml => "virsh --connect #{LIBVIRT_URI} dumpxml"
}
# ------------------------------------------------------------------------ #
# LibvirtDriver constructor #
# ------------------------------------------------------------------------ #
def initialize()
super(15,true)
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()
images_path = File.dirname remote_dfile
cmd = "mkdir -p #{images_path} && cat > #{remote_dfile} && " \
"#{LIBVIRT[:create]} #{remote_dfile}"
deploy_exe = SSHCommand.run("'#{cmd}'", host, log_method(id), domain)
if deploy_exe.code != 0
send_message(ACTION[:deploy],RESULT[:failure],id)
elsif deploy_exe.stdout.match(/^Domain (.*) created from .*$/)
send_message(ACTION[:deploy],RESULT[:success],id,$1)
else
send_message(ACTION[:deploy],RESULT[:failure],id,
"Domain id not found in #{LIBVIRT[:create]} output.")
end
end
# ------------------------------------------------------------------------ #
# Basic Domain Management Operations #
# ------------------------------------------------------------------------ #
def shutdown(id, host, deploy_id, not_used)
cmd = "#{LIBVIRT[:shutdown]} #{deploy_id} && " \
"c=0 && while [ $c -lt \"5\" ]; do " \
"if [ $(#{LIBVIRT[:poll]} #{deploy_id} > /dev/null 2>&1; echo $?) -ne \"0\" ]; " \
"then let 'c=c+1'; else c=0; fi; sleep 2; done; sleep 4"
execution=SSHCommand.run('bash', host, log_method(id), cmd)
if execution.code !=0
send_message(ACTION[:shutdown], RESULT[:failure], id)
else
send_message(ACTION[:shutdown], RESULT[:success], id)
end
end
def cancel(id, host, deploy_id, not_used)
ssh_action("#{LIBVIRT[:cancel]} #{deploy_id}", id, host, :cancel)
end
def save(id, host, deploy_id, file)
ssh_action("'touch #{file};#{LIBVIRT[:save]} #{deploy_id} #{file}'",id,host,:save)
end
def restore(id, host, deploy_id, file)
ssh_action("#{LIBVIRT[:restore]} #{file}", id, host, :restore)
end
def migrate(id, host, deploy_id, dest_host)
cmd = "#{LIBVIRT[:migrate]} #{deploy_id} "\
"#{QEMU_PROTOCOL}://#{dest_host}/system"
ssh_action(cmd, id, host, :migrate)
end
# ------------------------------------------------------------------------ #
# Get info from the Libvirt Domain #
# ------------------------------------------------------------------------ #
def poll(id, host, deploy_id, not_used)
exe = SSHCommand.run("#{LIBVIRT[:poll]} #{deploy_id}", host,
log_method(id))
exe2 = SSHCommand.run("#{LIBVIRT[:dumpxml]} #{deploy_id}", host,
log_method(id))
doc = REXML::Document.new(exe2.stdout)
interfaces = []
doc.elements.each('domain/devices/interface/target') do |ele|
interfaces << ele.attributes["dev"]
end
exe3 = SSHCommand.run("#{LIBVIRT[:netstats]} #{deploy_id} #{interfaces}", host,
log_method(id))
if exe.code != 0
result = :failure
info = "-"
if exe.stderr.match(/^error: failed to get domain '#{deploy_id}'/)
info = "#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:deleted]}"
result = :success
end
send_message(ACTION[:poll], RESULT[result], id, info)
return
end
info = ""
exe.stdout.each_line {|line|
columns=line.split(":").collect {|c| c.strip }
case columns[0]
when 'Used memory'
info << " #{POLL_ATTRIBUTE[:usedmemory]}=" \
<< (columns[1].to_i).to_s
when 'State'
case columns[1]
when "running","blocked","shutdown","dying"
state = VM_STATE[:active]
when "paused"
state = VM_STATE[:paused]
when "crashed"
state = VM_STATE[:error]
else
state = VM_STATE[:unknown]
end
info << " #{POLL_ATTRIBUTE[:state]}=#{state}"
end
}
exe3.stdout.each_line do |line|
columns=line.split(" ").collect {|c| c.strip }
case columns[1]
when 'rx_bytes'
info << " #{POLL_ATTRIBUTE[:netrx]}=" << (columns[2].to_i).to_s
when 'tx_bytes'
info << " #{POLL_ATTRIBUTE[:nettx]}=" << (columns[2].to_i).to_s
end
end
send_message(ACTION[:poll], RESULT[:success], id, info)
end
end
# ---------------------------------------------------------------------------- #
# LibvirtDriver Main program
# ---------------------------------------------------------------------------- #
kvm_driver = LibVirtDriver.new
kvm_driver.start_driver

23
src/vmm_mad/remotes/kvm/cancel Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
deploy_id=$1
virsh --connect $LIBVIRT_URI destroy $deploy_id

32
src/vmm_mad/remotes/kvm/deploy Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
domain=$1
mkdir -p `dirname $domain`
cat > $domain
data=`virsh --connect $LIBVIRT_URI create $domain`
if [ "x$?" = "x0" ]; then
echo $data | sed 's/Domain //' | sed 's/ created from .*$//'
else
exit -1
fi

View File

@ -0,0 +1,19 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
export LIBVIRT_URI=qemu:///system
export QEMU_PROTOCOL=qemu

24
src/vmm_mad/remotes/kvm/migrate Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
deploy_id=$1
dest_host=$2
virsh --connect $LIBVIRT_URI migrate --live $deploy_id $QEMU_PROTOCOL://$dest_host/system

53
src/vmm_mad/remotes/kvm/poll Executable file
View File

@ -0,0 +1,53 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
AWK_SCRIPT='
BEGIN { FS=":" };
$1=="Used memory" {
split($2, data, " ");
print "USEDMEMORY=" data[1]
};
$1=="State" {
vstat=$2;
gsub(" ", "", vstat);
if(vstat=="running" ||
vstat=="blocked" ||
vstat=="shutdown" ||
vstat=="dying")
state="a";
else if(vstat=="paused") state="p";
else if(vstat=="crashed") state="c";
else state="u";
print "STATUS=" state
}
'
deploy_id=$1
virsh_cmd="virsh --connect $LIBVIRT_URI --readonly dominfo $deploy_id"
awk_cmd="awk \'$AWK_SCRIPT\'"
info=`$virsh_cmd 2>/dev/null | awk "$AWK_SCRIPT"`
echo $info

23
src/vmm_mad/remotes/kvm/restore Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
file=$1
virsh --connect $LIBVIRT_URI restore $file

25
src/vmm_mad/remotes/kvm/save Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/kvmrc
deploy_id=$1
file=$2
touch $file
virsh --connect $LIBVIRT_URI save $deploy_id $file

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) #
@ -16,23 +16,33 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
if [ -z "${ONE_LOCATION}" ]; then
DRIVERRC=/etc/one/vmm_xen/vmm_xenrc
MADCOMMON=/usr/lib/one/mads/madcommon.sh
VAR_LOCATION=/var/lib/one
else
DRIVERRC=$ONE_LOCATION/etc/vmm_xen/vmm_xenrc
MADCOMMON=$ONE_LOCATION/lib/mads/madcommon.sh
VAR_LOCATION=$ONE_LOCATION/var
source $(dirname $0)/kvmrc
deploy_id=$1
POLL_INTERVAL=2
TIMEOUT=20
virsh --connect $LIBVIRT_URI shutdown $deploy_id
exit_code=$?
if [ "$exit_code" != "0" ]; then
exit $exit_code
fi
. $MADCOMMON
count=0
while [ $(virsh --connect $LIBVIRT_URI --readonly dominfo $deploy_id > /dev/null 2>&1; echo $?) = "0" ]
do
sleep $POLL_INTERVAL
if [ "$count" -gt "$TIMEOUT" ]
then
echo "Timeout reached" >&2
exit 1
fi
let count=count+$POLL_INTERVAL
done
# Export the vmm_mad specific rc
export_rc_vars $DRIVERRC
sleep 4
# Go to ONE_LOCATION
cd $VAR_LOCATION
# Execute the actual MAD
execute_mad $*
exit 0

23
src/vmm_mad/remotes/xen/cancel Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
deploy_id=$1
$XM_CANCEL $deploy_id

52
src/vmm_mad/remotes/xen/deploy Executable file
View File

@ -0,0 +1,52 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
function error_exit() {
exit_code=$1
if [ "x$exit_code" != "x0" ]; then
exit $exit_code
fi
}
domain=$1
mkdir -p `dirname $domain`
cat > $domain
output=`$XM_CREATE $domain`
error_exit $?
domain_name=`echo $output | grep 'Started domain' | sed 's/^.*Started domain //' | tr -d '\n'`
out=`grep -e '^\#O CPU_CREDITS =' < $domain`
if [ "x$?" != "x0" ]; then
credits=`echo $out | cut -d= -f2 | tr -d ' '`
name=`grep -e '^name =' < $domain | cut -d= -f2 | tr -d ' '`
$XM_CREDITS -d $name -w $credits
error_exit $?
fi
echo $domain_name

24
src/vmm_mad/remotes/xen/migrate Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
deploy_id=$1
dest_host=$2
$XM_MIGRATE $deploy_id $dest_host

60
src/vmm_mad/remotes/xen/poll Executable file
View File

@ -0,0 +1,60 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
INFO_MEM=4
INFO_CPU=3
INFO_NETTX=10
INFO_NETRX=11
INFO_STATE=1
AWK_SCRIPT='
{
mem=$5;
cpu=$4;
nettx=$11;
netrx=$12;
stat=$2
gsub("-", "", stat);
if(stat=="r" ||
stat=="b" ||
stat=="s" ||
stat=="d")
state="a";
else if(stat=="p") state="a";
else if(stat=="c") state="c";
else state="u";
print "USEDMEMORY=" mem " USEDCPU=" cpu " NETTX=" nettx " NETRX=" netrx " STATE=" state
}
'
function get_info() {
$XM_POLL | egrep "^ *(migrating-)?$1 " | tail -1 | sed 's/^ *//' | sed 's/no limit/no_limit/'
}
info=`get_info $1 2>/dev/null | awk "$AWK_SCRIPT"`
echo $info

24
src/vmm_mad/remotes/xen/restore Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
file=$1
$XM_RESTORE $file

25
src/vmm_mad/remotes/xen/save Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
deploy_id=$1
file=$2
$XM_SAVE $deploy_id $file

View File

@ -0,0 +1,42 @@
#!/bin/bash -e
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
source $(dirname $0)/xenrc
deploy_id=$1
function gdm {
$XM_LIST | grep "$deploy_id "
}
$XM_SHUTDOWN $deploy_id || exit -1
OUT=$(gdm)
while [ -n "$OUT" -a $(echo $OUT | awk '{print $5}') != "---s--" ]; do
sleep 1
OUT=$(gdm)
done
OUT=$(gdm)
if [ -n "$OUT" ]; then
$XM_CANCEL "$deploy_id"
fi
sleep 2

View File

@ -0,0 +1,28 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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. #
#--------------------------------------------------------------------------- #
export XM_PATH="/usr/sbin/xm"
export XM_CANCEL="sudo $XM_PATH destroy"
export XM_CREATE="sudo $XM_PATH create"
export XM_CREDITS="sudo $XM_PATH sched-cred"
export XM_MIGRATE="sudo $XM_PATH migrate -l"
export XM_SAVE="sudo $XM_PATH save"
export XM_RESTORE="sudo $XM_PATH restore"
export XM_LIST="sudo $XM_PATH list"
export XM_SHUTDOWN="sudo $XM_PATH shutdown"
export XM_POLL="sudo /usr/sbin/xentop -bi2"

View File

@ -17,11 +17,11 @@
#--------------------------------------------------------------------------- #
if [ -z "${ONE_LOCATION}" ]; then
DRIVERRC=/etc/one/vmm_kvm/vmm_kvmrc
DRIVERRC=/etc/one/vmm_sh/vmm_shrc
MADCOMMON=/usr/lib/one/mads/madcommon.sh
VAR_LOCATION=/var/lib/one
else
DRIVERRC=$ONE_LOCATION/etc/vmm_kvm/vmm_kvmrc
DRIVERRC=$ONE_LOCATION/etc/vmm_sh/vmm_shrc
MADCOMMON=$ONE_LOCATION/lib/mads/madcommon.sh
VAR_LOCATION=$ONE_LOCATION/var
fi

128
src/vmm_mad/sh/one_vmm_sh.rb Executable file
View File

@ -0,0 +1,128 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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"
# ---------------------------------------------------------------------------- #
# The main class for the Sh driver #
# ---------------------------------------------------------------------------- #
class ShDriver < VirtualMachineDriver
# ------------------------------------------------------------------------ #
# ShDriver constructor #
# ------------------------------------------------------------------------ #
def initialize(hypervisor, remote_dir)
super(15,true)
@remote_dir = remote_dir
@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()
cmd = "#{@remote_dir}/vmm/#{@hypervisor}/deploy #{remote_dfile}"
deploy_exe = SSHCommand.run(cmd, host, log_method(id), domain)
if deploy_exe.code != 0
send_message(ACTION[:deploy],RESULT[:failure],id)
else
send_message(ACTION[:deploy],RESULT[:success],id,deploy_exe.stdout)
end
end
# ------------------------------------------------------------------------ #
# Basic Domain Management Operations #
# ------------------------------------------------------------------------ #
def shutdown(id, host, deploy_id, not_used)
ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/shutdown #{deploy_id}",
id, host, :shutdown)
end
def cancel(id, host, deploy_id, not_used)
ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/cancel #{deploy_id}",
id, host, :cancel)
end
def save(id, host, deploy_id, file)
ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/save #{deploy_id} #{file}",
id, host, :save)
end
def restore(id, host, deploy_id, file)
ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/restore #{file}",
id, host, :restore)
end
def migrate(id, host, deploy_id, dest_host)
ssh_action("#{@remote_dir}/vmm/#{@hypervisor}/migrate #{deploy_id} #{dest_host}",
id, host, :migrate)
end
def poll(id, host, deploy_id, not_used)
cmd = "#{@remote_dir}/vmm/#{@hypervisor}/poll #{deploy_id}"
poll_exe = SSHCommand.run(cmd, host, log_method(id))
if poll_exe.code != 0
send_message(ACTION[:poll],RESULT[:failure],id)
else
send_message(ACTION[:poll],RESULT[:success],id,poll_exe.stdout)
end
end
end
# ---------------------------------------------------------------------------- #
# ShDriver Main program
# ---------------------------------------------------------------------------- #
remote_dir = ENV["VMM_REMOTE_DIR"]
remote_dir = "/tmp/one" if !remote_dir
hypervisor = ARGV[0]
sh_driver = ShDriver.new(hypervisor, remote_dir)
sh_driver.start_driver

View File

@ -14,8 +14,7 @@
# limitations under the License. #
#--------------------------------------------------------------------------- #
# To change the directory where the IM probes are copied on the remote node
# To change the directory where the VMM scripts are copied on the remote node
# uncomment and change the path of IM_REMOTE_DIR
#
#IM_REMOTE_DIR=/tmp/ne_im_scripts
#VMM_REMOTE_DIR=/tmp/ne_im_scripts

View File

@ -1,227 +0,0 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2010, 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"]
XENTOP_PATH = ENV["XENTOP_PATH"]
XM_PATH = ENV["XM_PATH"]
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 'pp'
require "VirtualMachineDriver"
# ---------------------------------------------------------------------------- #
# The main class for the Xen driver #
# ---------------------------------------------------------------------------- #
class XenDriver < VirtualMachineDriver
# ------------------------------------------------------------------------ #
# Xen commands constants #
# ------------------------------------------------------------------------ #
XEN = {
:create => "sudo #{XM_PATH} create",
:shutdown => "sudo #{XM_PATH} shutdown",
:cancel => "sudo #{XM_PATH} destroy",
:save => "sudo #{XM_PATH} save",
:restore => "sudo #{XM_PATH} restore",
:migrate => "sudo #{XM_PATH} migrate -l",
:poll => "sudo #{XENTOP_PATH} -bi2",
:credits => "sudo #{XM_PATH} sched-cred",
:list => "sudo #{XM_PATH} list"
}
XEN_INFO = {
:name => 0,
:state => 1,
:cpu_sec => 2,
:cpu_per => 3,
:mem => 4,
:mem_per => 5,
:maxmem => 6,
:maxmem_per => 7,
:vcpus => 8,
:nets => 9,
:nettx => 10,
:netrx => 11,
:vbds => 12,
:vbd_oo => 13,
:vbd_rd => 14,
:vbd_wr => 15,
:ssid => 16
}
# ------------------------------------------------------------------------ #
# XenDriver constructor #
# ------------------------------------------------------------------------ #
def initialize()
super(15,true)
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()
cmd = "cat > #{remote_dfile} && #{XEN[:create]} #{remote_dfile}"
values = domain.scan(/^#O (.*?) = (.*)$/)
credits = values.assoc("CPU_CREDITS")
if domain.match(/^name = '(.*?)'$/) && credits
cmd << " && #{XEN[:credits]} -d #{$1} -w #{credits[1]}"
end
deploy_exe = SSHCommand.run("'#{cmd}'", host, log_method(id), domain)
if deploy_exe.code != 0
send_message(ACTION[:deploy],RESULT[:failure],id)
elsif deploy_exe.stdout.match(/^Started domain (.*)/)
send_message(ACTION[:deploy],RESULT[:success],id,$1)
else
send_message(ACTION[:deploy],RESULT[:failure],id,
"Domain id not found in #{XEN[:create]} output.")
end
end
# ------------------------------------------------------------------------ #
# Basic Domain Management Operations #
# ------------------------------------------------------------------------ #
def shutdown(id, host, deploy_id, not_used)
cmd=<<-EOS
function gdm {
#{XEN[:list]} | grep '#{deploy_id}\\>'
}
#{XEN[:shutdown]} #{deploy_id} || exit -1
OUT=$(gdm)
while [ -n "$OUT" -a $(echo $OUT | awk '{print $5}') != "---s--" ]; do
sleep 1
OUT=$(gdm)
done
OUT=$(gdm)
if [ -n "$OUT" ]; then
#{XEN[:cancel]} '#{deploy_id}'
fi
sleep 2
EOS
execution=SSHCommand.run('bash', host, log_method(id), cmd)
if execution.code !=0
send_message(ACTION[:shutdown], RESULT[:failure], id)
else
send_message(ACTION[:shutdown], RESULT[:success], id)
end
end
def cancel(id, host, deploy_id, not_used)
ssh_action("#{XEN[:cancel]} #{deploy_id}", id, host, :cancel)
end
def save(id, host, deploy_id, file)
ssh_action("#{XEN[:save]} #{deploy_id} #{file}", id, host, :save)
end
def restore(id, host, deploy_id, file)
ssh_action("#{XEN[:restore]} #{file}", id, host, :restore)
end
def migrate(id, host, deploy_id, dest_host)
ssh_action("#{XEN[:migrate]} #{deploy_id} #{dest_host}",
id, host, :migrate)
end
# ------------------------------------------------------------------------ #
# Get info from the Xen Domain. #
# ------------------------------------------------------------------------ #
def poll(id, host, deploy_id, not_used)
exe = SSHCommand.run("#{XEN[:poll]} #{deploy_id}", host, log_method(id))
if exe.code != 0
send_message(ACTION[:poll], RESULT[:failure], id, "-")
return
end
dinfo = exe.stdout.split(/$/).select { |l|
l.match(/^ *(migrating-)?#{deploy_id} /) }[-1]
if !dinfo
send_message(ACTION[:poll], RESULT[:success], id,
"#{POLL_ATTRIBUTE[:state]}=#{VM_STATE[:deleted]}")
return
end
dinfo.gsub!("no limit", "no_limit")
data = dinfo.split
info = "#{POLL_ATTRIBUTE[:usedmemory]}=#{data[XEN_INFO[:mem]]} " \
"#{POLL_ATTRIBUTE[:usedcpu]}=#{data[XEN_INFO[:cpu_per]]} " \
"#{POLL_ATTRIBUTE[:nettx]}=#{data[XEN_INFO[:nettx]]} " \
"#{POLL_ATTRIBUTE[:netrx]}=#{data[XEN_INFO[:netrx]]} "
case data[XEN_INFO[:state]].gsub!("-", "")
when "r", "b", "s","d"
state = VM_STATE[:active]
when "p"
state = VM_STATE[:paused]
when "c"
state = VM_STATE[:error]
else
state = VM_STATE[:unknown]
end
info << " #{POLL_ATTRIBUTE[:state]}=#{state}"
send_message(ACTION[:poll], RESULT[:success], id, info)
end
end
# ---------------------------------------------------------------------------- #
# XenDriver Main program #
# ---------------------------------------------------------------------------- #
xen_driver = XenDriver.new
xen_driver.start_driver