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

Feature #1112: Add cluster attribute to Host

This commit is contained in:
Carlos Martín 2012-02-24 18:53:18 +01:00
parent 68fd921150
commit 2580411adf
5 changed files with 93 additions and 10 deletions

View File

@ -166,6 +166,28 @@ public:
return last_monitored;
};
/**
* Changes the cluster this host belongs to
*
* @param _cluster_id Id of the new cluster
* @param _cluster Name of the new cluter
*/
void set_cluster(int _cluster_id, const string& _cluster)
{
cluster_id = _cluster_id;
cluster = _cluster;
};
/**
* Returns the cluster ID
*
* @return The cluster ID
*/
int get_cluster_id()
{
return cluster_id;
};
// ------------------------------------------------------------------------
// Share functions
// ------------------------------------------------------------------------
@ -322,6 +344,12 @@ private:
*/
time_t last_monitored;
int cluster_id;
/**
* Name of the cluster this host belongs to.
*/
string cluster;
// -------------------------------------------------------------------------
// Host Attributes
// -------------------------------------------------------------------------
@ -334,11 +362,13 @@ private:
// Constructor
// *************************************************************************
Host(int id=-1,
const string& hostname="",
const string& im_mad_name="",
const string& vmm_mad_name="",
const string& vnm_mad_name="");
Host(int id,
const string& hostname,
const string& im_mad_name,
const string& vmm_mad_name,
const string& vnm_mad_name,
int cluster_id,
const string& cluster_name);
virtual ~Host();

View File

@ -53,6 +53,8 @@ public:
const string& im_mad_name,
const string& vmm_mad_name,
const string& vnm_mad_name,
int cluster_id,
const string& cluster_name,
string& error_str);
/**
@ -202,7 +204,7 @@ private:
*/
PoolObjectSQL * create()
{
return new Host;
return new Host(-1,"","","","",-1,"");
};
/**

View File

@ -33,13 +33,17 @@ Host::Host(
const string& _hostname,
const string& _im_mad_name,
const string& _vmm_mad_name,
const string& _vnm_mad_name):
const string& _vnm_mad_name,
int _cluster_id,
const string& _cluster_name):
PoolObjectSQL(id,HOST,_hostname,-1,-1,"","",table),
state(INIT),
im_mad_name(_im_mad_name),
vmm_mad_name(_vmm_mad_name),
vnm_mad_name(_vnm_mad_name),
last_monitored(0)
last_monitored(0),
cluster_id(_cluster_id),
cluster(_cluster_name)
{
obj_template = new HostTemplate;
}
@ -204,6 +208,8 @@ string& Host::to_xml(string& xml) const
"<VM_MAD>" << vmm_mad_name << "</VM_MAD>" <<
"<VN_MAD>" << vnm_mad_name << "</VN_MAD>" <<
"<LAST_MON_TIME>" << last_monitored << "</LAST_MON_TIME>" <<
"<CLUSTER_ID>" << cluster_id << "</CLUSTER_ID>" <<
"<CLUSTER>" << cluster << "</CLUSTER>" <<
host_share.to_xml(share_xml) <<
obj_template->to_xml(template_xml) <<
"</HOST>";
@ -237,6 +243,9 @@ int Host::from_xml(const string& xml)
rc += xpath(last_monitored, "/HOST/LAST_MON_TIME", 0);
rc += xpath(cluster_id, "/HOST/CLUSTER_ID", -1);
rc += xpath(cluster, "/HOST/CLUSTER", "not_found");
state = static_cast<HostState>( int_state );
// Set the owner and group to oneadmin

View File

@ -25,6 +25,7 @@
#include "HostHook.h"
#include "NebulaLog.h"
#include "GroupPool.h"
#include "Nebula.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -153,11 +154,18 @@ int HostPool::allocate (
const string& im_mad_name,
const string& vmm_mad_name,
const string& vnm_mad_name,
int cluster_id,
const string& cluster_name,
string& error_str)
{
Nebula& nd = Nebula::instance();
Host * host;
ostringstream oss;
ClusterPool * clpool;
Cluster * cluster;
if ( hostname.empty() )
{
goto error_name;
@ -192,12 +200,39 @@ int HostPool::allocate (
// Build a new Host object
host = new Host(-1, hostname, im_mad_name, vmm_mad_name, vnm_mad_name);
host = new Host(
-1,
hostname,
im_mad_name,
vmm_mad_name,
vnm_mad_name,
cluster_id,
cluster_name);
// Insert the Object in the pool
*oid = PoolSQL::allocate(host, error_str);
if ( *oid < 0 )
{
return *oid;
}
// Add Host to Cluster
clpool = nd.get_clpool();
cluster = clpool->get(cluster_id, true);
if( cluster == 0 )
{
return -1;
}
cluster->add_host(*oid);
clpool->update(cluster);
cluster->unlock();
return *oid;

View File

@ -317,9 +317,16 @@ int HostAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
string vmm_mad = xmlrpc_c::value_string(paramList.getString(3));
string vnm_mad = xmlrpc_c::value_string(paramList.getString(4));
int rc;
// TODO: include another int parameter for the cluster?
int cluster_id = ClusterPool::DEFAULT_CLUSTER_ID;
string cluster_name = ClusterPool::DEFAULT_CLUSTER_NAME;
HostPool * hpool = static_cast<HostPool *>(pool);
return hpool->allocate(&id, host, im_mad, vmm_mad, vnm_mad, error_str);
return hpool->allocate(&id, host, im_mad, vmm_mad, vnm_mad,
cluster_id, cluster_name, error_str);
}
/* -------------------------------------------------------------------------- */