mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-25 02:50:08 +03:00
Feature #4369: Create a default cluster on bootstrap
This commit is contained in:
parent
6bbac5077c
commit
724e9fe2b0
@ -44,6 +44,16 @@ public:
|
||||
*/
|
||||
static const int NONE_CLUSTER_ID;
|
||||
|
||||
/**
|
||||
* Name for the default cluster
|
||||
*/
|
||||
static const string DEFAULT_CLUSTER_NAME;
|
||||
|
||||
/**
|
||||
* Identifier for the default cluster
|
||||
*/
|
||||
static const int DEFAULT_CLUSTER_ID;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
/* Methods for DB management */
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
@ -177,7 +177,14 @@ public:
|
||||
|
||||
int get_cluster_id(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
return xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int cid = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
|
||||
if (cid == -1)
|
||||
{
|
||||
cid = ClusterPool::DEFAULT_CLUSTER_ID;
|
||||
}
|
||||
|
||||
return cid;
|
||||
};
|
||||
|
||||
int add_to_cluster(
|
||||
@ -280,7 +287,14 @@ public:
|
||||
|
||||
int get_cluster_id(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
return xmlrpc_c::value_int(paramList.getInt(5));
|
||||
int cid = xmlrpc_c::value_int(paramList.getInt(5));
|
||||
|
||||
if (cid == -1)
|
||||
{
|
||||
cid = ClusterPool::DEFAULT_CLUSTER_ID;
|
||||
}
|
||||
|
||||
return cid;
|
||||
};
|
||||
|
||||
int add_to_cluster(
|
||||
@ -384,7 +398,14 @@ public:
|
||||
|
||||
int get_cluster_id(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
return xmlrpc_c::value_int(paramList.getInt(2));
|
||||
int cid = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
|
||||
if (cid == -1)
|
||||
{
|
||||
cid = ClusterPool::DEFAULT_CLUSTER_ID;
|
||||
}
|
||||
|
||||
return cid;
|
||||
};
|
||||
|
||||
int add_to_cluster(
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <stdexcept>
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* There is a default cluster boostrapped by the core: */
|
||||
/* There is a default cluster boostrapped by the core: 0, default */
|
||||
/* The first 100 cluster IDs are reserved for system clusters. */
|
||||
/* Regular ones start from ID 100 */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -29,6 +29,9 @@
|
||||
const string ClusterPool::NONE_CLUSTER_NAME = "";
|
||||
const int ClusterPool::NONE_CLUSTER_ID = -1;
|
||||
|
||||
const string ClusterPool::DEFAULT_CLUSTER_NAME = "default";
|
||||
const int ClusterPool::DEFAULT_CLUSTER_ID = 0;
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -37,12 +40,48 @@ ClusterPool::ClusterPool(SqlDB * db):PoolSQL(db, Cluster::table, true, true)
|
||||
ostringstream oss;
|
||||
string error_str;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Create the default cluster
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
if (get_lastOID() == -1) //lastOID is set in PoolSQL::init_cb
|
||||
{
|
||||
int rc;
|
||||
|
||||
allocate(DEFAULT_CLUSTER_NAME, &rc, error_str);
|
||||
|
||||
if( rc != DEFAULT_CLUSTER_ID )
|
||||
{
|
||||
goto error_bootstrap;
|
||||
}
|
||||
|
||||
Cluster* cluster = get(DEFAULT_CLUSTER_ID, true);
|
||||
|
||||
if (cluster == 0)
|
||||
{
|
||||
goto error_bootstrap;
|
||||
}
|
||||
|
||||
cluster->add_datastore(DatastorePool::SYSTEM_DS_ID, error_str);
|
||||
cluster->add_datastore(DatastorePool::DEFAULT_DS_ID, error_str);
|
||||
cluster->add_datastore(DatastorePool::FILE_DS_ID, error_str);
|
||||
|
||||
update(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
|
||||
// User created clusters will start from ID 100
|
||||
set_update_lastOID(99);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
error_bootstrap:
|
||||
oss.str("");
|
||||
oss << "Error trying to create default cluster: " << error_str;
|
||||
NebulaLog::log("CLUSTER",Log::ERROR,oss);
|
||||
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -58,7 +58,9 @@ DatastorePool::DatastorePool(
|
||||
{
|
||||
DatastoreTemplate * ds_tmpl;
|
||||
int rc;
|
||||
set<int> empty;
|
||||
set<int> cluster_ids;
|
||||
|
||||
cluster_ids.insert(ClusterPool::DEFAULT_CLUSTER_ID);
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Create the system datastore
|
||||
@ -83,7 +85,7 @@ DatastorePool::DatastorePool(
|
||||
0137,
|
||||
ds_tmpl,
|
||||
&rc,
|
||||
empty,
|
||||
cluster_ids,
|
||||
error_str);
|
||||
|
||||
if( rc < 0 )
|
||||
@ -116,7 +118,7 @@ DatastorePool::DatastorePool(
|
||||
0137,
|
||||
ds_tmpl,
|
||||
&rc,
|
||||
empty,
|
||||
cluster_ids,
|
||||
error_str);
|
||||
|
||||
if( rc < 0 )
|
||||
@ -149,7 +151,7 @@ DatastorePool::DatastorePool(
|
||||
0137,
|
||||
ds_tmpl,
|
||||
&rc,
|
||||
empty,
|
||||
cluster_ids,
|
||||
error_str);
|
||||
|
||||
if( rc < 0 )
|
||||
|
@ -85,7 +85,7 @@ module OpenNebula
|
||||
# Allocates a new Datastore in OpenNebula
|
||||
#
|
||||
# @param description [String] The template of the Datastore.
|
||||
# @param cluster_id [Integer] Id of the cluster
|
||||
# @param cluster_id [Integer] Id of the cluster, -1 to use default
|
||||
#
|
||||
# @return [Integer, OpenNebula::Error] the new ID in case of
|
||||
# success, error otherwise
|
||||
|
@ -90,7 +90,7 @@ module OpenNebula
|
||||
# @param im [String] Name of the im_driver (information/monitoring)
|
||||
# @param vmm [String] Name of the vmm_driver (hypervisor)
|
||||
# @param vnm [String] Name of the vnm_driver (networking)
|
||||
# @param cluster_id [String] Id of the cluster
|
||||
# @param cluster_id [String] Id of the cluster, -1 to use default
|
||||
#
|
||||
# @return [Integer, OpenNebula::Error] the new ID in case of
|
||||
# success, error otherwise
|
||||
|
@ -76,7 +76,7 @@ module OpenNebula
|
||||
# Allocates a new VirtualNetwork in OpenNebula
|
||||
#
|
||||
# @param description [String] The template of the VirtualNetwork.
|
||||
# @param cluster_id [Integer] Id of the cluster
|
||||
# @param cluster_id [Integer] Id of the cluster, -1 to use default
|
||||
#
|
||||
# @return [Integer, OpenNebula::Error] the new ID in case of
|
||||
# success, error otherwise
|
||||
|
@ -42,19 +42,12 @@ void RequestManagerCluster::action_generic(
|
||||
PoolObjectAuth c_perms;
|
||||
PoolObjectAuth obj_perms;
|
||||
|
||||
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
|
||||
{
|
||||
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms,
|
||||
cluster_name, true);
|
||||
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms,
|
||||
cluster_name, true);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
if ( rc == -1 )
|
||||
{
|
||||
cluster_name = ClusterPool::NONE_CLUSTER_NAME;
|
||||
return;
|
||||
}
|
||||
|
||||
rc = get_info(pool, object_id, type, att, obj_perms, obj_name, true);
|
||||
@ -68,11 +61,7 @@ void RequestManagerCluster::action_generic(
|
||||
{
|
||||
AuthRequest ar(att.uid, att.group_ids);
|
||||
|
||||
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
|
||||
{
|
||||
ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER
|
||||
}
|
||||
|
||||
ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER
|
||||
ar.add_auth(AuthRequest::ADMIN, obj_perms); // ADMIN OBJECT
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
@ -116,87 +105,84 @@ void RequestManagerCluster::action_generic(
|
||||
object->unlock();
|
||||
|
||||
// ------------- Add/del object to new cluster ---------------------
|
||||
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
|
||||
cluster = clpool->get(cluster_id, true);
|
||||
|
||||
if ( cluster == 0 )
|
||||
{
|
||||
cluster = clpool->get(cluster_id, true);
|
||||
att.resp_obj = PoolObjectSQL::CLUSTER;
|
||||
att.resp_id = cluster_id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
if ( cluster == 0 )
|
||||
// Rollback
|
||||
get(object_id, true, &object, &cluster_obj);
|
||||
|
||||
if ( object != 0 )
|
||||
{
|
||||
att.resp_obj = PoolObjectSQL::CLUSTER;
|
||||
att.resp_id = cluster_id;
|
||||
failure_response(NO_EXISTS, att);
|
||||
|
||||
// Rollback
|
||||
get(object_id, true, &object, &cluster_obj);
|
||||
|
||||
if ( object != 0 )
|
||||
if (add)
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
cluster_obj->del_cluster(cluster_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
cluster_obj->add_cluster(cluster_id);
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
cluster_obj->del_cluster(cluster_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
cluster_obj->add_cluster(cluster_id);
|
||||
}
|
||||
|
||||
return;
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
}
|
||||
|
||||
if (add)
|
||||
{
|
||||
rc = add_object(cluster, object_id, att.resp_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = del_object(cluster, object_id, att.resp_msg);
|
||||
}
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
cluster->unlock();
|
||||
|
||||
failure_response(INTERNAL, att);
|
||||
|
||||
// Rollback
|
||||
get(object_id, true, &object, &cluster_obj);
|
||||
|
||||
if ( object != 0 )
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
cluster_obj->del_cluster(cluster_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
cluster_obj->add_cluster(cluster_id);
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
clpool->update(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
if (add)
|
||||
{
|
||||
rc = add_object(cluster, object_id, att.resp_msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = del_object(cluster, object_id, att.resp_msg);
|
||||
}
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
cluster->unlock();
|
||||
|
||||
failure_response(ACTION, att);
|
||||
|
||||
// Rollback
|
||||
get(object_id, true, &object, &cluster_obj);
|
||||
|
||||
if ( object != 0 )
|
||||
{
|
||||
if (add)
|
||||
{
|
||||
cluster_obj->del_cluster(cluster_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
cluster_obj->add_cluster(cluster_id);
|
||||
}
|
||||
|
||||
pool->update(object);
|
||||
|
||||
object->unlock();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
clpool->update(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
|
||||
success_response(cluster_id, att);
|
||||
|
||||
return;
|
||||
}
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerClusterHost::add_generic(
|
||||
int cluster_id,
|
||||
|
Loading…
x
Reference in New Issue
Block a user