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

feature #1288: Update quotas for chown operations

This commit is contained in:
Ruben S. Montero 2012-06-08 01:50:15 +02:00
parent 79a040ce17
commit 654e840871
4 changed files with 143 additions and 5 deletions

View File

@ -75,6 +75,32 @@ protected:
string session; /**< Session from ONE XML-RPC API */
xmlrpc_c::value * retval; /**< Return value from libxmlrpc-c */
RequestAttributes(){};
RequestAttributes(const RequestAttributes& ra)
{
uid = ra.uid;
gid = ra.gid;
uname = ra.uname;
gname = ra.gname;
session = ra.session;
retval = ra.retval;
};
RequestAttributes(int _uid, int _gid, const RequestAttributes& ra)
{
uid = _uid;
gid = _gid;
uname = "";
gname = "";
session = ra.session;
retval = ra.retval;
};
};
/* -------- Static (shared among request of the same method) -------- */

View File

@ -52,6 +52,11 @@ protected:
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
PoolObjectSQL * get_and_quota(int oid,
int new_uid,
int new_gid,
RequestAttributes& att);
};
/* ------------------------------------------------------------------------- */

View File

@ -197,6 +197,9 @@ class OneUserHelper < OpenNebulaHelper::OneHelper
table
end
#---------------------------------------------------------------------------
# Tables to format user quotas
#---------------------------------------------------------------------------
def format_ds_quota()
table = CLIHelper::ShowTable.new(nil, self) do
column :"DATASTORE ID", "", :left, :size=>12 do |d|

View File

@ -23,6 +23,96 @@
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
PoolObjectSQL * RequestManagerChown::get_and_quota(
int oid,
int new_uid,
int new_gid,
RequestAttributes& att)
{
Template * tmpl;
int old_uid;
int old_gid;
PoolObjectSQL * object;
object = pool->get(oid,true);
if ( object == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(auth_object), oid),
att);
return 0;
}
if ( new_uid < 0 )
{
return object;
}
if ( auth_object == PoolObjectSQL::VM )
{
tmpl = (static_cast<VirtualMachine*>(object))->clone_template();
}
else
{
Image * img = static_cast<Image *>(object);
tmpl = new Template;
tmpl->add("DATASTORE", img->get_ds_id());
tmpl->add("SIZE", img->get_size());
}
old_uid = object->get_uid();
old_gid = object->get_gid();
object->unlock();
RequestAttributes att_new(new_uid, new_gid, att);
RequestAttributes att_old(old_uid, old_gid, att);
if ( new_uid != 0 )
{
if ( quota_authorization(tmpl, att_new) == false )
{
delete tmpl;
return 0;
}
}
if ( old_uid != 0 )
{
quota_rollback(tmpl, att_old);
}
object = pool->get(oid,true);
if ( object == 0 )
{
if ( new_uid != 0 )
{
quota_rollback(tmpl, att_new);
}
if ( old_uid != 0 )
{
quota_authorization(tmpl, att_old);
}
failure_response(NO_EXISTS,
get_error(object_name(auth_object), oid),
att);
}
delete tmpl;
return object;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
@ -102,13 +192,27 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList,
}
}
// ------------- Update the object ---------------------
// --------------- Update the object and check quotas ----------------------
object = pool->get(oid,true);
if ( auth_object == PoolObjectSQL::VM ||
auth_object == PoolObjectSQL::IMAGE )
{
object = get_and_quota(oid, noid, ngid, att);
}
else
{
object = pool->get(oid,true);
if ( object == 0 )
{
failure_response(NO_EXISTS,get_error(object_name(auth_object),oid),att);
if ( object == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(auth_object), oid),
att);
}
}
if ( object == 0 )
{
return;
}