mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
feature #622: VirtualMachineAllocate method in Request Manager
This commit is contained in:
parent
d25384092b
commit
0a13288330
@ -48,7 +48,7 @@ protected:
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList);
|
||||
|
||||
bool allocate_authorization(Template * obj_template);
|
||||
virtual bool allocate_authorization(Template * obj_template);
|
||||
|
||||
string allocate_error (char *error);
|
||||
|
||||
@ -67,6 +67,40 @@ private:
|
||||
bool do_template;
|
||||
};
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class VirtualMachineAllocate: public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
VirtualMachineAllocate():
|
||||
RequestManagerAllocate("VirtualMachineAllocate",
|
||||
"Allocates a new virtual machine",
|
||||
"A:ss",
|
||||
true)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_vmpool();
|
||||
auth_object = AuthRequest::VM;
|
||||
};
|
||||
|
||||
~VirtualMachineAllocate(){};
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
Template * get_object_template()
|
||||
{
|
||||
return new VirtualMachineTemplate;
|
||||
};
|
||||
|
||||
int pool_allocate(xmlrpc_c::paramList const& _paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str);
|
||||
|
||||
bool allocate_authorization(Template * obj_template);
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
@ -163,7 +197,6 @@ public:
|
||||
string& error_str);
|
||||
};
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
@ -246,7 +279,7 @@ class GroupAllocate: public RequestManagerAllocate
|
||||
{
|
||||
public:
|
||||
GroupAllocate():
|
||||
RequestManagerAllocate("GroupInfo",
|
||||
RequestManagerAllocate("GroupAllocate",
|
||||
"Allocates a new group",
|
||||
"A:ss",
|
||||
false)
|
||||
|
@ -69,7 +69,7 @@ bool Request::basic_authorization(int oid)
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error("USER",oid)); //TODO
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object),oid));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -86,7 +86,7 @@ bool Request::basic_authorization(int oid)
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
failure_response(AUTHORIZATION, //TODO
|
||||
authorization_error("INFO","USER",oid,-1));
|
||||
authorization_error("INFO",object_name(auth_object),oid,-1));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -96,6 +96,36 @@ bool RequestManagerAllocate::allocate_authorization(Template * tmpl)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
bool VirtualMachineAllocate::allocate_authorization(Template * tmpl)
|
||||
{
|
||||
if ( uid == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
AuthRequest ar(uid);
|
||||
string t64;
|
||||
|
||||
VirtualMachineTemplate * ttmpl = static_cast<VirtualMachineTemplate *>(tmpl);
|
||||
|
||||
ar.add_auth(auth_object,tmpl->to_xml(t64),auth_op,uid,false);
|
||||
|
||||
VirtualMachine::set_auth_request(uid, ar, ttmpl);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
failure_response(AUTHORIZATION, //TODO
|
||||
authorization_error("INFO","USER",uid,-1));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params)
|
||||
{
|
||||
Template * tmpl = 0;
|
||||
@ -137,6 +167,21 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params)
|
||||
success_response(id);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachineAllocate::pool_allocate(xmlrpc_c::paramList const& paramList,
|
||||
Template * tmpl,
|
||||
int& id,
|
||||
string& error_str)
|
||||
{
|
||||
VirtualMachineTemplate * ttmpl = static_cast<VirtualMachineTemplate *>(tmpl);
|
||||
VirtualMachinePool * vmpool = static_cast<VirtualMachinePool *>(pool);
|
||||
|
||||
return vmpool->allocate(uid, gid, ttmpl, &id, error_str, false);
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user