mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
This commit is contained in:
parent
e3a930dd10
commit
ca3d0154c8
@ -153,22 +153,16 @@ protected:
|
||||
* @param id of the object over which the get failed
|
||||
* @return string for logging
|
||||
*/
|
||||
string get_error (const string &object,
|
||||
int id);
|
||||
string get_error (const string &object, int id);
|
||||
|
||||
/**
|
||||
* Logs action errors
|
||||
* @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)
|
||||
* @param err_desc brief description of the error
|
||||
* @param err_detail additional error details from Managers & Pools
|
||||
* @return string for logging
|
||||
*/
|
||||
string action_error (const string &action,
|
||||
const string &object,
|
||||
int id,
|
||||
int rc);
|
||||
string request_error (const string &err_desc, const string &err_detail);
|
||||
|
||||
/**
|
||||
* Logs allocate errors
|
||||
* @param message with the allocate error details
|
||||
@ -176,6 +170,14 @@ protected:
|
||||
*/
|
||||
string allocate_error (const string& error);
|
||||
|
||||
/**
|
||||
* Logs allocate errors for a given resource
|
||||
* @param obj the resource
|
||||
* @param message with the allocate error details
|
||||
* @return string for logging
|
||||
*/
|
||||
string allocate_error (AuthRequest::Object obj, const string& error);
|
||||
|
||||
/**
|
||||
* Logs allocate errors
|
||||
* @param message with the allocate error details (parsing)
|
||||
|
@ -51,8 +51,6 @@ protected:
|
||||
string& error_str) = 0;
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
string leases_error (const string& error);
|
||||
|
||||
string leases_error (char * error);
|
||||
};
|
||||
|
||||
|
@ -223,31 +223,33 @@ string Request::get_error (const string &object,
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string Request::action_error (const string &action,
|
||||
const string &object,
|
||||
int id,
|
||||
int rc)
|
||||
string Request::request_error (const string &err_desc, const string &err_detail)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "[" << method_name << "]" << " Error trying to " << action << " "
|
||||
<< object;
|
||||
oss << "[" << method_name << "]" << err_desc;
|
||||
|
||||
switch(id)
|
||||
if (!err_detail.empty())
|
||||
{
|
||||
case -2:
|
||||
break;
|
||||
case -1:
|
||||
oss << "Pool.";
|
||||
break;
|
||||
default:
|
||||
oss << " [" << id << "].";
|
||||
break;
|
||||
oss << err_detail;
|
||||
}
|
||||
|
||||
if ( rc != 0 )
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string Request::allocate_error (AuthRequest::Object obj, const string& error)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "[" << method_name << "]" << " Error allocating a new "
|
||||
<< object_name(obj) << ".";
|
||||
|
||||
if (!error.empty())
|
||||
{
|
||||
oss << " Returned error code [" << rc << "].";
|
||||
oss << " " << error;
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
|
@ -1,167 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::GenericAddDelGroup::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int object_id, object_owner;
|
||||
int group_id, group_owner;
|
||||
int uid, rc;
|
||||
|
||||
PoolSQL * object_pool = rm->get_pool(object_type);
|
||||
PoolSQL * group_pool = rm->get_pool(group_type);
|
||||
string method_name = rm->get_method_prefix(object_type) + "Add";
|
||||
|
||||
PoolObjectSQL * object = 0;
|
||||
PoolObjectSQL * group = 0;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
oss << method_name << " invoked";
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,oss);
|
||||
oss.str("");
|
||||
|
||||
// Get the parameters
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
object_id = xmlrpc_c::value_int (paramList.getInt(1));
|
||||
group_id = xmlrpc_c::value_int (paramList.getInt(2));
|
||||
|
||||
// Authenticate the user
|
||||
uid = rm->upool->authenticate(session);
|
||||
|
||||
if ( uid == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// Get object owner
|
||||
object = object_pool->get(object_id,true);
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
goto error_get_object;
|
||||
}
|
||||
|
||||
object_owner = object->get_uid();
|
||||
|
||||
object->unlock();
|
||||
object = 0;
|
||||
|
||||
// Get group owner
|
||||
group = group_pool->get(group_id,true);
|
||||
|
||||
if ( group == 0 )
|
||||
{
|
||||
goto error_get_group;
|
||||
}
|
||||
|
||||
group_owner = group->get_uid();
|
||||
|
||||
group->unlock();
|
||||
group = 0;
|
||||
|
||||
// Authorize the operation
|
||||
if ( uid != 0 ) // rc == 0 means oneadmin
|
||||
{
|
||||
AuthRequest ar(uid);
|
||||
|
||||
ar.add_auth(object_type, object_id, AuthRequest::MANAGE, 0, false);
|
||||
ar.add_auth(group_type, group_id, AuthRequest::MANAGE, 0, false);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the object_id to the group and, if the object keeps a list of the
|
||||
// groups it belongs to, the group_id to it.
|
||||
rc = rm->add_object_group(object_type,group_type, object_id, group_id, oss);
|
||||
|
||||
if( rc != 0 )
|
||||
{
|
||||
goto error_add_object_group;
|
||||
}
|
||||
|
||||
// All nice, return success to the client
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
|
||||
|
||||
// Copy arrayresult into retval mem space
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult; // and get rid of the original
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_get_object:
|
||||
oss.str(get_error(method_name, object_type, object_id));
|
||||
goto error_common;
|
||||
|
||||
error_get_group:
|
||||
oss.str(get_error(method_name, group_type, group_id));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
// TODO: get real error from UserPool::authorize
|
||||
oss.str(authorization_error(method_name, "MANAGE", object_type, uid, object_id));
|
||||
goto error_common;
|
||||
|
||||
error_add_object_group:
|
||||
|
||||
error_common:
|
||||
if( object != 0 )
|
||||
{
|
||||
object->unlock();
|
||||
}
|
||||
|
||||
if( group != 0 )
|
||||
{
|
||||
group->unlock();
|
||||
}
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -44,7 +44,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
|
||||
if ( noid < 0 )
|
||||
{
|
||||
failure_response(XML_RPC_API,"Wrong User ID"); //TODO
|
||||
failure_response(XML_RPC_API,request_error("Wrong User ID",""));
|
||||
return;
|
||||
}
|
||||
else if ( upool->get(noid,false) == 0 )
|
||||
@ -56,7 +56,7 @@ void RequestManagerChown::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
|
||||
if ( ngid < 0 )
|
||||
{
|
||||
failure_response(XML_RPC_API,"Wrong Group ID");
|
||||
failure_response(XML_RPC_API,request_error("Wrong Group ID",""));
|
||||
return;
|
||||
}
|
||||
else if ( gpool->get(ngid,false) == 0 )
|
||||
|
@ -36,7 +36,7 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error("USER",oid));
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object),oid));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL,"Internal Error");
|
||||
failure_response(INTERNAL,request_error("Internal Error",""));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,203 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::VirtualMachineDeploy::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
int vid;
|
||||
int hid;
|
||||
int uid;
|
||||
int rc;
|
||||
|
||||
string hostname;
|
||||
string vmm_mad;
|
||||
string tm_mad;
|
||||
string vmdir;
|
||||
|
||||
const string method_name = "VirtualMachineDeploy";
|
||||
|
||||
VirtualMachine * vm;
|
||||
Host * host;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
DispatchManager * dm = nd.get_dm();
|
||||
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
ostringstream oss;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachineDeploy invoked");
|
||||
|
||||
//Parse Arguments
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
vid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
hid = xmlrpc_c::value_int(paramList.getInt(2));
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Authenticate the user
|
||||
// -------------------------------------------------------------------------
|
||||
rc = VirtualMachineDeploy::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Get user data
|
||||
// -------------------------------------------------------------------------
|
||||
vm = VirtualMachineDeploy::vmpool->get(vid,true);
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
goto error_vm_get;
|
||||
}
|
||||
|
||||
uid = vm->get_uid();
|
||||
|
||||
vm->unlock();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Authorize the operation
|
||||
// -------------------------------------------------------------------------
|
||||
if ( rc != 0 ) // rc == 0 means oneadmin
|
||||
{
|
||||
AuthRequest ar(rc);
|
||||
|
||||
ar.add_auth(AuthRequest::VM,vid,AuthRequest::MANAGE,uid,false);
|
||||
ar.add_auth(AuthRequest::HOST,hid,AuthRequest::USE,0,false);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Get host info to deploy the VM
|
||||
// -------------------------------------------------------------------------
|
||||
host = VirtualMachineDeploy::hpool->get(hid,true);
|
||||
|
||||
if ( host == 0 )
|
||||
{
|
||||
goto error_host_get;
|
||||
}
|
||||
|
||||
hostname = host->get_name();
|
||||
vmm_mad = host->get_vmm_mad();
|
||||
tm_mad = host->get_tm_mad();
|
||||
|
||||
nd.get_configuration_attribute("VM_DIR",vmdir);
|
||||
|
||||
host->unlock();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Deploy the VM
|
||||
// -------------------------------------------------------------------------
|
||||
vm = VirtualMachineDeploy::vmpool->get(vid,true);
|
||||
|
||||
if ( vm == 0 )
|
||||
{
|
||||
goto error_vm_get;
|
||||
}
|
||||
|
||||
if ( vm->get_state() != VirtualMachine::PENDING )
|
||||
{
|
||||
goto error_state;
|
||||
}
|
||||
|
||||
vm->add_history(hid,hostname,vmdir,vmm_mad,tm_mad);
|
||||
|
||||
rc = VirtualMachineDeploy::vmpool->update_history(vm);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
goto error_history;
|
||||
}
|
||||
|
||||
vmpool->update(vm); //Insert last_seq in the DB
|
||||
|
||||
dm->deploy(vm);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Results
|
||||
// -------------------------------------------------------------------------
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true));
|
||||
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult;
|
||||
|
||||
return;
|
||||
|
||||
error_host_get:
|
||||
oss.str(get_error(method_name, "HOST", hid));
|
||||
goto error_common;
|
||||
|
||||
error_vm_get:
|
||||
oss.str(get_error(method_name, "VM", vid));
|
||||
goto error_common;
|
||||
|
||||
error_state:
|
||||
oss << action_error(method_name, "MANAGE", "VM", vid, -1)
|
||||
<< ". Reason: VM in wrong state.";
|
||||
goto error_common_lock;
|
||||
|
||||
error_authenticate:
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "MANAGE", "VM", rc, vid));
|
||||
goto error_common;
|
||||
|
||||
error_history:
|
||||
oss.str(action_error(method_name, "INSERT HISTORY", "VM", vid, rc));
|
||||
goto error_common_lock;
|
||||
|
||||
error_common_lock:
|
||||
vm->unlock();
|
||||
|
||||
error_common:
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false));
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -50,7 +50,7 @@ void ImageEnable::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
err_msg = "Could not disable image";
|
||||
}
|
||||
|
||||
failure_response(INTERNAL, err_msg);//TODO
|
||||
failure_response(INTERNAL, request_error(err_msg,""));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -83,7 +83,6 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
}
|
||||
|
||||
result = image->persistent(persistent_flag);
|
||||
image->unlock();
|
||||
|
||||
if ( !result )
|
||||
{
|
||||
@ -95,9 +94,16 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
{
|
||||
err_msg = "Could not make image non-persistent";
|
||||
}
|
||||
failure_response(INTERNAL, err_msg); //TODO
|
||||
|
||||
failure_response(INTERNAL,request_error(err_msg,""));
|
||||
|
||||
image->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(image);
|
||||
|
||||
image->unlock();
|
||||
|
||||
success_response(id);
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error("USER",oid));
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object),oid));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ void RequestManagerPoolInfo::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL,"Internal Error");
|
||||
failure_response(INTERNAL,request_error("Internal Error",""));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ void RequestManagerPoolInfoFilter::request_execute(xmlrpc_c::paramList const& pa
|
||||
|
||||
if ( filter_flag < MINE )
|
||||
{
|
||||
failure_response(XML_RPC_API, "Incorrect filter_flag, must be >= -3.");
|
||||
failure_response(XML_RPC_API, request_error("Incorrect filter_flag.",""));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ void RequestManagerPoolInfoFilter::request_execute(xmlrpc_c::paramList const& pa
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL,"Internal Error");
|
||||
failure_response(INTERNAL,request_error("Internal Error",""));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ void RequestManagerPublish::request_execute(xmlrpc_c::paramList const& paramList
|
||||
|
||||
if ( object == 0 )
|
||||
{
|
||||
failure_response(NO_EXISTS, get_error("USER",oid));
|
||||
failure_response(NO_EXISTS, get_error(object_name(auth_object),oid));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -44,9 +44,10 @@ void RequestManagerPublish::request_execute(xmlrpc_c::paramList const& paramList
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(ACTION,action_error("PUBLISH","USER",oid,0));
|
||||
object->unlock();
|
||||
failure_response(INTERNAL,
|
||||
request_error("Can not publish/unpublish resource",""));
|
||||
|
||||
object->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ void RequestManagerUpdateTemplate::request_execute(xmlrpc_c::paramList const& pa
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL, error_str); //TODO
|
||||
failure_response(INTERNAL, request_error("Can not update template",error_str));
|
||||
object->unlock();
|
||||
|
||||
return;
|
||||
|
@ -25,7 +25,7 @@ void RequestManagerUser::
|
||||
User * user;
|
||||
string error_str;
|
||||
|
||||
if ( basic_authorization(id) == false ) //TODO REALLY NEED TO ADD GROUP HERE?
|
||||
if ( basic_authorization(id) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -40,7 +40,7 @@ void RequestManagerUser::
|
||||
|
||||
if ( user_action(user,paramList,error_str) < 0 )
|
||||
{
|
||||
failure_response(INTERNAL, error_str); //TODO
|
||||
failure_response(INTERNAL, request_error(error_str,""));
|
||||
}
|
||||
|
||||
success_response(id);
|
||||
@ -58,7 +58,7 @@ int UserChangePassword::user_action(User * user,
|
||||
|
||||
user->set_password(new_pass);
|
||||
|
||||
(static_cast<UserPool *>(pool))->update(user);
|
||||
pool->update(user);
|
||||
|
||||
user->unlock();
|
||||
|
||||
@ -87,7 +87,7 @@ int UserAddGroup::user_action(User * user,
|
||||
return rc;
|
||||
}
|
||||
|
||||
(static_cast<UserPool *>(pool))->update(user);
|
||||
pool->update(user);
|
||||
|
||||
user->unlock();
|
||||
|
||||
@ -102,9 +102,11 @@ int UserAddGroup::user_action(User * user,
|
||||
if ( user != 0 )
|
||||
{
|
||||
user->del_group(group_id);
|
||||
}
|
||||
|
||||
(static_cast<UserPool *>(pool))->update(user);
|
||||
pool->update(user);
|
||||
|
||||
user->unlock();
|
||||
}
|
||||
|
||||
error_str = "Group does not exists";
|
||||
return -1;
|
||||
@ -141,7 +143,7 @@ int UserDelGroup::user_action(User * user,
|
||||
return rc;
|
||||
}
|
||||
|
||||
(static_cast<UserPool *>(pool))->update(user);
|
||||
pool->update(user);
|
||||
|
||||
user->unlock();
|
||||
|
||||
|
@ -1,120 +0,0 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManager.h"
|
||||
#include "NebulaLog.h"
|
||||
|
||||
#include "AuthManager.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RequestManager::UserChangePassword::execute(
|
||||
xmlrpc_c::paramList const& paramList,
|
||||
xmlrpc_c::value * const retval)
|
||||
{
|
||||
string session;
|
||||
|
||||
int uid;
|
||||
int rc;
|
||||
string new_pass;
|
||||
User * user;
|
||||
ostringstream oss;
|
||||
|
||||
const string method_name = "UserChangePassword";
|
||||
|
||||
/* -- RPC specific vars -- */
|
||||
vector<xmlrpc_c::value> arrayData;
|
||||
xmlrpc_c::value_array * arrayresult;
|
||||
|
||||
NebulaLog::log("ReM",Log::DEBUG,"UserChangePassword method invoked");
|
||||
|
||||
// Get the parameters & user
|
||||
session = xmlrpc_c::value_string(paramList.getString(0));
|
||||
uid = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
new_pass = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
//Authenticate the user
|
||||
rc = UserChangePassword::upool->authenticate(session);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
goto error_authenticate;
|
||||
}
|
||||
|
||||
//Authorize the operation
|
||||
if ( rc != 0 ) // rc == 0 means oneadmin
|
||||
{
|
||||
AuthRequest ar(rc);
|
||||
|
||||
ar.add_auth(AuthRequest::USER,uid,AuthRequest::MANAGE,0,false);
|
||||
|
||||
if (UserPool::authorize(ar) == -1)
|
||||
{
|
||||
goto error_authorize;
|
||||
}
|
||||
}
|
||||
|
||||
user = UserChangePassword::upool->get(uid,true);
|
||||
|
||||
if ( user == 0 )
|
||||
{
|
||||
goto error_user_get;
|
||||
}
|
||||
|
||||
user->set_password(new_pass);
|
||||
|
||||
UserChangePassword::upool->update(user);
|
||||
|
||||
user->unlock();
|
||||
|
||||
//Result
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(true));
|
||||
arrayresult = new xmlrpc_c::value_array(arrayData);
|
||||
|
||||
*retval = *arrayresult;
|
||||
|
||||
delete arrayresult;
|
||||
|
||||
return;
|
||||
|
||||
error_authenticate:
|
||||
oss.str(authenticate_error(method_name));
|
||||
goto error_common;
|
||||
|
||||
error_authorize:
|
||||
oss.str(authorization_error(method_name, "MANAGE", "USER", rc, uid));
|
||||
goto error_common;
|
||||
|
||||
error_user_get:
|
||||
oss.str(get_error(method_name, "USER", uid));
|
||||
goto error_common;
|
||||
|
||||
error_common:
|
||||
NebulaLog::log("ReM",Log::ERROR,oss);
|
||||
|
||||
arrayData.push_back(xmlrpc_c::value_boolean(false));
|
||||
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
|
||||
|
||||
xmlrpc_c::value_array arrayresult_error(arrayData);
|
||||
|
||||
*retval = arrayresult_error;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
@ -72,7 +72,7 @@ void VMTemplateInstantiate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
failure_response(INTERNAL, error_str); //TODO
|
||||
failure_response(INTERNAL, allocate_error(AuthRequest::VM,error_str));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,8 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm,
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
failure_response(INTERNAL, "Can not update virtual machine history");
|
||||
failure_response(INTERNAL,
|
||||
request_error("Can not update virtual machine history",""));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -219,13 +220,16 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
failure_response(NO_EXISTS,get_error(object_name(auth_object),id));
|
||||
break;
|
||||
case -2:
|
||||
failure_response(ACTION, "Worng state to perform action");
|
||||
failure_response(ACTION,
|
||||
request_error("Worng state to perform action",""));
|
||||
break;
|
||||
case -3:
|
||||
failure_response(ACTION, "Virtual machine action not supported");
|
||||
failure_response(ACTION,
|
||||
request_error("Virtual machine action not supported",""));
|
||||
break;
|
||||
default:
|
||||
failure_response(INTERNAL, "Internal error");
|
||||
failure_response(INTERNAL,
|
||||
request_error("Internal error","Action result not defined"));
|
||||
}
|
||||
|
||||
return;
|
||||
@ -265,7 +269,9 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList)
|
||||
|
||||
if ( vm->get_state() != VirtualMachine::PENDING )
|
||||
{
|
||||
failure_response(ACTION, "Worng state to perform action");
|
||||
failure_response(ACTION,
|
||||
request_error("Worng state to perform action",""));
|
||||
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
@ -320,7 +326,9 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
|
||||
(vm->get_lcm_state() != VirtualMachine::RUNNING) ||
|
||||
(vm->hasPreviousHistory() && vm->get_previous_reason() == History::NONE))
|
||||
{
|
||||
failure_response(ACTION, "Worng state to perform action");
|
||||
failure_response(ACTION,
|
||||
request_error("Worng state to perform action",""));
|
||||
|
||||
vm->unlock();
|
||||
return;
|
||||
}
|
||||
@ -390,7 +398,8 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
failure_response(INTERNAL,"Allocate Image"); //allocate_error(error_str)); //TODO
|
||||
failure_response(INTERNAL,
|
||||
allocate_error(AuthRequest::IMAGE,error_str));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -403,6 +412,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
if ( (img = ipool->get(iid,true)) != 0 )
|
||||
{
|
||||
ipool->drop(img);
|
||||
img->unlock();
|
||||
}
|
||||
|
||||
return;
|
||||
@ -410,6 +420,13 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
|
||||
rc = vm->save_disk(disk_id, iid, error_str);
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
pool->update(vm);
|
||||
};
|
||||
|
||||
vm->unlock();
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
Image * img;
|
||||
@ -417,16 +434,14 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
|
||||
if ( (img = ipool->get(iid,true)) != 0 )
|
||||
{
|
||||
ipool->drop(img);
|
||||
img->unlock();
|
||||
}
|
||||
|
||||
failure_response(INTERNAL,error_str); //TODO
|
||||
|
||||
failure_response(INTERNAL,
|
||||
request_error("Can not save_as disk",error_str));
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(vm);
|
||||
|
||||
vm->unlock();
|
||||
|
||||
success_response(id);
|
||||
}
|
||||
|
@ -19,24 +19,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string RequestManagerVirtualNetwork::leases_error (const string& error)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "[" << method_name << "]" << " Error modifiying network leases.";
|
||||
|
||||
if (!error.empty())
|
||||
{
|
||||
oss << " " << error;
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@ -44,15 +26,15 @@ string RequestManagerVirtualNetwork::leases_error (char *error)
|
||||
{
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Parse error";
|
||||
oss << "Parse error.";
|
||||
|
||||
if ( error != 0 )
|
||||
{
|
||||
oss << ": " << error;
|
||||
oss << " " << error;
|
||||
free(error);
|
||||
}
|
||||
|
||||
return leases_error(oss.str());
|
||||
return request_error("Error modifiying network leases.",oss.str());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@ -96,9 +78,15 @@ void RequestManagerVirtualNetwork::
|
||||
|
||||
if ( rc < 0 )
|
||||
{
|
||||
failure_response(INTERNAL, leases_error(error_str));
|
||||
failure_response(INTERNAL,
|
||||
request_error("Error modifiying network leases.",error_str));
|
||||
|
||||
vn->unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(vn);
|
||||
|
||||
vn->unlock();
|
||||
|
||||
success_response(id);
|
||||
|
Loading…
Reference in New Issue
Block a user