mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-22 17:57:46 +03:00
feature #201: Initial commit adding cluster support in the core, and new XML-RPC methods.
This commit is contained in:
parent
e7ee28a91d
commit
00ebe0dd36
139
include/ClusterPool.h
Normal file
139
include/ClusterPool.h
Normal file
@ -0,0 +1,139 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef CLUSTER_POOL_H_
|
||||
#define CLUSTER_POOL_H_
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
|
||||
#include "SqlDB.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
/**
|
||||
* A cluster helper class. It is not a normal PoolSQL,
|
||||
* but a series of static methods related to clusters.
|
||||
*/
|
||||
class ClusterPool
|
||||
{
|
||||
private:
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
friend class HostPool;
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Attributes */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* This map stores the clusters
|
||||
*/
|
||||
map<int, string> cluster_names;
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Methods for cluster management */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Returns true if the clid is an id for an existing cluster
|
||||
* @param clid ID of the cluster
|
||||
*
|
||||
* @return true if the clid is an id for an existing cluster
|
||||
*/
|
||||
bool exists(int clid)
|
||||
{
|
||||
return cluster_names.count(clid) > 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Allocates a new cluster in the pool
|
||||
* @param clid the id assigned to the cluster
|
||||
* @return the id assigned to the cluster or -1 in case of failure
|
||||
*/
|
||||
int allocate(int * clid, string name, SqlDB *db);
|
||||
|
||||
/**
|
||||
* Returns the xml representation of the given cluster
|
||||
* @param clid ID of the cluster
|
||||
*
|
||||
* @return the xml representation of the given cluster
|
||||
*/
|
||||
string info(int clid);
|
||||
|
||||
/**
|
||||
* Removes the given cluster from the pool and the DB
|
||||
* @param clid ID of the cluster
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int drop(int clid, SqlDB *db);
|
||||
|
||||
/**
|
||||
* Dumps the cluster pool in XML format.
|
||||
* @param oss the output stream to dump the pool contents
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump(ostringstream& oss);
|
||||
|
||||
/**
|
||||
* Bootstraps the database table(s) associated to the Cluster
|
||||
*/
|
||||
static void bootstrap(SqlDB * db)
|
||||
{
|
||||
ostringstream oss(ClusterPool::db_bootstrap);
|
||||
db->exec(oss);
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to insert new Cluster in the pool
|
||||
* @param oid the id assigned to the Cluster
|
||||
* @param name the Cluster's name
|
||||
* @return 0 on success, -1 in case of failure
|
||||
*/
|
||||
int insert (int oid, string name, SqlDB *db);
|
||||
|
||||
/**
|
||||
* Formats as XML the given id and name.
|
||||
* @param oss the output stream to dump the pool contents
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
void dump(ostringstream& oss, int id, string name);
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* DB manipulation */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
static const char * db_names;
|
||||
|
||||
static const char * db_bootstrap;
|
||||
|
||||
static const char * table;
|
||||
|
||||
};
|
||||
|
||||
#endif /*CLUSTER_POOL_H_*/
|
@ -188,6 +188,12 @@ public:
|
||||
return last_monitored;
|
||||
};
|
||||
|
||||
int set_cluster(string cluster_name)
|
||||
{
|
||||
cluster = cluster_name;
|
||||
return 0;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Template
|
||||
// ------------------------------------------------------------------------
|
||||
@ -396,6 +402,11 @@ private:
|
||||
*/
|
||||
time_t last_monitored;
|
||||
|
||||
/**
|
||||
* Name of the cluster this host belongs to.
|
||||
*/
|
||||
string cluster;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Host Attributes
|
||||
// -------------------------------------------------------------------------
|
||||
@ -472,7 +483,8 @@ protected:
|
||||
VM_MAD = 4,
|
||||
TM_MAD = 5,
|
||||
LAST_MON_TIME = 6,
|
||||
LIMIT = 7
|
||||
CLUSTER = 7,
|
||||
LIMIT = 8
|
||||
};
|
||||
|
||||
static const char * db_names;
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "PoolSQL.h"
|
||||
#include "Host.h"
|
||||
#include "ClusterPool.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <sstream>
|
||||
@ -36,7 +37,7 @@ class HostPool : public PoolSQL
|
||||
{
|
||||
public:
|
||||
|
||||
HostPool(SqlDB * db):PoolSQL(db,Host::table){};
|
||||
HostPool(SqlDB * db);
|
||||
|
||||
~HostPool(){};
|
||||
|
||||
@ -81,6 +82,8 @@ public:
|
||||
static void bootstrap(SqlDB *_db)
|
||||
{
|
||||
Host::bootstrap(_db);
|
||||
|
||||
ClusterPool::bootstrap(_db);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -144,7 +147,113 @@ public:
|
||||
*/
|
||||
int dump(ostringstream& oss, const string& where);
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Methods for cluster management */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/*
|
||||
ClusterPool * cluster_pool()
|
||||
{
|
||||
return &cluster_pool;
|
||||
}
|
||||
//*/
|
||||
|
||||
/**
|
||||
* Returns true if the clid is an id for an existing cluster
|
||||
* @param clid ID of the cluster
|
||||
*
|
||||
* @return true if the clid is an id for an existing cluster
|
||||
*/
|
||||
bool exists_cluster(int clid)
|
||||
{
|
||||
return cluster_pool.exists(clid);
|
||||
};
|
||||
|
||||
/**
|
||||
* Allocates a new cluster in the pool
|
||||
* @param clid the id assigned to the cluster
|
||||
* @return the id assigned to the cluster or -1 in case of failure
|
||||
*/
|
||||
int allocate_cluster(int * clid, string name)
|
||||
{
|
||||
return cluster_pool.allocate(clid, name, db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the xml representation of the given cluster
|
||||
* @param clid ID of the cluster
|
||||
*
|
||||
* @return the xml representation of the given cluster
|
||||
*/
|
||||
string info_cluster(int clid)
|
||||
{
|
||||
return cluster_pool.info(clid);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the given cluster from the pool and the DB
|
||||
* @param clid ID of the cluster
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int drop_cluster(int clid)
|
||||
{
|
||||
return cluster_pool.drop(clid, db);
|
||||
};
|
||||
|
||||
/**
|
||||
* Dumps the cluster pool in XML format.
|
||||
* @param oss the output stream to dump the pool contents
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int dump_cluster(ostringstream& oss)
|
||||
{
|
||||
return cluster_pool.dump(oss);
|
||||
};
|
||||
|
||||
/**
|
||||
* Assigns the host to the given cluster
|
||||
* @param host The host to assign
|
||||
* @param clid ID of the cluster
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int set_cluster(Host* host, int clid)
|
||||
{
|
||||
map<int, string>::iterator it;
|
||||
|
||||
it = cluster_pool.cluster_names.find(clid);
|
||||
|
||||
if(it == cluster_pool.cluster_names.end())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return host->set_cluster( it->second );
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Removes the host from the given cluster.
|
||||
* The result is the same as assigning the host to
|
||||
* the default cluster.
|
||||
* @param host The host to assign
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int remove_cluster(Host* host)
|
||||
{
|
||||
// To remove a host from a cluster means
|
||||
// moving it to the default cluster.
|
||||
return set_cluster(host, 0);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
ClusterPool cluster_pool;
|
||||
|
||||
|
||||
/**
|
||||
* Factory method to produce Host objects
|
||||
* @return a pointer to the new Host
|
||||
@ -154,6 +263,15 @@ private:
|
||||
return new Host;
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback function to build the cluster pool
|
||||
* @param num the number of columns read from the DB
|
||||
* @param names the column names
|
||||
* @param vaues the column values
|
||||
* @return 0 on success
|
||||
*/
|
||||
int init_cb(void *nil, int num, char **values, char **names);
|
||||
|
||||
/**
|
||||
* Callback function to get the IDs of the hosts to be monitored
|
||||
* (Host::discover)
|
||||
@ -175,4 +293,4 @@ private:
|
||||
int dump_cb(void * _oss, int num, char **values, char **names);
|
||||
};
|
||||
|
||||
#endif /*HOST_POOL_H_*/
|
||||
#endif /*HOST_POOL_H_*/
|
||||
|
@ -456,7 +456,166 @@ private:
|
||||
HostPool * hpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Cluster Interface */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ClusterAllocate: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ClusterAllocate(
|
||||
HostPool * _hpool,
|
||||
UserPool * _upool):
|
||||
hpool(_hpool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:ss";
|
||||
_help="Allocates a cluster in the pool";
|
||||
};
|
||||
|
||||
~ClusterAllocate(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
HostPool * hpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ClusterInfo: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ClusterInfo(
|
||||
HostPool * _hpool,
|
||||
UserPool * _upool):
|
||||
hpool(_hpool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:si";
|
||||
_help="Returns cluster information";
|
||||
};
|
||||
|
||||
~ClusterInfo(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
HostPool * hpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ClusterDelete: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ClusterDelete(
|
||||
HostPool * _hpool,
|
||||
UserPool * _upool):
|
||||
hpool(_hpool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:si";
|
||||
_help="Deletes a cluster from the pool";
|
||||
};
|
||||
|
||||
~ClusterDelete(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
HostPool * hpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ClusterAdd: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ClusterAdd(
|
||||
HostPool * _hpool,
|
||||
UserPool * _upool):
|
||||
hpool(_hpool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:sii";
|
||||
_help="Adds a host to a cluster";
|
||||
};
|
||||
|
||||
~ClusterAdd(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
HostPool * hpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ClusterRemove: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ClusterRemove(
|
||||
HostPool * _hpool,
|
||||
UserPool * _upool):
|
||||
hpool(_hpool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:si";
|
||||
_help="Removes a host from its cluster";
|
||||
};
|
||||
|
||||
~ClusterRemove(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
HostPool * hpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
class ClusterPoolInfo: public xmlrpc_c::method
|
||||
{
|
||||
public:
|
||||
ClusterPoolInfo(
|
||||
HostPool * _hpool,
|
||||
UserPool * _upool):
|
||||
hpool(_hpool),
|
||||
upool(_upool)
|
||||
{
|
||||
_signature="A:s";
|
||||
_help="Returns the cluster pool information";
|
||||
};
|
||||
|
||||
~ClusterPoolInfo(){};
|
||||
|
||||
void execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retvalP);
|
||||
|
||||
private:
|
||||
HostPool * hpool;
|
||||
UserPool * upool;
|
||||
};
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Virtual Network Interface */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
168
src/host/ClusterPool.cc
Normal file
168
src/host/ClusterPool.cc
Normal file
@ -0,0 +1,168 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "ClusterPool.h"
|
||||
|
||||
const char * ClusterPool::table = "cluster_pool";
|
||||
|
||||
const char * ClusterPool::db_names = "oid, cluster_name";
|
||||
|
||||
const char * ClusterPool::db_bootstrap =
|
||||
"CREATE TABLE IF NOT EXISTS cluster_pool ("
|
||||
"oid INTEGER PRIMARY KEY, cluster_name VARCHAR(128), "
|
||||
"UNIQUE(cluster_name) )";
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterPool::allocate(int * clid, string name, SqlDB *db)
|
||||
{
|
||||
int rc;
|
||||
|
||||
map<int, string>::iterator it;
|
||||
|
||||
// Return error if name already exists
|
||||
for(it=cluster_names.begin();it!=cluster_names.end();it++)
|
||||
{
|
||||
if(it->second == name)
|
||||
{
|
||||
goto error_existing_name;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the highest key, and add 1
|
||||
*clid = cluster_names.rbegin()->first + 1;
|
||||
|
||||
rc = insert(*clid, name, db);
|
||||
|
||||
if(rc != 0)
|
||||
{
|
||||
goto error_db;
|
||||
}
|
||||
|
||||
return *clid;
|
||||
|
||||
// TODO: LOG ERRORS
|
||||
error_existing_name:
|
||||
error_db:
|
||||
error_common:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string ClusterPool::info(int clid)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
map<int, string>::iterator it;
|
||||
|
||||
it = cluster_names.find(clid);
|
||||
|
||||
if(it != cluster_names.end())
|
||||
{
|
||||
dump(oss, it->first, it->second);
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterPool::drop(int clid, SqlDB *db)
|
||||
{
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
// Return error if cluster is 'default' or if it doesn't exist
|
||||
if( clid == 0 || cluster_names.count(clid) == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
oss << "DELETE FROM " << table << " WHERE oid=" << clid;
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
if(rc == 0)
|
||||
{
|
||||
cluster_names.erase(clid);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterPool::dump(ostringstream& oss)
|
||||
{
|
||||
map<int, string>::iterator it;
|
||||
|
||||
|
||||
oss << "<CLUSTER_POOL>";
|
||||
|
||||
for(it=cluster_names.begin();it!=cluster_names.end();it++)
|
||||
{
|
||||
dump(oss, it->first, it->second);
|
||||
}
|
||||
|
||||
oss << "</CLUSTER_POOL>";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ClusterPool::insert(int oid, string name, SqlDB *db)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
int rc;
|
||||
|
||||
char * sql_name;
|
||||
|
||||
sql_name = db->escape_str(name.c_str());
|
||||
|
||||
if ( sql_name == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
oss << "INSERT INTO "<< table <<" ("<< db_names <<") VALUES ("
|
||||
<< oid << ","
|
||||
<< "'" << sql_name << "')";
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
db->free_str(sql_name);
|
||||
|
||||
if( rc == 0 )
|
||||
{
|
||||
cluster_names.insert( make_pair(oid, name) );
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ClusterPool::dump(ostringstream& oss, int id, string name)
|
||||
{
|
||||
oss <<
|
||||
"<CLUSTER>" <<
|
||||
"<ID>" << id << "</ID>" <<
|
||||
"<NAME>" << name << "</NAME>" <<
|
||||
"</CLUSTER>";
|
||||
}
|
@ -40,7 +40,8 @@ Host::Host(
|
||||
vmm_mad_name(_vmm_mad_name),
|
||||
tm_mad_name(_tm_mad_name),
|
||||
last_monitored(0),
|
||||
host_template(id)
|
||||
host_template(id),
|
||||
cluster("default")
|
||||
{};
|
||||
|
||||
|
||||
@ -53,12 +54,13 @@ Host::~Host(){};
|
||||
const char * Host::table = "host_pool";
|
||||
|
||||
const char * Host::db_names = "(oid,host_name,state,im_mad,vm_mad,"
|
||||
"tm_mad,last_mon_time)";
|
||||
"tm_mad,last_mon_time, cluster)";
|
||||
|
||||
const char * Host::db_bootstrap = "CREATE TABLE IF NOT EXISTS host_pool ("
|
||||
"oid INTEGER PRIMARY KEY,host_name VARCHAR(512), state INTEGER,"
|
||||
"im_mad VARCHAR(128),vm_mad VARCHAR(128),tm_mad VARCHAR(128),"
|
||||
"last_mon_time INTEGER, UNIQUE(host_name, im_mad, vm_mad, tm_mad) )";
|
||||
"last_mon_time INTEGER, cluster VARCHAR(128), "
|
||||
"UNIQUE(host_name, im_mad, vm_mad, tm_mad) )";
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@ -72,6 +74,7 @@ int Host::select_cb(void * nil, int num, char **values, char ** names)
|
||||
(!values[VM_MAD]) ||
|
||||
(!values[TM_MAD]) ||
|
||||
(!values[LAST_MON_TIME]) ||
|
||||
(!values[CLUSTER]) ||
|
||||
(num != LIMIT ))
|
||||
{
|
||||
return -1;
|
||||
@ -87,6 +90,8 @@ int Host::select_cb(void * nil, int num, char **values, char ** names)
|
||||
|
||||
last_monitored = static_cast<time_t>(atoi(values[LAST_MON_TIME]));
|
||||
|
||||
cluster = values[CLUSTER];
|
||||
|
||||
host_template.id = oid;
|
||||
host_share.hsid = oid;
|
||||
|
||||
@ -238,6 +243,7 @@ int Host::insert_replace(SqlDB *db, bool replace)
|
||||
char * sql_im_mad_name;
|
||||
char * sql_tm_mad_name;
|
||||
char * sql_vmm_mad_name;
|
||||
char * sql_cluster;
|
||||
|
||||
// Update the Host
|
||||
|
||||
@ -269,6 +275,13 @@ int Host::insert_replace(SqlDB *db, bool replace)
|
||||
goto error_vmm;
|
||||
}
|
||||
|
||||
sql_cluster = db->escape_str(cluster.c_str());
|
||||
|
||||
if ( sql_cluster == 0 )
|
||||
{
|
||||
goto error_cluster;
|
||||
}
|
||||
|
||||
if(replace)
|
||||
{
|
||||
oss << "REPLACE";
|
||||
@ -287,7 +300,8 @@ int Host::insert_replace(SqlDB *db, bool replace)
|
||||
<< "'" << sql_im_mad_name << "',"
|
||||
<< "'" << sql_vmm_mad_name << "',"
|
||||
<< "'" << sql_tm_mad_name << "',"
|
||||
<< last_monitored << ")";
|
||||
<< last_monitored << ","
|
||||
<< "'" << sql_cluster << "')";
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
@ -295,9 +309,12 @@ int Host::insert_replace(SqlDB *db, bool replace)
|
||||
db->free_str(sql_im_mad_name);
|
||||
db->free_str(sql_tm_mad_name);
|
||||
db->free_str(sql_vmm_mad_name);
|
||||
db->free_str(sql_cluster);
|
||||
|
||||
return rc;
|
||||
|
||||
error_cluster:
|
||||
db->free_str(sql_vmm_mad_name);
|
||||
error_vmm:
|
||||
db->free_str(sql_tm_mad_name);
|
||||
error_tm:
|
||||
@ -320,6 +337,7 @@ int Host::dump(ostringstream& oss, int num, char **values, char **names)
|
||||
(!values[VM_MAD]) ||
|
||||
(!values[TM_MAD]) ||
|
||||
(!values[LAST_MON_TIME]) ||
|
||||
(!values[CLUSTER]) ||
|
||||
(num != LIMIT + HostShare::LIMIT ))
|
||||
{
|
||||
return -1;
|
||||
@ -333,7 +351,8 @@ int Host::dump(ostringstream& oss, int num, char **values, char **names)
|
||||
"<IM_MAD>" << values[IM_MAD] <<"</IM_MAD>" <<
|
||||
"<VM_MAD>" << values[VM_MAD] <<"</VM_MAD>" <<
|
||||
"<TM_MAD>" << values[TM_MAD] <<"</TM_MAD>" <<
|
||||
"<LAST_MON_TIME>"<< values[LAST_MON_TIME]<<"</LAST_MON_TIME>";
|
||||
"<LAST_MON_TIME>"<< values[LAST_MON_TIME]<<"</LAST_MON_TIME>"<<
|
||||
"<CLUSTER>" << values[CLUSTER] <<"</CLUSTER>";
|
||||
|
||||
HostShare::dump(oss,num - LIMIT, values + LIMIT, names + LIMIT);
|
||||
|
||||
@ -428,6 +447,7 @@ string& Host::to_xml(string& xml) const
|
||||
"<VM_MAD>" << vmm_mad_name << "</VM_MAD>" <<
|
||||
"<TM_MAD>" << tm_mad_name << "</TM_MAD>" <<
|
||||
"<LAST_MON_TIME>" << last_monitored << "</LAST_MON_TIME>" <<
|
||||
"<CLUSTER>" << cluster << "</CLUSTER>" <<
|
||||
host_share.to_xml(share_xml) <<
|
||||
host_template.to_xml(template_xml) <<
|
||||
"</HOST>";
|
||||
@ -455,6 +475,7 @@ string& Host::to_str(string& str) const
|
||||
"VMM MAD = " << vmm_mad_name << endl <<
|
||||
"TM MAD = " << tm_mad_name << endl <<
|
||||
"LAST_MON = " << last_monitored << endl <<
|
||||
"CLUSTER = " << cluster << endl <<
|
||||
"ATTRIBUTES" << endl << host_template.to_str(template_str) << endl <<
|
||||
"HOST SHARES" << endl << host_share.to_str(share_str) <<endl;
|
||||
|
||||
|
@ -19,6 +19,48 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "HostPool.h"
|
||||
#include "ClusterPool.h"
|
||||
|
||||
int HostPool::init_cb(void *nil, int num, char **values, char **names)
|
||||
{
|
||||
if ( num != 2 || values == 0 || values[0] == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
cluster_pool.cluster_names.insert( make_pair(atoi(values[0]), values[1]) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
HostPool::HostPool(SqlDB* db):PoolSQL(db,Host::table)
|
||||
{
|
||||
ostringstream sql;
|
||||
|
||||
set_callback(static_cast<Callbackable::Callback>(&HostPool::init_cb));
|
||||
|
||||
sql << "SELECT " << ClusterPool::db_names << " FROM "
|
||||
<< ClusterPool::table;
|
||||
|
||||
db->exec(sql, this);
|
||||
|
||||
unset_callback();
|
||||
|
||||
if (cluster_pool.cluster_names.empty())
|
||||
{
|
||||
string default_name = "default";
|
||||
|
||||
// Insert the "default" cluster
|
||||
int rc = cluster_pool.insert(0, default_name, db);
|
||||
// TODO Check and log error
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostPool::allocate (
|
||||
int * oid,
|
||||
|
@ -26,6 +26,7 @@ source_files=[
|
||||
'HostShare.cc',
|
||||
'HostPool.cc',
|
||||
'HostTemplate.cc',
|
||||
'ClusterPool.cc',
|
||||
]
|
||||
|
||||
# Build library
|
||||
|
@ -245,7 +245,25 @@ void RequestManager::register_xml_methods()
|
||||
|
||||
xmlrpc_c::methodPtr host_enable(new
|
||||
RequestManager::HostEnable(hpool,upool));
|
||||
|
||||
|
||||
xmlrpc_c::methodPtr cluster_allocate(new
|
||||
RequestManager::ClusterAllocate(hpool,upool));
|
||||
|
||||
xmlrpc_c::methodPtr cluster_info(new
|
||||
RequestManager::ClusterInfo(hpool,upool));
|
||||
|
||||
xmlrpc_c::methodPtr cluster_delete(new
|
||||
RequestManager::ClusterDelete(hpool,upool));
|
||||
|
||||
xmlrpc_c::methodPtr cluster_add(new
|
||||
RequestManager::ClusterAdd(hpool,upool));
|
||||
|
||||
xmlrpc_c::methodPtr cluster_remove(new
|
||||
RequestManager::ClusterRemove(hpool,upool));
|
||||
|
||||
xmlrpc_c::methodPtr clusterpool_info(new
|
||||
RequestManager::ClusterPoolInfo(hpool,upool));
|
||||
|
||||
xmlrpc_c::methodPtr vn_allocate(new
|
||||
RequestManager::VirtualNetworkAllocate(vnpool,upool));
|
||||
|
||||
@ -288,7 +306,17 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.host.enable", host_enable);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.hostpool.info", hostpool_info);
|
||||
|
||||
|
||||
/* Cluster related methods */
|
||||
|
||||
RequestManagerRegistry.addMethod("one.cluster.allocate", cluster_allocate);
|
||||
RequestManagerRegistry.addMethod("one.cluster.info", cluster_info);
|
||||
RequestManagerRegistry.addMethod("one.cluster.delete", cluster_delete);
|
||||
RequestManagerRegistry.addMethod("one.cluster.add", cluster_add);
|
||||
RequestManagerRegistry.addMethod("one.cluster.remove", cluster_remove);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.clusterpool.info", clusterpool_info);
|
||||
|
||||
/* Network related methods*/
|
||||
|
||||
RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate);
|
||||
|
130
src/rm/RequestManagerClusterAdd.cc
Normal file
130
src/rm/RequestManagerClusterAdd.cc
Normal file
@ -0,0 +1,130 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::ClusterAdd::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int hid;
|
||||
int clid;
|
||||
int rc;
|
||||
|
||||
Host * host;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ClusterAdd method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
hid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
clid = xmlrpc_c::value_int (paramList.getInt(2));
|
||||
|
||||
|
||||
// Only oneadmin can add hosts to clusters
|
||||
rc = ClusterAdd::upool->authenticate(session);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
|
||||
// Check if cluster exists
|
||||
if ( !ClusterAdd::hpool->exists_cluster(clid) )
|
||||
{
|
||||
goto error_cluster;
|
||||
}
|
||||
|
||||
// Check if host exists
|
||||
host = ClusterAdd::hpool->get(hid,true);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
goto error_host_get;
|
||||
}
|
||||
|
||||
// Set cluster
|
||||
rc = ClusterAdd::hpool->set_cluster(host, clid);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_cluster_add;
|
||||
}
|
||||
|
||||
// Update the DB
|
||||
ClusterAdd::hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
|
||||
// All nice, return success to the client
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult; // and get rid of the original
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss << "User not authorized to add hosts to clusters";
|
||||
goto error_common;
|
||||
|
||||
error_cluster:
|
||||
oss << "Error getting cluster with CLID = " << clid;
|
||||
goto error_common;
|
||||
|
||||
error_host_get:
|
||||
oss << "The host " << hid << " does not exists";
|
||||
goto error_common;
|
||||
|
||||
error_cluster_add:
|
||||
host->unlock();
|
||||
|
||||
oss << "Can not add host " << hid << " to cluster " << clid <<
|
||||
", returned error code [" << rc << "]";
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
97
src/rm/RequestManagerClusterAllocate.cc
Normal file
97
src/rm/RequestManagerClusterAllocate.cc
Normal file
@ -0,0 +1,97 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::ClusterAllocate::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
string clustername;
|
||||
|
||||
int id;
|
||||
|
||||
int rc;
|
||||
ostringstream oss;
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ClusterAllocate method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
clustername = xmlrpc_c::value_string(paramList.getString(1));
|
||||
|
||||
// Only oneadmin can add new clusters
|
||||
rc = ClusterAllocate::upool->authenticate(session);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Perform the allocation in the hostpool
|
||||
rc = ClusterAllocate::hpool->allocate_cluster(&id, clustername);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_cluster_allocate;
|
||||
}
|
||||
|
||||
// All nice, return the new id to client
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
|
||||
arrayData.push_back(xmlrpc_c::value_int(id));
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
// Copy arrayresult into retval mem space
|
||||
*retval = *arrayresult;
|
||||
// and get rid of the original
|
||||
delete arrayresult;
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss << "User not authorized to add new clusters";
|
||||
goto error_common;
|
||||
|
||||
error_cluster_allocate:
|
||||
oss << "Can not allocate cluster " << clustername <<
|
||||
" in the ClusterPool, returned error code [" << rc << "]";
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
104
src/rm/RequestManagerClusterDelete.cc
Normal file
104
src/rm/RequestManagerClusterDelete.cc
Normal file
@ -0,0 +1,104 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::ClusterDelete::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
// <clid> of the cluster to delete from the HostPool
|
||||
int clid;
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ClusterDelete method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
clid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
|
||||
// Only oneadmin can delete clusters
|
||||
rc = ClusterDelete::upool->authenticate(session);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
|
||||
// Check if cluster exists
|
||||
if ( !ClusterDelete::hpool->exists_cluster(clid) )
|
||||
{
|
||||
goto error_cluster;
|
||||
}
|
||||
|
||||
rc = ClusterDelete::hpool->drop_cluster(clid);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_cluster_delete;
|
||||
}
|
||||
|
||||
// Return success
|
||||
arrayData.push_back(xmlrpc_c::value_boolean( rc == 0 )); // SUCCESS
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
*retval = *arrayresult;
|
||||
// and get rid of the original
|
||||
delete arrayresult;
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss << "User not authorized to delete clusters";
|
||||
goto error_common;
|
||||
|
||||
error_cluster:
|
||||
oss << "Error getting cluster with CLID = " << clid;
|
||||
goto error_common;
|
||||
|
||||
error_cluster_delete:
|
||||
oss << "Can not delete cluster with CLID " << clid <<
|
||||
" from the ClusterPool, returned error code [" << rc << "]";
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
NebulaLog::log ("Rem",Log::ERROR,oss);
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
98
src/rm/RequestManagerClusterInfo.cc
Normal file
98
src/rm/RequestManagerClusterInfo.cc
Normal file
@ -0,0 +1,98 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::ClusterInfo::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
string info;
|
||||
|
||||
int clid;
|
||||
int rc;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ClusterInfo method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
clid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
|
||||
// Check if it is a valid user
|
||||
rc = ClusterInfo::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Check if cluster exists
|
||||
rc = ClusterInfo::hpool->exists_cluster(clid);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_cluster;
|
||||
}
|
||||
|
||||
info = ClusterInfo::hpool->info_cluster(clid);
|
||||
|
||||
// All nice, return the cluster info to the client
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
|
||||
arrayData.push_back(xmlrpc_c::value_string(info));
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult; // and get rid of the original
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss << "User not authenticated, ClusterInfo call aborted.";
|
||||
goto error_common;
|
||||
|
||||
error_cluster:
|
||||
oss << "Error getting cluster with CLID = " << clid;
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
94
src/rm/RequestManagerClusterPoolInfo.cc
Executable file
94
src/rm/RequestManagerClusterPoolInfo.cc
Executable file
@ -0,0 +1,94 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::ClusterPoolInfo::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ClusterPoolInfo method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
|
||||
|
||||
// Check if it is a valid user
|
||||
rc = ClusterPoolInfo::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Perform the allocation in the vmpool
|
||||
rc = ClusterPoolInfo::hpool->dump_cluster(oss);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_dump;
|
||||
}
|
||||
|
||||
//All nice, return the info to the client
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
*retval = *arrayresult;
|
||||
|
||||
// and get rid of the original
|
||||
delete arrayresult;
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss << "User not authenticated, RequestManagerClusterPoolInfo aborted.";
|
||||
goto error_common;
|
||||
|
||||
error_dump:
|
||||
oss << "Error getting Cluster pool";
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
118
src/rm/RequestManagerClusterRemove.cc
Normal file
118
src/rm/RequestManagerClusterRemove.cc
Normal file
@ -0,0 +1,118 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* 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. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::ClusterRemove::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int hid;
|
||||
int rc;
|
||||
|
||||
Host * host;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"ClusterRemove method invoked");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
hid = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
|
||||
|
||||
// Only oneadmin can remove hosts from clusters
|
||||
rc = ClusterRemove::upool->authenticate(session);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
|
||||
// Check if host exists
|
||||
host = ClusterRemove::hpool->get(hid,true);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
goto error_host_get;
|
||||
}
|
||||
|
||||
// Remove host from cluster
|
||||
rc = ClusterRemove::hpool->remove_cluster(host);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_cluster_remove;
|
||||
}
|
||||
|
||||
// Update the DB
|
||||
ClusterRemove::hpool->update(host);
|
||||
|
||||
host->unlock();
|
||||
|
||||
// All nice, return success to the client
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult; // and get rid of the original
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss << "User not authorized to remove hosts from clusters";
|
||||
goto error_common;
|
||||
|
||||
error_host_get:
|
||||
oss << "The host " << hid << " does not exists";
|
||||
goto error_common;
|
||||
|
||||
error_cluster_remove:
|
||||
host->unlock();
|
||||
|
||||
oss << "Can not remove host " << hid << " from its cluster, "
|
||||
<< "returned error code [" << rc << "]";
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -34,6 +34,12 @@ source_files=[
|
||||
'RequestManagerHostInfo.cc',
|
||||
'RequestManagerHostPoolInfo.cc',
|
||||
'RequestManagerHostEnable.cc',
|
||||
'RequestManagerClusterAdd.cc',
|
||||
'RequestManagerClusterAllocate.cc',
|
||||
'RequestManagerClusterDelete.cc',
|
||||
'RequestManagerClusterInfo.cc',
|
||||
'RequestManagerClusterPoolInfo.cc',
|
||||
'RequestManagerClusterRemove.cc',
|
||||
'RequestManagerVirtualNetworkAllocate.cc',
|
||||
'RequestManagerVirtualNetworkInfo.cc',
|
||||
'RequestManagerVirtualNetworkPoolInfo.cc',
|
||||
|
Loading…
x
Reference in New Issue
Block a user