mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Merge branch 'feature-1112' of git.opennebula.org:one into feature-1112
This commit is contained in:
commit
071500b5db
@ -219,6 +219,26 @@ protected:
|
||||
* @return string for logging
|
||||
*/
|
||||
string allocate_error (PoolObjectSQL::ObjectType obj, const string& error);
|
||||
|
||||
/**
|
||||
* Locks the requested object, gets information, and unlocks it
|
||||
*
|
||||
* @param pool object pool
|
||||
* @param id of the object
|
||||
* @param type of the object
|
||||
* @param att the specific request attributes
|
||||
*
|
||||
* @param perms returns the object's permissions
|
||||
* @param name returns the object's name
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
int get_info (PoolSQL * pool,
|
||||
int id,
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -52,13 +52,6 @@ protected:
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
|
||||
int get_info (PoolSQL * pool,
|
||||
int id,
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -67,13 +67,6 @@ protected:
|
||||
virtual int del_object(Cluster* cluster, int id, string& error_msg) = 0;
|
||||
|
||||
virtual void get(int oid, bool lock, PoolObjectSQL ** object, Clusterable ** cluster_obj) = 0;
|
||||
|
||||
int get_info (PoolSQL * pool,
|
||||
int id,
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -135,6 +135,10 @@ public:
|
||||
};
|
||||
|
||||
~HostDelete(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
int drop(int oid, PoolObjectSQL * object, string& error_msg);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
@ -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
|
||||
|
@ -297,3 +297,31 @@ string Request::allocate_error (const string& error)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Request::get_info(
|
||||
PoolSQL * pool,
|
||||
int id,
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name)
|
||||
{
|
||||
PoolObjectSQL * ob;
|
||||
|
||||
if ((ob = pool->get(id,true)) == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(type), id), att);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ob->get_permissions(perms);
|
||||
|
||||
name = ob->get_name();
|
||||
|
||||
ob->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -306,27 +306,66 @@ 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);
|
||||
// ------------------------- Check Cluster exists ------------------------
|
||||
|
||||
return hpool->allocate(&id, host, im_mad, vmm_mad, vnm_mad,
|
||||
cluster_id, cluster_name, error_str);
|
||||
get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att,
|
||||
cluster_perms, cluster_name);
|
||||
|
||||
// ------------- 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);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -23,33 +23,6 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int RequestManagerChown::get_info (PoolSQL * pool,
|
||||
int id,
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name)
|
||||
{
|
||||
PoolObjectSQL * ob;
|
||||
|
||||
if ((ob = pool->get(id,true)) == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(type), id), att);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ob->get_permissions(perms);
|
||||
|
||||
name = ob->get_name();
|
||||
|
||||
ob->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
|
@ -21,35 +21,6 @@ using namespace std;
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
// TODO: same method in RequestManagerChown, should be moved to Request
|
||||
|
||||
int RequestManagerCluster::get_info (PoolSQL * pool,
|
||||
int id,
|
||||
PoolObjectSQL::ObjectType type,
|
||||
RequestAttributes& att,
|
||||
PoolObjectAuth& perms,
|
||||
string& name)
|
||||
{
|
||||
PoolObjectSQL * ob;
|
||||
|
||||
if ((ob = pool->get(id,true)) == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error(object_name(type), id), att);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ob->get_permissions(perms);
|
||||
|
||||
name = ob->get_name();
|
||||
|
||||
ob->unlock();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerCluster::add_generic(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att,
|
||||
|
@ -153,6 +153,43 @@ int ImageDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int HostDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
Host * host = static_cast<Host *>(object);
|
||||
int cluster_id = host->get_cluster_id();
|
||||
|
||||
int rc = pool->drop(object, error_msg);
|
||||
|
||||
object->unlock();
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
ClusterPool * clpool = nd.get_clpool();
|
||||
|
||||
Cluster * cluster = clpool->get(cluster_id, true);
|
||||
|
||||
if( cluster != 0 )
|
||||
{
|
||||
rc = cluster->del_host(oid, error_msg);
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
cluster->unlock();
|
||||
return rc;
|
||||
}
|
||||
|
||||
clpool->update(cluster);
|
||||
|
||||
cluster->unlock();
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
int UserDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
|
||||
{
|
||||
User * user = static_cast<User *>(object);
|
||||
|
Loading…
x
Reference in New Issue
Block a user