mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-26 10:03:37 +03:00
Feature #1112: Make cluster parameter mandatory for new hosts
This commit is contained in:
parent
c8d1af5e8a
commit
f722dafb43
@ -207,7 +207,7 @@ public:
|
||||
HostAllocate():
|
||||
RequestManagerAllocate("HostAllocate",
|
||||
"Allocates a new host",
|
||||
"A:sssss",
|
||||
"A:sssssi",
|
||||
false)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
@ -217,11 +217,10 @@ public:
|
||||
|
||||
~HostAllocate(){};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str,
|
||||
RequestAttributes& att);
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -61,9 +61,13 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
EOT
|
||||
|
||||
command :create, create_desc, :hostname, :im_mad, :vmm_mad,
|
||||
:vnm_mad do
|
||||
:vnm_mad, [:clusterid, nil] do
|
||||
helper.create_resource(options) do |host|
|
||||
host.allocate(args[0], args[1], args[2], args[3])
|
||||
if args[4]
|
||||
host.allocate(args[0], args[1], args[2], args[3])
|
||||
else
|
||||
host.allocate(args[0], args[1], args[2], args[3], args[4].to_i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -23,6 +23,8 @@ module OpenNebula
|
||||
# Constants and Class attribute accessors
|
||||
#######################################################################
|
||||
|
||||
DEFAULT_CLUSTER_ID = 0
|
||||
|
||||
CLUSTER_POOL_METHODS = {
|
||||
:info => "clusterpool.info"
|
||||
}
|
||||
|
@ -82,11 +82,12 @@ module OpenNebula
|
||||
# @param im [String] Name of the im_driver (information/monitoring)
|
||||
# @param vmm [String] Name of the vmm_driver (hypervisor)
|
||||
# @param tm [String] Name of the vnm_driver (networking)
|
||||
# @param cluster_id [Integer] Id of the cluster
|
||||
#
|
||||
# @return [Integer, OpenNebula::Error] the new ID in case of
|
||||
# success, error otherwise
|
||||
def allocate(hostname,im,vmm,vnm)
|
||||
super(HOST_METHODS[:allocate],hostname,im,vmm,vnm)
|
||||
def allocate(hostname,im,vmm,vnm,cluster_id=ClusterPool::DEFAULT_CLUSTER_ID)
|
||||
super(HOST_METHODS[:allocate],hostname,im,vmm,vnm,cluster_id)
|
||||
end
|
||||
|
||||
# Deletes the Host
|
||||
|
@ -306,27 +306,80 @@ int TemplateAllocate::pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int HostAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str,
|
||||
RequestAttributes& att)
|
||||
void HostAllocate::request_execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
string error_str;
|
||||
string cluster_name;
|
||||
string ds_data;
|
||||
int rc, id;
|
||||
|
||||
PoolObjectAuth cluster_perms;
|
||||
|
||||
string host = xmlrpc_c::value_string(paramList.getString(1));
|
||||
string im_mad = xmlrpc_c::value_string(paramList.getString(2));
|
||||
string vmm_mad = xmlrpc_c::value_string(paramList.getString(3));
|
||||
string vnm_mad = xmlrpc_c::value_string(paramList.getString(4));
|
||||
int cluster_id = xmlrpc_c::value_int(paramList.getInt(5));
|
||||
|
||||
// TODO: include another int parameter for the cluster?
|
||||
int cluster_id = ClusterPool::DEFAULT_CLUSTER_ID;
|
||||
string cluster_name = ClusterPool::DEFAULT_CLUSTER_NAME;
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
// TODO: Add to auth request CLUSTER MANAGE or ADMIN
|
||||
ClusterPool * clpool = nd.get_clpool();
|
||||
HostPool * hpool = static_cast<HostPool *>(pool);
|
||||
|
||||
HostPool * hpool = static_cast<HostPool *>(pool);
|
||||
Cluster * cluster;
|
||||
|
||||
return hpool->allocate(&id, host, im_mad, vmm_mad, vnm_mad,
|
||||
cluster_id, cluster_name, error_str);
|
||||
// ------------------------- Check Cluster exists ------------------------
|
||||
|
||||
if ((cluster = clpool->get(cluster_id,true)) == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS,
|
||||
get_error(object_name(PoolObjectSQL::CLUSTER), cluster_id),
|
||||
att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
cluster->get_permissions(cluster_perms);
|
||||
|
||||
cluster_name = cluster->get_name();
|
||||
|
||||
cluster->unlock();
|
||||
|
||||
// ------------- Set authorization request for non-oneadmin's -------------
|
||||
|
||||
if ( att.uid != 0 )
|
||||
{
|
||||
AuthRequest ar(att.uid, att.gid);
|
||||
string tmpl_str = "";
|
||||
|
||||
ar.add_create_auth(auth_object, tmpl_str); // CREATE HOST
|
||||
|
||||
ar.add_auth(AuthRequest::ADMIN, cluster_perms); // ADMIN CLUSTER
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
failure_response(AUTHORIZATION,
|
||||
authorization_error(ar.message, att),
|
||||
att);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------- Allocate Host --------------------------------------------
|
||||
|
||||
rc = hpool->allocate(&id, host, im_mad, vmm_mad, vnm_mad,
|
||||
cluster_id, cluster_name, error_str);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
failure_response(INTERNAL, allocate_error(error_str), att);
|
||||
return;
|
||||
}
|
||||
|
||||
success_response(id, att);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
Loading…
x
Reference in New Issue
Block a user