1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-08 21:17:43 +03:00

Feature #1112: Hosts, DS & VNets can belong to the 'none' cluster.

The cluster id -1 is used to indicate objects that can be clustered,
but are not assigned to any cluster. The new methods to remove objects
from their current datastore actually set this 'none' or -1 cluster
ID.

VNets are always created in this 'none' cluster. Hosts and DS require
a cluster ID to be placed when allocated, and the ruby OCA by default
sets it to 'none'
This commit is contained in:
Carlos Martín 2012-03-01 17:14:52 +01:00
parent 55b4b9510a
commit 9a7d78f7f2
15 changed files with 386 additions and 191 deletions

View File

@ -44,6 +44,16 @@ public:
*/
static const int DEFAULT_CLUSTER_ID;
/**
* Name for the "none" cluster
*/
static const string NONE_CLUSTER_NAME;
/**
* Identifier for the "none" cluster
*/
static const int NONE_CLUSTER_ID;
/* ---------------------------------------------------------------------- */
/* Methods for DB management */
/* ---------------------------------------------------------------------- */

View File

@ -37,21 +37,13 @@ protected:
RequestManagerAllocate(const string& method_name,
const string& help,
const string& xml_args,
bool dt,
bool dc=false)
:Request(method_name,xml_args,help), do_template(dt), do_cluster(dc)
bool dt)
:Request(method_name,xml_args,help), do_template(dt)
{
auth_op = AuthRequest::CREATE;
if ( do_cluster )
{
Nebula& nd = Nebula::instance();
clpool = nd.get_clpool();
}
else
{
clpool = 0;
}
Nebula& nd = Nebula::instance();
clpool = nd.get_clpool();
};
~RequestManagerAllocate(){};
@ -91,7 +83,7 @@ protected:
virtual int get_cluster_id(xmlrpc_c::paramList const& paramList)
{
return -1;
return ClusterPool::NONE_CLUSTER_ID;
};
virtual int add_to_cluster(Cluster* cluster, int id, string& error_msg)
@ -105,7 +97,6 @@ protected:
private:
bool do_template;
bool do_cluster;
};
@ -156,7 +147,6 @@ public:
RequestManagerAllocate("VirtualNetworkAllocate",
"Allocates a new virtual network",
"A:ss",
true,
true)
{
Nebula& nd = Nebula::instance();
@ -180,10 +170,6 @@ public:
RequestAttributes& att,
int cluster_id,
const string& cluster_name);
int get_cluster_id(xmlrpc_c::paramList const& paramList);
int add_to_cluster(Cluster* cluster, int id, string& error_msg);
};
/* ------------------------------------------------------------------------- */
@ -254,8 +240,7 @@ public:
RequestManagerAllocate("HostAllocate",
"Allocates a new host",
"A:sssssi",
false,
true)
false)
{
Nebula& nd = Nebula::instance();
pool = nd.get_hpool();
@ -274,9 +259,15 @@ public:
int cluster_id,
const string& cluster_name);
int get_cluster_id(xmlrpc_c::paramList const& paramList);
int get_cluster_id(xmlrpc_c::paramList const& paramList)
{
return xmlrpc_c::value_int(paramList.getInt(5));
};
int add_to_cluster(Cluster* cluster, int id, string& error_msg);
int add_to_cluster(Cluster* cluster, int id, string& error_msg)
{
return cluster->add_host(id, error_msg);
};
};
/* ------------------------------------------------------------------------- */
@ -341,7 +332,6 @@ public:
RequestManagerAllocate("DatastoreAllocate",
"Allocates a new Datastore",
"A:ssi",
true,
true)
{
Nebula& nd = Nebula::instance();
@ -366,9 +356,15 @@ public:
int cluster_id,
const string& cluster_name);
int get_cluster_id(xmlrpc_c::paramList const& paramList);
int get_cluster_id(xmlrpc_c::paramList const& paramList)
{
return xmlrpc_c::value_int(paramList.getInt(2));
};
int add_to_cluster(Cluster* cluster, int id, string& error_msg);
int add_to_cluster(Cluster* cluster, int id, string& error_msg)
{
return cluster->add_datastore(id, error_msg);
};
};
/* ------------------------------------------------------------------------- */

View File

@ -55,11 +55,12 @@ protected:
/* --------------------------------------------------------------------- */
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
virtual void request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att) = 0;
void add_generic(
xmlrpc_c::paramList const& _paramList,
int cluster_id,
int object_id,
RequestAttributes& att,
PoolSQL * pool,
PoolObjectSQL::ObjectType type);
@ -74,21 +75,16 @@ protected:
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterAddHost : public RequestManagerCluster
class RequestManagerClusterHost : public RequestManagerCluster
{
public:
ClusterAddHost():
RequestManagerCluster("ClusterAddHost",
"Adds a host to the cluster",
"A:sii"){};
RequestManagerClusterHost(
const string& method_name,
const string& help,
const string& params):
RequestManagerCluster(method_name, help, params){};
~ClusterAddHost(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att)
{
return add_generic(_paramList, att, hpool, PoolObjectSQL::HOST);
}
~RequestManagerClusterHost(){};
virtual int add_object(Cluster* cluster, int id, string& error_msg)
{
@ -112,21 +108,66 @@ public:
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterAddDatastore : public RequestManagerCluster
class ClusterAddHost : public RequestManagerClusterHost
{
public:
ClusterAddDatastore():
RequestManagerCluster("ClusterAddDatastore",
"Adds a datastore to the cluster",
ClusterAddHost():
RequestManagerClusterHost("ClusterAddHost",
"Adds a host to the cluster",
"A:sii"){};
~ClusterAddDatastore(){};
~ClusterAddHost(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
void request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
return add_generic(_paramList, att, dspool, PoolObjectSQL::DATASTORE);
int cluster_id = xmlrpc_c::value_int(paramList.getInt(1));
int object_id = xmlrpc_c::value_int(paramList.getInt(2));
return add_generic(cluster_id, object_id, att,
hpool, PoolObjectSQL::HOST);
}
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterDelHost : public RequestManagerClusterHost
{
public:
ClusterDelHost():
RequestManagerClusterHost("ClusterDelHost",
"Deletes a host from its cluster",
"A:sii"){};
~ClusterDelHost(){};
void request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
// First param is ignored, as objects can be assigned to only
// one cluster
int cluster_id = ClusterPool::NONE_CLUSTER_ID;
int object_id = xmlrpc_c::value_int(paramList.getInt(2));
return add_generic(cluster_id, object_id, att,
hpool, PoolObjectSQL::HOST);
}
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerClusterDatastore : public RequestManagerCluster
{
public:
RequestManagerClusterDatastore(
const string& method_name,
const string& help,
const string& params):
RequestManagerCluster(method_name, help, params){};
~RequestManagerClusterDatastore(){};
virtual int add_object(Cluster* cluster, int id, string& error_msg)
{
@ -150,21 +191,67 @@ public:
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterAddVNet : public RequestManagerCluster
class ClusterAddDatastore : public RequestManagerClusterDatastore
{
public:
ClusterAddVNet():
RequestManagerCluster("ClusterAddVNet",
"Adds a virtual network to the cluster",
ClusterAddDatastore():
RequestManagerClusterDatastore("ClusterAddDatastore",
"Adds a datastore to the cluster",
"A:sii"){};
~ClusterAddVNet(){};
~ClusterAddDatastore(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
void request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
return add_generic(_paramList, att, vnpool, PoolObjectSQL::NET);
int cluster_id = xmlrpc_c::value_int(paramList.getInt(1));
int object_id = xmlrpc_c::value_int(paramList.getInt(2));
return add_generic(cluster_id, object_id, att,
dspool, PoolObjectSQL::DATASTORE);
}
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterDelDatastore : public RequestManagerClusterDatastore
{
public:
ClusterDelDatastore():
RequestManagerClusterDatastore("ClusterDelDatastore",
"Deletes a datastore from its cluster",
"A:sii"){};
~ClusterDelDatastore(){};
void request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
// First param is ignored, as objects can be assigned to only
// one cluster
int cluster_id = ClusterPool::NONE_CLUSTER_ID;
int object_id = xmlrpc_c::value_int(paramList.getInt(2));
return add_generic(cluster_id, object_id, att,
dspool, PoolObjectSQL::DATASTORE);
}
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerClusterVNet : public RequestManagerCluster
{
public:
RequestManagerClusterVNet(
const string& method_name,
const string& help,
const string& params):
RequestManagerCluster(method_name, help, params){};
~RequestManagerClusterVNet(){};
virtual int add_object(Cluster* cluster, int id, string& error_msg)
{
@ -185,6 +272,56 @@ public:
};
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterAddVNet : public RequestManagerClusterVNet
{
public:
ClusterAddVNet():
RequestManagerClusterVNet("ClusterAddVNet",
"Adds a virtual network to the cluster",
"A:sii"){};
~ClusterAddVNet(){};
void request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
int cluster_id = xmlrpc_c::value_int(paramList.getInt(1));
int object_id = xmlrpc_c::value_int(paramList.getInt(2));
return add_generic(cluster_id, object_id, att,
vnpool, PoolObjectSQL::NET);
}
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterDelVNet : public RequestManagerClusterVNet
{
public:
ClusterDelVNet():
RequestManagerClusterVNet("ClusterDelVNet",
"Deletes a virtual network from its cluster",
"A:sii"){};
~ClusterDelVNet(){};
void request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
// First param is ignored, as objects can be assigned to only
// one cluster
int cluster_id = ClusterPool::NONE_CLUSTER_ID;
int object_id = xmlrpc_c::value_int(paramList.getInt(2));
return add_generic(cluster_id, object_id, att,
vnpool, PoolObjectSQL::NET);
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -31,22 +31,13 @@ class RequestManagerDelete: public Request
{
protected:
RequestManagerDelete(const string& method_name,
const string& help,
bool _do_cluster=false)
:Request(method_name,"A:si",help),
do_cluster(_do_cluster)
const string& help)
:Request(method_name,"A:si",help)
{
auth_op = AuthRequest::MANAGE;
if ( do_cluster )
{
Nebula& nd = Nebula::instance();
clpool = nd.get_clpool();
}
else
{
clpool = 0;
}
Nebula& nd = Nebula::instance();
clpool = nd.get_clpool();
};
~RequestManagerDelete(){};
@ -65,7 +56,7 @@ protected:
virtual int get_cluster_id(PoolObjectSQL * object)
{
return -1;
return ClusterPool::NONE_CLUSTER_ID;
};
virtual int del_from_cluster(Cluster* cluster, int id, string& error_msg)
@ -74,7 +65,6 @@ protected:
};
private:
bool do_cluster;
ClusterPool * clpool;
};
@ -105,8 +95,7 @@ class VirtualNetworkDelete: public RequestManagerDelete
public:
VirtualNetworkDelete():
RequestManagerDelete("VirtualNetworkDelete",
"Deletes a virtual network",
true)
"Deletes a virtual network")
{
Nebula& nd = Nebula::instance();
pool = nd.get_vnpool();
@ -157,7 +146,7 @@ class HostDelete : public RequestManagerDelete
{
public:
HostDelete():
RequestManagerDelete("HostDelete", "Deletes a host", true)
RequestManagerDelete("HostDelete", "Deletes a host")
{
Nebula& nd = Nebula::instance();
pool = nd.get_hpool();
@ -227,7 +216,7 @@ class DatastoreDelete: public RequestManagerDelete
{
public:
DatastoreDelete():
RequestManagerDelete("DatastoreDelete", "Deletes a datastore", true)
RequestManagerDelete("DatastoreDelete", "Deletes a datastore")
{
Nebula& nd = Nebula::instance();
pool = nd.get_dspool();

View File

@ -107,6 +107,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
end
delhost_desc = <<-EOT.unindent
Deletes a Host from the given Cluster
EOT
# TODO: allow the second param to be [:range, :hostid_list]
command :delhost, delhost_desc, :clusterid, :hostid do
helper.perform_actions(args[0],options,"updated") do |cluster|
cluster.delhost(args[1].to_i)
end
end
adddatastore_desc = <<-EOT.unindent
Adds a Datastore to the given Cluster
EOT
@ -118,6 +129,17 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
end
deldatastore_desc = <<-EOT.unindent
Deletes a Datastore from the given Cluster
EOT
# TODO: allow the second param to be [:range, :datastoreid_list]
command :deldatastore, deldatastore_desc, :clusterid, :datastoreid do
helper.perform_actions(args[0],options,"updated") do |cluster|
cluster.deldatastore(args[1].to_i)
end
end
addvnet_desc = <<-EOT.unindent
Adds a Virtual Network to the given Cluster
EOT
@ -128,4 +150,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
cluster.addvnet(args[1].to_i)
end
end
delvnet_desc = <<-EOT.unindent
Deletes a Virtual Network from the given Cluster
EOT
# TODO: allow the second param to be [:range, :vnetid_list]
command :delvnet, delvnet_desc,:clusterid, :vnetid do
helper.perform_actions(args[0],options,"updated") do |cluster|
cluster.delvnet(args[1].to_i)
end
end
end

View File

@ -64,10 +64,15 @@ cmd=CommandParser::CmdParser.new(ARGV) do
Creates a new Datastore from the given template file
EOT
command :create, create_desc, :file, :clusterid do
command :create, create_desc, :file, [:clusterid, nil] do
helper.create_resource(options) do |datastore|
template=File.read(args[0])
datastore.allocate(template, args[1].to_i)
if args.size == 1
datastore.allocate(template)
else
datastore.allocate(template, args[1].to_i)
end
end
end

View File

@ -29,6 +29,9 @@
const string ClusterPool::DEFAULT_CLUSTER_NAME = "default";
const int ClusterPool::DEFAULT_CLUSTER_ID = 0;
const string ClusterPool::NONE_CLUSTER_NAME = "none";
const int ClusterPool::NONE_CLUSTER_ID = -1;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -28,8 +28,11 @@ module OpenNebula
:allocate => "cluster.allocate",
:delete => "cluster.delete",
:addhost => "cluster.addhost",
:delhost => "cluster.delhost",
:adddatastore => "cluster.adddatastore",
:addvnet => "cluster.addvnet"
:deldatastore => "cluster.deldatastore",
:addvnet => "cluster.addvnet",
:delvnet => "cluster.delvnet"
}
# Creates a Cluster description with just its identifier
@ -88,6 +91,19 @@ module OpenNebula
return rc
end
# Deletes a Host from this Cluster
# @param hid [Integer] Host ID
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def delhost(hid)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(CLUSTER_METHODS[:delhost], @pe_id, hid)
rc = nil if !OpenNebula.is_error?(rc)
return rc
end
# Adds a Datastore to this Cluster
# @param ds_id [Integer] Datastore ID
# @return [nil, OpenNebula::Error] nil in case of success, Error
@ -101,6 +117,19 @@ module OpenNebula
return rc
end
# Deletes a Datastore from this Cluster
# @param ds_id [Integer] Datastore ID
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def deldatastore(ds_id)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(CLUSTER_METHODS[:deldatastore], @pe_id, ds_id)
rc = nil if !OpenNebula.is_error?(rc)
return rc
end
# Adds a VNet to this Cluster
# @param vnet_id [Integer] VNet ID
# @return [nil, OpenNebula::Error] nil in case of success, Error
@ -114,6 +143,19 @@ module OpenNebula
return rc
end
# Deletes a VNet from this Cluster
# @param vnet_id [Integer] VNet ID
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def delvnet(vnet_id)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(CLUSTER_METHODS[:delvnet], @pe_id, vnet_id)
rc = nil if !OpenNebula.is_error?(rc)
return rc
end
# ---------------------------------------------------------------------
# Helpers to get information
# ---------------------------------------------------------------------

View File

@ -23,6 +23,7 @@ module OpenNebula
# Constants and Class attribute accessors
#######################################################################
NONE_CLUSTER_ID = -1
DEFAULT_CLUSTER_ID = 0
CLUSTER_POOL_METHODS = {

View File

@ -67,7 +67,7 @@ module OpenNebula
#
# @return [Integer, OpenNebula::Error] the new ID in case of
# success, error otherwise
def allocate(description, cluster_id)
def allocate(description, cluster_id=ClusterPool::NONE_CLUSTER_ID)
super(DATASTORE_METHODS[:allocate], description, cluster_id)
end

View File

@ -86,7 +86,7 @@ module OpenNebula
#
# @return [Integer, OpenNebula::Error] the new ID in case of
# success, error otherwise
def allocate(hostname,im,vmm,vnm,cluster_id=ClusterPool::DEFAULT_CLUSTER_ID)
def allocate(hostname,im,vmm,vnm,cluster_id=ClusterPool::NONE_CLUSTER_ID)
super(HOST_METHODS[:allocate],hostname,im,vmm,vnm,cluster_id)
end

View File

@ -327,8 +327,11 @@ void RequestManager::register_xml_methods()
// Cluster Methods
xmlrpc_c::methodPtr cluster_addhost(new ClusterAddHost());
xmlrpc_c::methodPtr cluster_delhost(new ClusterDelHost());
xmlrpc_c::methodPtr cluster_addds(new ClusterAddDatastore());
xmlrpc_c::methodPtr cluster_delds(new ClusterDelDatastore());
xmlrpc_c::methodPtr cluster_addvnet(new ClusterAddVNet());
xmlrpc_c::methodPtr cluster_delvnet(new ClusterDelVNet());
/* VM related methods */
RequestManagerRegistry.addMethod("one.vm.deploy", vm_deploy);
@ -423,9 +426,13 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.cluster.allocate",cluster_allocate);
RequestManagerRegistry.addMethod("one.cluster.delete", cluster_delete);
RequestManagerRegistry.addMethod("one.cluster.info", cluster_info);
RequestManagerRegistry.addMethod("one.cluster.addhost", cluster_addhost);
RequestManagerRegistry.addMethod("one.cluster.delhost", cluster_delhost);
RequestManagerRegistry.addMethod("one.cluster.adddatastore", cluster_addds);
RequestManagerRegistry.addMethod("one.cluster.deldatastore", cluster_delds);
RequestManagerRegistry.addMethod("one.cluster.addvnet", cluster_addvnet);
RequestManagerRegistry.addMethod("one.cluster.delvnet", cluster_delvnet);
RequestManagerRegistry.addMethod("one.clusterpool.info",clusterpool_info);
};

View File

@ -44,7 +44,7 @@ bool RequestManagerAllocate::allocate_authorization(
ar.add_create_auth(auth_object, tmpl_str);
if ( do_cluster )
if ( cluster_perms->oid != ClusterPool::NONE_CLUSTER_ID )
{
ar.add_auth(AuthRequest::ADMIN, *cluster_perms); // ADMIN CLUSTER
}
@ -107,8 +107,8 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
int rc, id;
Cluster * cluster = 0;
int cluster_id = -1;
string cluster_name = "";
int cluster_id = ClusterPool::NONE_CLUSTER_ID;
string cluster_name = ClusterPool::NONE_CLUSTER_NAME;
PoolObjectAuth cluster_perms;
if ( do_template == true )
@ -128,10 +128,10 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
}
}
if ( do_cluster == true )
{
cluster_id = get_cluster_id(params);
cluster_id = get_cluster_id(params);
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
{
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att,
cluster_perms, cluster_name);
@ -141,6 +141,10 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
return;
}
}
else
{
cluster_perms.oid = ClusterPool::NONE_CLUSTER_ID;
}
if ( allocate_authorization(tmpl, att, &cluster_perms) == false )
{
@ -156,7 +160,7 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params,
return;
}
if ( do_cluster == true )
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
{
cluster = clpool->get(cluster_id, true);
@ -234,21 +238,6 @@ int VirtualNetworkAllocate::pool_allocate(
cluster_id, cluster_name, error_str);
}
/* -------------------------------------------------------------------------- */
int VirtualNetworkAllocate::get_cluster_id(xmlrpc_c::paramList const& paramList)
{
return ClusterPool::DEFAULT_CLUSTER_ID;
}
/* -------------------------------------------------------------------------- */
int VirtualNetworkAllocate::add_to_cluster(
Cluster* cluster, int id, string& error_msg)
{
return cluster->add_vnet(id, error_msg);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -413,17 +402,6 @@ int HostAllocate::pool_allocate(
/* -------------------------------------------------------------------------- */
int HostAllocate::get_cluster_id(xmlrpc_c::paramList const& paramList)
{
return xmlrpc_c::value_int(paramList.getInt(5));
}
/* -------------------------------------------------------------------------- */
int HostAllocate::add_to_cluster(Cluster* cluster, int id, string& error_msg)
{
return cluster->add_host(id, error_msg);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -492,21 +470,6 @@ int DatastoreAllocate::pool_allocate(
return dspool->allocate(ds_tmpl, &id, cluster_id, cluster_name, error_str);
}
/* -------------------------------------------------------------------------- */
int DatastoreAllocate::get_cluster_id(xmlrpc_c::paramList const& paramList)
{
return xmlrpc_c::value_int(paramList.getInt(2));
}
/* -------------------------------------------------------------------------- */
int DatastoreAllocate::add_to_cluster(
Cluster* cluster, int id, string& error_msg)
{
return cluster->add_datastore(id, error_msg);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -22,14 +22,12 @@ using namespace std;
/* ------------------------------------------------------------------------- */
void RequestManagerCluster::add_generic(
xmlrpc_c::paramList const& paramList,
int cluster_id,
int object_id,
RequestAttributes& att,
PoolSQL * pool,
PoolObjectSQL::ObjectType type)
{
int cluster_id = xmlrpc_c::value_int(paramList.getInt(1));
int object_id = xmlrpc_c::value_int(paramList.getInt(2));
int rc;
string cluster_name;
@ -47,11 +45,18 @@ void RequestManagerCluster::add_generic(
int old_cluster_id;
string old_cluster_name;
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms, cluster_name);
if ( rc == -1 )
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
{
return;
rc = get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att, c_perms, cluster_name);
if ( rc == -1 )
{
return;
}
}
else
{
cluster_name = ClusterPool::NONE_CLUSTER_NAME;
}
rc = get_info(pool, object_id, type, att, obj_perms, obj_name);
@ -65,7 +70,11 @@ void RequestManagerCluster::add_generic(
{
AuthRequest ar(att.uid, att.gid);
ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
{
ar.add_auth(auth_op, c_perms); // ADMIN CLUSTER
}
ar.add_auth(AuthRequest::ADMIN, obj_perms); // ADMIN OBJECT
if (UserPool::authorize(ar) == -1)
@ -107,73 +116,78 @@ void RequestManagerCluster::add_generic(
object->unlock();
// ------------- Add object to new cluster ---------------------
cluster = clpool->get(cluster_id, true);
if ( cluster == 0 )
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID )
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::CLUSTER),cluster_id),
att);
cluster = clpool->get(cluster_id, true);
// Rollback
get(object_id, true, &object, &cluster_obj);
if ( object != 0 )
if ( cluster == 0 )
{
cluster_obj->set_cluster(old_cluster_id, old_cluster_name);
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::CLUSTER),cluster_id),
att);
pool->update(object);
// Rollback
get(object_id, true, &object, &cluster_obj);
object->unlock();
if ( object != 0 )
{
cluster_obj->set_cluster(old_cluster_id, old_cluster_name);
pool->update(object);
object->unlock();
}
return;
}
return;
}
if ( add_object(cluster, object_id, err_msg) < 0 )
{
cluster->unlock();
failure_response(INTERNAL,
request_error("Cannot add object to cluster", err_msg),
att);
return;
}
clpool->update(cluster);
if ( add_object(cluster, object_id, err_msg) < 0 )
{
cluster->unlock();
failure_response(INTERNAL,
request_error("Cannot add host to cluster", err_msg),
att);
return;
}
clpool->update(cluster);
cluster->unlock();
// ------------- Remove host from old cluster ---------------------
cluster = clpool->get(old_cluster_id, true);
if ( cluster == 0 )
if ( old_cluster_id != ClusterPool::NONE_CLUSTER_ID )
{
// This point should be unreachable.
// The old cluster is not empty (at least has the host_id),
// so it cannot be deleted
success_response(cluster_id, att);
return;
}
cluster = clpool->get(old_cluster_id, true);
if ( cluster == 0 )
{
// This point should be unreachable.
// The old cluster is not empty (at least has the host_id),
// so it cannot be deleted
success_response(cluster_id, att);
return;
}
if ( del_object(cluster, object_id, err_msg) < 0 )
{
cluster->unlock();
failure_response(INTERNAL,
request_error("Cannot remove object from cluster", err_msg),
att);
return;
}
clpool->update(cluster);
if ( del_object(cluster, object_id, err_msg) < 0 )
{
cluster->unlock();
failure_response(INTERNAL,
request_error("Cannot remove host from cluster", err_msg),
att);
return;
}
clpool->update(cluster);
cluster->unlock();
success_response(cluster_id, att);
return;

View File

@ -109,18 +109,13 @@ int RequestManagerDelete::drop(
PoolObjectSQL * object,
string& error_msg)
{
int cluster_id = -1;
if ( do_cluster )
{
cluster_id = get_cluster_id(object);
}
int cluster_id = get_cluster_id(object);
int rc = pool->drop(object, error_msg);
object->unlock();
if ( do_cluster == true && rc == 0 )
if ( cluster_id != ClusterPool::NONE_CLUSTER_ID && rc == 0 )
{
Cluster * cluster = clpool->get(cluster_id, true);