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

Merge branch 'feature-2092'

This commit is contained in:
Ruben S. Montero 2013-10-10 13:12:03 +02:00
commit d21c71f93c
7 changed files with 211 additions and 13 deletions

View File

@ -23,6 +23,7 @@
#include "Clusterable.h"
#include "ObjectCollection.h"
#include "NebulaLog.h"
#include "NebulaUtil.h"
using namespace std;
@ -85,6 +86,21 @@ public:
(state == MONITORING_DISABLED));
}
/**
* Check if host is hybrid
* @return true if the host is enabled
*/
bool isHybrid() const;
/**
* Return an element of the hypervisor array. The calling function
* must check that the index is valid.
*/
static const char * get_hybrid_hypervisor_by_id(int i)
{
return HYBRID_HYPERVISORS[i];
}
/**
* Disables the current host, it will not be monitored nor used by the
* scheduler
@ -459,6 +475,7 @@ private:
*/
ObjectCollection vm_collection;
// *************************************************************************
// Constructor
// *************************************************************************
@ -489,6 +506,17 @@ private:
static const char * monit_table;
/**
* Array containing the hybrid hypervisors, and counter. There is a
* correspondence between Host::HYBRID_HYPERVISOR and
* VirtualMachine::HYBRID_ATTRIBUTES. Attributes in HYBRID_ATTRIBUTES[i] are
* meant to be used in hosts reporting a a hypervisor of type
* HYBRID_HYPERVISOR[i]
*/
static const char * HYBRID_HYPERVISORS[];
static const int NUM_HYBRID_HYPERVISORS;
/**
* Execute an INSERT or REPLACE Sql query.
* @param db The SQL DB

View File

@ -67,12 +67,30 @@ public:
*/
void remove_all_except_restricted();
/**
* Returns the hypervisor name if the template is hybrid
* @param hypervisor the resulting hypervisor string
* @return true if any hybrid hypervisor attribute found, false otherwise
*/
bool get_hybrid_hypervisor(string& hypervisor) const;
private:
friend class VirtualMachinePool;
static vector<string> restricted_attributes;
/**
* Array containing the hybrid attributes, and counter. There is a
* correspondence between Host::HYBRID_HYPERVISOR and
* VirtualMachine::HYBRID_ATTRIBUTES. Attributes in HYBRID_ATTRIBUTES[i] are
* meant to be used in hosts reporting a a hypervisor of type
* HYBRID_HYPERVISOR[i]
*/
static const char * HYBRID_ATTRIBUTES[];
static const int NUM_HYBRID_ATTRIBUTES;
/**
* Stores the attributes as restricted, these attributes will be used in
* VirtualMachineTemplate::check

View File

@ -23,6 +23,13 @@
#include "Host.h"
#include "Nebula.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
const char * Host::HYBRID_HYPERVISORS[] = {"EC2"};
const int Host::NUM_HYBRID_HYPERVISORS = 1;
/* ************************************************************************ */
/* Host :: Constructor/Destructor */
/* ************************************************************************ */
@ -426,6 +433,29 @@ error_common:
return -1;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
bool Host::isHybrid() const
{
string hypervisor;
bool is_hybrid = false;
get_template_attribute("HYPERVISOR", hypervisor);
one_util::toupper(hypervisor);
for(int i=0; i < NUM_HYBRID_HYPERVISORS; i++)
{
if(hypervisor==HYBRID_HYPERVISORS[i])
{
is_hybrid = true;
break;
}
}
return is_hybrid;
}
/* ************************************************************************ */
/* Host :: Misc */
/* ************************************************************************ */

View File

@ -148,7 +148,11 @@ void TransferManager::trigger(Actions action, int _vid)
void TransferManager::do_action(const string &action, void * arg)
{
int vid;
int vid;
VirtualMachine * vm;
Host * host;
bool host_is_hybrid;
Nebula& nd = Nebula::instance();
if (arg == 0)
{
@ -159,41 +163,118 @@ void TransferManager::do_action(const string &action, void * arg)
delete static_cast<int *>(arg);
vm = vmpool->get(vid,true);
if (vm == 0)
{
return;
}
host = hpool->get(vm->get_hid(),true);
host_is_hybrid=host->isHybrid();
vm->unlock();
host->unlock();
if (action == "PROLOG")
{
prolog_action(vid);
if (host_is_hybrid)
{
(nd.get_lcm())->trigger(LifeCycleManager::PROLOG_SUCCESS,vid);
}
else
{
prolog_action(vid);
}
}
else if (action == "PROLOG_MIGR")
{
prolog_migr_action(vid);
if (host_is_hybrid)
{
(nd.get_lcm())->trigger(LifeCycleManager::PROLOG_SUCCESS,vid);
}
else
{
prolog_migr_action(vid);
}
}
else if (action == "PROLOG_RESUME")
{
prolog_resume_action(vid);
if (host_is_hybrid)
{
(nd.get_lcm())->trigger(LifeCycleManager::PROLOG_SUCCESS,vid);
}
else
{
prolog_resume_action(vid);
}
}
else if (action == "EPILOG")
{
epilog_action(vid);
if (host_is_hybrid)
{
(nd.get_lcm())->trigger(LifeCycleManager::EPILOG_SUCCESS,vid);
}
else
{
epilog_action(vid);
}
}
else if (action == "EPILOG_STOP")
{
epilog_stop_action(vid);
if (host_is_hybrid)
{
(nd.get_lcm())->trigger(LifeCycleManager::EPILOG_SUCCESS,vid);
}
else
{
epilog_stop_action(vid);
}
}
else if (action == "EPILOG_DELETE")
{
epilog_delete_action(vid);
if (host_is_hybrid)
{
(nd.get_lcm())->trigger(LifeCycleManager::EPILOG_SUCCESS,vid);
}
else
{
epilog_delete_action(vid);
}
}
else if (action == "EPILOG_DELETE_STOP")
{
epilog_delete_stop_action(vid);
if (host_is_hybrid)
{
(nd.get_lcm())->trigger(LifeCycleManager::EPILOG_SUCCESS,vid);
}
else
{
epilog_delete_stop_action(vid);
}
}
else if (action == "EPILOG_DELETE_PREVIOUS")
{
epilog_delete_previous_action(vid);
if (host_is_hybrid)
{
(nd.get_lcm())->trigger(LifeCycleManager::EPILOG_SUCCESS,vid);
}
else
{
epilog_delete_previous_action(vid);
}
}
else if (action == "EPILOG_DELETE_BOTH")
{
epilog_delete_both_action(vid);
if (host_is_hybrid)
{
(nd.get_lcm())->trigger(LifeCycleManager::EPILOG_SUCCESS,vid);
}
else
{
epilog_delete_both_action(vid);
}
}
else if (action == "CHECKPOINT")
{
@ -460,7 +541,6 @@ void TransferManager::prolog_action(int vid)
}
int uid = vm->get_uid();
vm->unlock();
User * user = Nebula::instance().get_upool()->get(uid, true);

View File

@ -1103,6 +1103,7 @@ int VirtualMachine::automatic_requirements(string& error_str)
ostringstream oss;
string requirements;
string cluster_id = "";
string hypervisor;
int incomp_id;
int rc;
@ -1181,9 +1182,21 @@ int VirtualMachine::automatic_requirements(string& error_str)
if ( !cluster_id.empty() )
{
oss.str("");
oss << "CLUSTER_ID = " << cluster_id;
}
if (static_cast<VirtualMachineTemplate*>(obj_template)->get_hybrid_hypervisor(hypervisor))
{
if ( !cluster_id.empty() )
{
oss << " || ";
}
oss << "HYPERVISOR = " << hypervisor;
}
if ( !cluster_id.empty() || !hypervisor.empty() )
{
obj_template->add("AUTOMATIC_REQUIREMENTS", oss.str());
}

View File

@ -15,12 +15,21 @@
/* -------------------------------------------------------------------------- */
#include "VirtualMachineTemplate.h"
#include "Host.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
vector<string> VirtualMachineTemplate::restricted_attributes;
/* ************************************************************************ */
/* Hybrid Attributes */
/* ************************************************************************ */
const char * VirtualMachineTemplate::HYBRID_ATTRIBUTES[] = {"EC2"};
const int VirtualMachineTemplate::NUM_HYBRID_ATTRIBUTES = 1;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -136,3 +145,21 @@ void VirtualMachineTemplate::remove_all_except_restricted()
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool VirtualMachineTemplate::get_hybrid_hypervisor(string& hypervisor) const
{
vector<const Attribute *> attrs;
bool found_it = false;
for(int i=0; i < NUM_HYBRID_ATTRIBUTES; i++)
{
if(get(HYBRID_ATTRIBUTES[i],attrs))
{
hypervisor = Host::get_hybrid_hypervisor_by_id(i);
found_it = true;
break;
}
}
return found_it;
}

View File

@ -18,7 +18,6 @@
#define TO_UPPER(S) transform(S.begin(),S.end(),S.begin(),(int(*)(int))toupper)
/* ************************************************************************ */
/* VMTemplate :: Constructor/Destructor */
/* ************************************************************************ */
@ -241,3 +240,6 @@ int VMTemplate::from_xml(const string& xml)
return 0;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */