diff --git a/include/RequestManagerAllocate.h b/include/RequestManagerAllocate.h index 78efb9965b..4492a16996 100644 --- a/include/RequestManagerAllocate.h +++ b/include/RequestManagerAllocate.h @@ -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) diff --git a/src/rm/Request.cc b/src/rm/Request.cc index 74d321d139..9a14edfbb4 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -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; } diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 600a02c09e..910d6b4e13 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -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(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(tmpl); + VirtualMachinePool * vmpool = static_cast(pool); + + return vmpool->allocate(uid, gid, ttmpl, &id, error_str, false); +} + + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */