feature #662: Delete uses a common Request. Moved more functionality to base classes

This commit is contained in:
Ruben S. Montero committed 2011-05-26 00:59:50 +02:00
1 parent c15a9e9a12
commit fc15b443b6
12 files changed
+403 -139

No files matched your search

+42 -4
View File
@@ -25,9 +25,6 @@ void Request::execute(
xmlrpc_c::paramList const& _paramList,
xmlrpc_c::value * const _retval)
{
int uid;
int gid;
retval = _retval;
session = xmlrpc_c::value_string (_paramList.getString(0));
@@ -42,13 +39,54 @@ void Request::execute(
}
else
{
request_execute(uid, gid, _paramList);
request_execute(_paramList);
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool Request::basic_authorization(int oid)
{
PoolObjectSQL * object;
bool pub;
int ouid;
object = pool->get(oid,true);
if ( object == 0 )
{
failure_response(NO_EXISTS, get_error("USER",oid)); //TODO
return false;
}
ouid = object->get_uid();
pub = isPublic(object);
object->unlock();
if ( uid != 0 ) // uid == 0 means oneadmin
{
AuthRequest ar(uid);
ar.add_auth(auth_object, oid, auth_op, ouid, pub);
if (UserPool::authorize(ar) == -1)
{
failure_response(AUTHORIZATION, //TODO
authorization_error("INFO","USER",oid,-1));
return false;
}
}
return true;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Request::failure_response(ErrorCode ec, const string& str_val)
{
vector<xmlrpc_c::value> arrayData;
+17 -21
View File
@@ -21,6 +21,7 @@
#include "RequestManagerPoolInfoFilter.h"
#include "RequestManagerPoolInfo.h"
#include "RequestManagerInfo.h"
#include "RequestManagerDelete.h"
#include <sys/signal.h>
#include <sys/socket.h>
@@ -217,6 +218,15 @@ void RequestManager::do_action(
void RequestManager::register_xml_methods()
{
// Delete Methods
xmlrpc_c::methodPtr host_delete(new HostDelete());
xmlrpc_c::methodPtr template_delete(new TemplateDelete());
xmlrpc_c::methodPtr cluster_delete(new ClusterDelete());
xmlrpc_c::methodPtr group_delete(new GroupDelete());
xmlrpc_c::methodPtr vn_delete(new VirtualNetworkDelete());
xmlrpc_c::methodPtr user_delete(new UserDelete());
xmlrpc_c::methodPtr image_delete(new ImageDelete());
// Info Methods
xmlrpc_c::methodPtr vm_info(new VirtualMachineInfo());
xmlrpc_c::methodPtr host_info(new HostInfo());
@@ -263,8 +273,6 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr template_allocate(new
RequestManager::TemplateAllocate(tpool,upool));
xmlrpc_c::methodPtr template_delete(new
RequestManager::TemplateDelete(tpool, upool));
xmlrpc_c::methodPtr template_update(new
@@ -283,8 +291,6 @@ void RequestManager::register_xml_methods()
RequestManager::HostAllocate(hpool,upool));
xmlrpc_c::methodPtr host_delete(new
RequestManager::HostDelete(hpool,upool));
xmlrpc_c::methodPtr host_enable(new
RequestManager::HostEnable(hpool,upool));
@@ -293,8 +299,6 @@ void RequestManager::register_xml_methods()
RequestManager::ClusterAllocate(upool,cpool));
xmlrpc_c::methodPtr cluster_delete(new
RequestManager::ClusterDelete(upool,cpool));
xmlrpc_c::methodPtr cluster_add(new
RequestManager::ClusterAdd(hpool,upool,cpool));
@@ -306,8 +310,6 @@ void RequestManager::register_xml_methods()
RequestManager::GroupAllocate(upool,gpool));
xmlrpc_c::methodPtr group_delete(new
RequestManager::GroupDelete(upool,gpool));
xmlrpc_c::methodPtr vn_allocate(new
RequestManager::VirtualNetworkAllocate(vnpool,upool));
@@ -316,8 +318,6 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr vn_publish(new
RequestManager::VirtualNetworkPublish(vnpool, upool));
xmlrpc_c::methodPtr vn_delete(new
RequestManager::VirtualNetworkDelete(vnpool, upool));
xmlrpc_c::methodPtr vn_addleases(new
RequestManager::VirtualNetworkAddLeases(vnpool, upool));
@@ -331,8 +331,6 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr user_allocate(new
RequestManager::UserAllocate(upool));
xmlrpc_c::methodPtr user_delete(new
RequestManager::UserDelete(upool));
xmlrpc_c::methodPtr user_change_password(new
@@ -344,8 +342,6 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr image_allocate(new
RequestManager::ImageAllocate(ipool, upool));
xmlrpc_c::methodPtr image_delete(new
RequestManager::ImageDelete(ipool, upool));
xmlrpc_c::methodPtr image_update(new
@@ -382,12 +378,12 @@ void RequestManager::register_xml_methods()
/* VM Template related methods*/
/*
RequestManagerRegistry.addMethod("one.template.allocate",template_allocate);
RequestManagerRegistry.addMethod("one.template.delete", template_delete);
RequestManagerRegistry.addMethod("one.template.update", template_update);
RequestManagerRegistry.addMethod("one.template.rmattr", template_rm_attribute);
RequestManagerRegistry.addMethod("one.template.publish", template_publish);
RequestManagerRegistry.addMethod("one.template.chown", template_chown);
*/
RequestManagerRegistry.addMethod("one.template.delete", template_delete);
RequestManagerRegistry.addMethod("one.template.info", template_info);
RequestManagerRegistry.addMethod("one.templatepool.info",template_pool_info);
@@ -395,9 +391,9 @@ void RequestManager::register_xml_methods()
/* Host related methods*/
/*
RequestManagerRegistry.addMethod("one.host.allocate", host_allocate);
RequestManagerRegistry.addMethod("one.host.delete", host_delete);
RequestManagerRegistry.addMethod("one.host.enable", host_enable);
*/
RequestManagerRegistry.addMethod("one.host.delete", host_delete);
RequestManagerRegistry.addMethod("one.host.info", host_info);
RequestManagerRegistry.addMethod("one.hostpool.info", hostpool_info);
@@ -405,10 +401,10 @@ void RequestManager::register_xml_methods()
/* Cluster related methods */
/*
RequestManagerRegistry.addMethod("one.cluster.allocate", cluster_allocate);
RequestManagerRegistry.addMethod("one.cluster.delete", cluster_delete);
RequestManagerRegistry.addMethod("one.cluster.add", cluster_add);
RequestManagerRegistry.addMethod("one.cluster.remove", cluster_remove);
*/
RequestManagerRegistry.addMethod("one.cluster.delete", cluster_delete);
RequestManagerRegistry.addMethod("one.cluster.info", cluster_info);
RequestManagerRegistry.addMethod("one.clusterpool.info", clusterpool_info);
@@ -416,8 +412,8 @@ void RequestManager::register_xml_methods()
/* Group related methods */
/*
RequestManagerRegistry.addMethod("one.group.allocate", group_allocate);
RequestManagerRegistry.addMethod("one.group.delete", group_delete);
*/
RequestManagerRegistry.addMethod("one.group.delete", group_delete);
RequestManagerRegistry.addMethod("one.group.info", group_info);
RequestManagerRegistry.addMethod("one.grouppool.info", grouppool_info);
@@ -426,11 +422,11 @@ void RequestManager::register_xml_methods()
/*
RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate);
RequestManagerRegistry.addMethod("one.vn.publish", vn_publish);
RequestManagerRegistry.addMethod("one.vn.delete", vn_delete);
RequestManagerRegistry.addMethod("one.vn.addleases", vn_addleases);
RequestManagerRegistry.addMethod("one.vn.rmleases", vn_rmleases);
RequestManagerRegistry.addMethod("one.vn.chown", vn_chown);
*/
RequestManagerRegistry.addMethod("one.vn.delete", vn_delete);
RequestManagerRegistry.addMethod("one.vn.info", vn_info);
RequestManagerRegistry.addMethod("one.vnpool.info", vnpool_info);
@@ -439,10 +435,10 @@ void RequestManager::register_xml_methods()
/* User related methods*/
/*
RequestManagerRegistry.addMethod("one.user.allocate", user_allocate);
RequestManagerRegistry.addMethod("one.user.delete", user_delete);
RequestManagerRegistry.addMethod("one.user.passwd", user_change_password);
RequestManagerRegistry.addMethod("one.user.chown", user_chown);
*/
RequestManagerRegistry.addMethod("one.user.delete", user_delete);
RequestManagerRegistry.addMethod("one.user.info", user_info);
RequestManagerRegistry.addMethod("one.userpool.info", userpool_info);
@@ -450,7 +446,6 @@ void RequestManager::register_xml_methods()
/* Image related methods*/
/*
RequestManagerRegistry.addMethod("one.image.allocate", image_allocate);
RequestManagerRegistry.addMethod("one.image.delete", image_delete);
RequestManagerRegistry.addMethod("one.image.update", image_update);
RequestManagerRegistry.addMethod("one.image.rmattr", image_rm_attribute);
RequestManagerRegistry.addMethod("one.image.publish", image_publish);
@@ -459,6 +454,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.image.chown", image_chown);
*/
RequestManagerRegistry.addMethod("one.image.delete", image_delete);
RequestManagerRegistry.addMethod("one.image.info", image_info);
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
+56
View File
@@ -0,0 +1,56 @@
/* -------------------------------------------------------------------------- */
/* 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 "RequestManagerDelete.h"
using namespace std;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void RequestManagerDelete::request_execute(xmlrpc_c::paramList const& paramList)
{
int oid = xmlrpc_c::value_int(paramList.getInt(1));
PoolObjectSQL * object;
if ( basic_authorization(oid) == false )
{
return;
}
object = pool->get(oid,true);
if ( object == 0 )
{
failure_response(NO_EXISTS, get_error("USER",oid));
return;
}
int rc = pool->drop(object);
object->unlock();
if ( rc != 0 )
{
failure_response(INTERNAL,"Internal Error");
return;
}
success_response(oid);
return;
}
+6 -44
View File
@@ -21,53 +21,24 @@ using namespace std;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void RequestManagerInfo::request_execute(
int uid,
int gid,
xmlrpc_c::paramList const& paramList)
void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList)
{
ostringstream oss;
int oid = xmlrpc_c::value_int(paramList.getInt(1));
int ouid;
bool pub;
int oid = xmlrpc_c::value_int(paramList.getInt(1));
PoolObjectSQL * object;
object = pool->get(oid,true);
if ( object == 0 )
{
goto error_get;
}
ouid = object->get_uid();
pub = isPublic(object);
object->unlock();
//Authorize the operation
if ( uid != 0 ) // uid == 0 means oneadmin
if ( basic_authorization(oid) == false )
{
AuthRequest ar(uid);
ar.add_auth(auth_object,
oid,
AuthRequest::INFO,
ouid,
pub);
if (UserPool::authorize(ar) == -1)
{
goto error_authorize;
}
return;
}
object = pool->get(oid,true);
if ( object == 0 )
{
goto error_get;
failure_response(NO_EXISTS, get_error("USER",oid));
return;
}
oss << *object;
@@ -77,14 +48,5 @@ void RequestManagerInfo::request_execute(
success_response(oss.str());
return;
error_get: //TBD Improve Error messages for DUMP
failure_response(INTERNAL,"Internal Error");
return;
//TODO Get the object name from the AuthRequest Class
error_authorize:
failure_response(NO_EXISTS, get_error("USER",oid));
return;
}
+1 -4
View File
@@ -21,10 +21,7 @@ using namespace std;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void RequestManagerPoolInfo::request_execute(
int uid,
int gid,
xmlrpc_c::paramList const& paramList)
void RequestManagerPoolInfo::request_execute(xmlrpc_c::paramList const& paramList)
{
ostringstream oss;
int rc;
+1 -4
View File
@@ -30,10 +30,7 @@ const int RequestManagerPoolInfoFilter::MINE_GROUP = -1;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void RequestManagerPoolInfoFilter::request_execute(
int uid,
int gid,
xmlrpc_c::paramList const& paramList)
void RequestManagerPoolInfoFilter::request_execute(xmlrpc_c::paramList const& paramList)
{
int filter_flag = xmlrpc_c::value_int(paramList.getInt(1));
+2
View File
@@ -27,6 +27,8 @@ source_files=[
'RequestManagerInfo.cc',
'RequestManagerPoolInfo.cc',
'RequestManagerPoolInfoFilter.cc',
'RequestManagerDelete.cc',
# 'RequestManagerAction.cc',
# 'RequestManagerAllocate.cc',
# 'RequestManagerDeploy.cc',