1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

Feature #1112: refactor Request::get_info

This commit is contained in:
Carlos Martín 2012-02-28 17:59:03 +01:00
parent 7b9e27cffd
commit 07eba81abd
7 changed files with 50 additions and 86 deletions

View File

@ -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);
};
/* -------------------------------------------------------------------------- */

View File

@ -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);
};
/* ------------------------------------------------------------------------- */

View File

@ -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);
};
/* ------------------------------------------------------------------------- */

View File

@ -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;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -328,24 +328,10 @@ void HostAllocate::request_execute(
ClusterPool * clpool = nd.get_clpool();
HostPool * hpool = static_cast<HostPool *>(pool);
Cluster * cluster;
// ------------------------- 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();
get_info(clpool, cluster_id, PoolObjectSQL::CLUSTER, att,
cluster_perms, cluster_name);
// ------------- Set authorization request for non-oneadmin's -------------

View File

@ -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)
{

View File

@ -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,