1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

bug #4164: Moved imported_vm_action logic to the driver class. Add

defaults for well-known drivers
This commit is contained in:
Ruben S. Montero 2015-11-20 15:44:37 +01:00
parent 46b723c815
commit 57ca5f414b
8 changed files with 165 additions and 60 deletions

View File

@ -528,37 +528,6 @@ public:
return -1;
};
/**
* Gets a VM_MAD configuration attribute
*/
int get_vm_conf_attribute(
const string& vm_mad_name,
const VectorAttribute* &value) const
{
vector<const Attribute*>::const_iterator it;
vector<const Attribute*> values;
nebula_configuration->Template::get("VM_MAD", values);
for (it = values.begin(); it != values.end(); it ++)
{
value = dynamic_cast<const VectorAttribute*>(*it);
if (value == 0)
{
continue;
}
if (value->vector_value("NAME") == vm_mad_name)
{
return 0;
}
}
value = 0;
return -1;
};
/**
* Gets an XML document with all of the configuration attributes
* @return the XML

View File

@ -167,6 +167,13 @@ namespace one_util
* @return 0 on match, another value otherwise
*/
int regex_match(const char *pattern, const char *subject);
/**
* Trim an string using the isspace function
* @param the string
* @return trimed string
*/
std::string trim(const std::string& str);
};
#endif /* _NEBULA_UTIL_H_ */

View File

@ -107,6 +107,24 @@ public:
*/
int load_mads(int uid);
/**
* Check if action is supported for imported VMs
* @param mad name of the driver
* @param action
* @return True if it is supported
*/
bool is_imported_action_supported(const string& mad,History::VMAction action)
{
const VirtualMachineManagerDriver * vmd = get(mad);
if ( vmd == 0 )
{
return false;
}
return vmd->is_imported_action_supported(action);
}
private:
/**
* Thread id for the Virtual Machine Manager

View File

@ -23,6 +23,7 @@
#include "Mad.h"
#include "VirtualMachinePool.h"
#include "History.h"
using namespace std;
@ -83,6 +84,16 @@ public:
*/
static void process_poll(VirtualMachine* vm, const string &monitor_str);
/**
* Check if action is supported for imported VMs
* @param action
* @return True if it is supported
*/
bool is_imported_action_supported(History::VMAction action) const
{
return (imported_vm_actions && (1 << static_cast<int>(action))) != 0;
}
protected:
/**
* Gets a configuration attr from driver configuration file (single
@ -131,6 +142,12 @@ private:
*/
Template driver_conf;
/**
* List of available actions for imported VMs. Each bit is an action
* as defined in History.h, 1=supported and 0=not supported
*/
long long imported_vm_actions;
/**
* Pointer to the Virtual Machine Pool, to access VMs
*/

View File

@ -411,7 +411,6 @@ IM_MAD = [
#
# imported_vms_actions : comma-separated list of actions supported
# for imported vms. The available actions are:
#
# migrate
# live-migrate
# shutdown
@ -464,7 +463,9 @@ VM_MAD = [
arguments = "-t 15 -r 0 -i kvm",
default = "vmm_exec/vmm_exec_kvm.conf",
type = "kvm",
imported_vms_actions = "shutdown,shutdown-hard,hold,release,suspend,resume,delete,reboot,reboot-hard,resched,unresched,disk-attach,disk-detach,nic-attach,nic-detach,snap-create,snap-delete"
imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
resume, delete, reboot, reboot-hard, resched, unresched, disk-attach,
disk-detach, nic-attach, nic-detach, snap-create, snap-delete"
]
#-------------------------------------------------------------------------------
@ -490,7 +491,9 @@ VM_MAD = [
# arguments = "-t 15 -r 0 xen3",
# default = "vmm_exec/vmm_exec_xen3.conf",
# type = "xen",
# imported_vms_actions = "shutdown,shutdown-hard,hold,release,suspend,resume,delete,reboot,reboot-hard,resched,unresched,disk-attach,disk-detach,nic-attach,nic-detach,snap-create,snap-delete"
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, disk-attach,
# disk-detach, nic-attach, nic-detach, snap-create, snap-delete"
#]
#
# Driver for Xen 4.x
@ -500,7 +503,9 @@ VM_MAD = [
# arguments = "-t 15 -r 0 xen4",
# default = "vmm_exec/vmm_exec_xen4.conf",
# type = "xen",
# imported_vms_actions = "shutdown,shutdown-hard,hold,release,suspend,resume,delete,reboot,reboot-hard,resched,unresched,disk-attach,disk-detach,nic-attach,nic-detach,snap-create,snap-delete"
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, disk-attach,
# disk-detach, nic-attach, nic-detach, snap-create, snap-delete"
#]
#
#-------------------------------------------------------------------------------
@ -520,7 +525,9 @@ VM_MAD = [
# arguments = "-t 15 -r 0 vmware -s sh",
# default = "vmm_exec/vmm_exec_vmware.conf",
# type = "vmware",
# imported_vms_actions = "shutdown,shutdown-hard,hold,release,suspend,resume,delete,reboot,reboot-hard,resched,unresched,poweroff,poweroff-hard,disk-attach,disk-detach,nic-attach,nic-detach,snap-create,snap-delete"
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, disk-attach,
# disk-detach, nic-attach, nic-detach, snap-create, snap-delete"
# ]
#-------------------------------------------------------------------------------
@ -539,7 +546,10 @@ VM_MAD = [
# arguments = "-p -t 15 -r 0 vcenter -s sh",
# default = "vmm_exec/vmm_exec_vcenter.conf",
# type = "xml",
# imported_vms_actions = "shutdown,shutdown-hard,hold,release,suspend,resume,delete,reboot,reboot-hard,resched,unresched,poweroff,poweroff-hard,disk-attach,disk-detach,nic-attach,nic-detach,snap-create,snap-delete"
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
# poweroff-hard, disk-attach, disk-detach, nic-attach, nic-detach,
# snap-create, snap-delete"
#]
#-------------------------------------------------------------------------------
@ -553,7 +563,10 @@ VM_MAD = [
# executable = "one_vmm_sh",
# arguments = "-t 15 -r 0 ec2",
# type = "xml",
# imported_vms_actions = "shutdown,shutdown-hard,hold,release,suspend,resume,delete,reboot,reboot-hard,resched,unresched,poweroff,poweroff-hard,disk-attach,disk-detach,nic-attach,nic-detach,snap-create,snap-delete"
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
# poweroff-hard, disk-attach, disk-detach, nic-attach, nic-detach,
# snap-create, snap-delete"
#]
#-------------------------------------------------------------------------------
@ -567,7 +580,10 @@ VM_MAD = [
# executable = "one_vmm_sh",
# arguments = "-t 15 -r 0 sl",
# type = "xml",
# imported_vms_actions = "shutdown,shutdown-hard,hold,release,suspend,resume,delete,reboot,reboot-hard,resched,unresched,poweroff,poweroff-hard,disk-attach,disk-detach,nic-attach,nic-detach,snap-create,snap-delete"
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
# poweroff-hard, disk-attach, disk-detach, nic-attach, nic-detach,
# snap-create, snap-delete"
#]
#-------------------------------------------------------------------------------
@ -581,7 +597,10 @@ VM_MAD = [
# executable = "one_vmm_sh",
# arguments = "-t 15 -r 0 az",
# type = "xml",
# imported_vms_actions = "shutdown,shutdown-hard,hold,release,suspend,resume,delete,reboot,reboot-hard,resched,unresched,poweroff,poweroff-hard,disk-attach,disk-detach,nic-attach,nic-detach,snap-create,snap-delete"
# imported_vms_actions = "shutdown, shutdown-hard, hold, release, suspend,
# resume, delete, reboot, reboot-hard, resched, unresched, poweroff,
# poweroff-hard, disk-attach, disk-detach, nic-attach, nic-detach,
# snap-create, snap-delete"
#]
#-------------------------------------------------------------------------------

View File

@ -283,3 +283,26 @@ int one_util::regex_match(const char *pattern, const char *subject)
return rc;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static bool not_space(int c)
{
return std::isspace(c) == 0;
};
std::string one_util::trim(const std::string& str)
{
std::string::const_iterator wfirst;
std::string::const_reverse_iterator rwlast;
wfirst = find_if(str.begin(), str.end(), not_space);
rwlast = find_if(str.rbegin(),str.rend(),not_space);
std::string::const_iterator wlast(rwlast.base());
std::string tstr(wfirst, wlast);
return tstr;
}

View File

@ -2399,31 +2399,14 @@ bool VirtualMachine::is_imported() const
bool VirtualMachine::is_imported_action_supported(History::VMAction action) const
{
const VectorAttribute* vatt;
string action_st;
string action_list;
vector<string> actions;
int rc;
if (!hasHistory())
{
return true;
}
rc = Nebula::instance().get_vm_conf_attribute(get_vmm_mad(), vatt);
if (rc != 0)
{
return false;
}
vatt->vector_value("IMPORTED_VMS_ACTIONS", action_list);
VirtualMachineManager * vmm = Nebula::instance().get_vmm();
actions = one_util::split(action_list, ',');
action_st = History::action_to_str(action);
return (find(actions.begin(), actions.end(), action_st) != actions.end());
return vmm->is_imported_action_supported(get_vmm_mad(), action);
}
/* -------------------------------------------------------------------------- */

View File

@ -27,7 +27,8 @@ VirtualMachineManagerDriver::VirtualMachineManagerDriver(
const map<string,string>& attrs,
bool sudo,
VirtualMachinePool * pool):
Mad(userid,attrs,sudo),driver_conf(true),vmpool(pool)
Mad(userid,attrs,sudo), driver_conf(true), imported_vm_actions(0),
vmpool(pool)
{
map<string,string>::const_iterator it;
char * error_msg = 0;
@ -72,6 +73,74 @@ VirtualMachineManagerDriver::VirtualMachineManagerDriver(
NebulaLog::log("VMM", Log::ERROR, oss);
}
}
it = attrs.find("IMPORTED_VMS_ACTIONS");
if (it != attrs.end())
{
vector<string> actions;
vector<string>::iterator vit;
string action;
History::VMAction id;
actions = one_util::split(it->second, ',');
for (vit = actions.begin() ; vit != actions.end() ; ++vit)
{
action = one_util::trim(*vit);
if ( History::action_from_str(action, id) != 0 )
{
NebulaLog::log("VMM", Log::ERROR, "Wrong action: " + action);
continue;
}
imported_vm_actions += 1 << static_cast<int>(id);
}
}
else
{
NebulaLog::log("VMM", Log::INFO, "Using default imported VMs actions");
it = attrs.find("NAME");
if (it != attrs.end())
{
if ( it->second == "kvm" )
{
imported_vm_actions = 132623768;
}
else if ( it->second == "xen3" )
{
imported_vm_actions = 132623768;
}
else if ( it->second == "xen" )
{
imported_vm_actions = 132623768;
}
else if ( it->second == "vmware" )
{
imported_vm_actions = 132623768;
}
else if ( it->second == "vcenter" )
{
imported_vm_actions = 134196632;
}
else if ( it->second == "ec2" )
{
imported_vm_actions = 134196632;
}
else if ( it->second == "az" )
{
imported_vm_actions = 134196632;
}
else if ( it->second == "sl" )
{
imported_vm_actions = 134196632;
}
}
}
}
/* -------------------------------------------------------------------------- */