diff --git a/include/RequestManager.h b/include/RequestManager.h index 5e4b47fe45..f76af653d8 100644 --- a/include/RequestManager.h +++ b/include/RequestManager.h @@ -173,6 +173,16 @@ private: // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- + + /** + * Logs authorization errors + * @param method name of the RM method where the error arose + * @param action authorization action + * @param object object that needs to be authorized + * @param uid user that is authorized + * @param id id of the object, -1 for Pool + * @returns string for logging + */ static string authorization_error (const string& method, const string &action, const string &object, @@ -180,7 +190,7 @@ private: int id) { ostringstream oss; - oss << "[" << method << "]" << " User [" << uid << "] not authorized " + oss << "[" << method << "]" << " User [" << uid << "] not authorized" << " to perform " << action << " on " << object; @@ -196,6 +206,11 @@ private: return oss.str(); } + /** + * Logs authenticate errors + * @param method name of the RM method where the error arose + * @returns string for logging + */ static string authenticate_error (const string& method) { ostringstream oss; @@ -205,7 +220,14 @@ private: return oss.str(); } - + + /** + * Logs get object errors + * @param method name of the RM method where the error arose + * @param object over which the get failed + * @param id of the object over which the get failed + * @returns string for logging + */ static string get_error (const string& method, const string &object, int id) @@ -227,6 +249,16 @@ private: return oss.str(); } + /** + * Logs action errors + * @param method name of the RM method where the error arose + * @param action that triggered the error + * @param object over which the action was applied + * @param id id of the object, -1 for Pool, -2 for no-id objects + * (allocate error, parse error) + * @param rc returned error code (NULL to ignore) + * @returns string for logging + */ static string action_error (const string& method, const string &action, const string &object, @@ -271,8 +303,14 @@ private: { public: VirtualMachineAllocate( - UserPool * _upool): - upool(_upool) + VirtualMachinePool * _vmpool, + VirtualNetworkPool * _vnpool, + ImagePool * _ipool, + UserPool * _upool): + vmpool(_vmpool), + vnpool(_vnpool), + ipool(_ipool), + upool(_upool) { _signature="A:ss"; _help="Allocates a virtual machine in the pool"; @@ -284,6 +322,9 @@ private: xmlrpc_c::paramList const& paramList, xmlrpc_c::value * const retval); private: + VirtualMachinePool * vmpool; + VirtualNetworkPool * vnpool; + ImagePool * ipool; UserPool * upool; }; @@ -294,8 +335,8 @@ private: public: VirtualMachineDeploy( VirtualMachinePool * _vmpool, - HostPool * _hpool, - UserPool * _upool): + HostPool * _hpool, + UserPool * _upool): vmpool(_vmpool), hpool(_hpool), upool(_upool) diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index cf3fb033e0..a3f4b3af39 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -214,7 +214,7 @@ void RequestManager::do_action( void RequestManager::register_xml_methods() { xmlrpc_c::methodPtr vm_allocate(new - RequestManager::VirtualMachineAllocate(upool)); + RequestManager::VirtualMachineAllocate(vmpool, vnpool, ipool, upool)); xmlrpc_c::methodPtr vm_deploy(new RequestManager::VirtualMachineDeploy(vmpool,hpool,upool)); diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index c9fd655bcd..f51d7c8470 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -34,11 +34,6 @@ void RequestManager::VirtualMachineAllocate::execute( int vid, uid; int rc; - Nebula& nd = Nebula::instance(); - ImagePool * ipool = nd.get_ipool(); - VirtualNetworkPool* vnpool= nd.get_vnpool(); - VirtualMachinePool* vmpool= nd.get_vmpool(); - ostringstream oss; vector arrayData; @@ -96,7 +91,7 @@ void RequestManager::VirtualMachineAllocate::execute( continue; } - ipool->authorize_disk(vector,&ar); + VirtualMachineAllocate::ipool->authorize_disk(vector,&ar); } num = vm_template->get("NIC",vectors); @@ -110,7 +105,7 @@ void RequestManager::VirtualMachineAllocate::execute( continue; } - vnpool->authorize_nic(vector,&ar); + VirtualMachineAllocate::vnpool->authorize_nic(vector,&ar); } ar.add_auth(AuthRequest::VM, @@ -128,7 +123,7 @@ void RequestManager::VirtualMachineAllocate::execute( //-------------------------------------------------------------------------- // Allocate the VirtualMAchine //-------------------------------------------------------------------------- - rc = vmpool->allocate(uid,vm_template,&vid,false); + rc = VirtualMachineAllocate::vmpool->allocate(uid,vm_template,&vid,false); if ( rc < 0 ) { @@ -157,10 +152,10 @@ error_authorize: goto error_common; error_parse: - oss.str(action_error(method_name, "PARSE", "VM TEMPLATE",-2,rc)); + oss << action_error(method_name, "PARSE", "VM TEMPLATE",-2,rc); if (error_msg != 0) { - oss << "Reason: " << error_msg; + oss << ". Reason: " << error_msg; free(error_msg); } diff --git a/src/rm/RequestManagerImageAllocate.cc b/src/rm/RequestManagerImageAllocate.cc index 8fc05ee328..84e1fd287f 100644 --- a/src/rm/RequestManagerImageAllocate.cc +++ b/src/rm/RequestManagerImageAllocate.cc @@ -127,10 +127,10 @@ error_authorize: goto error_common; error_parse: - oss.str(action_error(method_name, "PARSE", "IMAGE TEMPLATE",-2,rc)); + oss << action_error(method_name, "PARSE", "IMAGE TEMPLATE",-2,rc); if (error_msg != 0) { - oss << "Reason: " << error_msg; + oss << ". Reason: " << error_msg; free(error_msg); } diff --git a/src/rm/RequestManagerVirtualNetworkAllocate.cc b/src/rm/RequestManagerVirtualNetworkAllocate.cc index 761c47baa3..0856d29d81 100644 --- a/src/rm/RequestManagerVirtualNetworkAllocate.cc +++ b/src/rm/RequestManagerVirtualNetworkAllocate.cc @@ -127,10 +127,10 @@ error_authorize: goto error_common; error_parse: - oss.str(action_error(method_name, "PARSE", "VNET TEMPLATE",-2,rc)); + oss << action_error(method_name, "PARSE", "VNET TEMPLATE",-2,rc); if (error_msg != 0) { - oss << "Reason: " << error_msg; + oss << ". Reason: " << error_msg; free(error_msg); }