1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-26 09:57:23 +03:00

feature #662: Pool Info methods now uses the same implementation

This commit is contained in:
Ruben S. Montero 2011-05-24 17:31:27 +02:00
parent 061ea1b397
commit ac46cf5dee
10 changed files with 411 additions and 180 deletions

View File

@ -45,10 +45,13 @@ public:
* Error codes for the XML-RPC API
*/
enum ErrorCode {
SUCCESS = 0x0000,
AUTHENTICATION = 0x0100,
AUTHORIZATION = 0x0200,
GET = 0x0400,
ACTION = 0x0800
NO_EXISTS = 0x0400,
ACTION = 0x0800,
XML_RPC_API = 0x1000,
INTERNAL = 0x2000,
};
protected:

View File

@ -0,0 +1,127 @@
/* -------------------------------------------------------------------------- */
/* 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. */
/* -------------------------------------------------------------------------- */
#ifndef REQUEST_MANAGER_POOL_INFO_H_
#define REQUEST_MANAGER_POOL_INFO_H_
#include "Request.h"
#include "Nebula.h"
using namespace std;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerPoolInfo: public Request
{
protected:
RequestManagerPoolInfo(const string& method_name,
const string& help)
:Request(method_name,"A:s",help){};
~RequestManagerPoolInfo(){};
/* -------------------------------------------------------------------- */
void request_execute(int uid,
int gid,
xmlrpc_c::paramList const& _paramList);
/* -------------------------------------------------------------------- */
PoolSQL *pool;
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class HostPoolInfo : public RequestManagerPoolInfo
{
public:
HostPoolInfo():
RequestManagerPoolInfo("HostPoolInfo",
"Returns the host pool")
{
Nebula& nd = Nebula::instance();
pool = nd.get_hpool();
};
~HostPoolInfo(){};
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterPoolInfo : public RequestManagerPoolInfo
{
public:
ClusterPoolInfo():
RequestManagerPoolInfo("ClusterPoolInfo",
"Returns the cluster pool")
{
Nebula& nd = Nebula::instance();
pool = nd.get_cpool();
};
~ClusterPoolInfo(){};
private:
VMTemplatePool * tpool;
UserPool * upool;
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class GroupPoolInfo: public RequestManagerPoolInfo
{
public:
GroupPoolInfo():
RequestManagerPoolInfo("GroupPoolInfo",
"Returns the group pool")
{
Nebula& nd = Nebula::instance();
pool = nd.get_gpool();
};
~GroupPoolInfo(){};
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class UserPoolInfo: public RequestManagerPoolInfo
{
public:
UserPoolInfo():
RequestManagerPoolInfo("UserPoolInfo",
"Returns the user pool")
{
Nebula& nd = Nebula::instance();
pool = nd.get_upool();
};
~UserPoolInfo(){};
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#endif

View File

@ -0,0 +1,134 @@
/* -------------------------------------------------------------------------- */
/* 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. */
/* -------------------------------------------------------------------------- */
#ifndef REQUEST_MANAGER_POOL_INFO_FILTER_H_
#define REQUEST_MANAGER_POOL_INFO_FILTER_H_
#include "Request.h"
#include "Nebula.h"
//#include "AuthManager.h"
using namespace std;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerPoolInfoFilter: public Request
{
protected:
RequestManagerPoolInfoFilter(const string& method_name,
const string& help)
:Request(method_name,"A:si",help){};
~RequestManagerPoolInfoFilter(){};
/* -------------------------------------------------------------------- */
static const int ALL; /**< Secify all objects in the pool (-2) */
static const int MINE; /**< Secify user's objects in the pool (-3)*/
static const int MINE_GROUP; /**< Secify users + group objects (-1) */
/* -------------------------------------------------------------------- */
void request_execute(int uid,
int gid,
xmlrpc_c::paramList const& _paramList);
/* -------------------------------------------------------------------- */
PoolSQL *pool;
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualMachinePoolInfo : public RequestManagerPoolInfoFilter
{
public:
VirtualMachinePoolInfo():
RequestManagerPoolInfoFilter("VirtualMachinePoolInfo",
"Returns the virtual machine instances pool")
{
Nebula& nd = Nebula::instance();
pool = nd.get_vmpool();
};
~VirtualMachinePoolInfo(){};
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class TemplatePoolInfo : public RequestManagerPoolInfoFilter
{
public:
TemplatePoolInfo():
RequestManagerPoolInfoFilter("TemplatePoolInfo",
"Returns the virtual machine template pool")
{
Nebula& nd = Nebula::instance();
pool = nd.get_tpool();
};
~TemplatePoolInfo(){};
private:
VMTemplatePool * tpool;
UserPool * upool;
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualNetworkPoolInfo: public RequestManagerPoolInfoFilter
{
public:
VirtualNetworkPoolInfo():
RequestManagerPoolInfoFilter("VirtualNetworkPoolInfo",
"Returns the virtual network pool")
{
Nebula& nd = Nebula::instance();
pool = nd.get_vnpool();
};
~VirtualNetworkPoolInfo(){};
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ImagePoolInfo: public RequestManagerPoolInfoFilter
{
public:
ImagePoolInfo():
RequestManagerPoolInfoFilter("ImagePoolInfo",
"Returns the image pool")
{
Nebula& nd = Nebula::instance();
pool = nd.get_ipool();
};
~ImagePoolInfo(){};
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#endif

View File

@ -105,14 +105,6 @@ public:
User::bootstrap(_db);
};
//TODO REMOVE THIS, HERE TO FIX COMPILATION
/**
* Returns whether there is a user with given username/password or not
* @param session, colon separated username and password string
* @return -1 if authn failed, uid of the user in other case
*/
// int authenticate(string& session){return 0;}
/**
* Returns whether there is a user with given username/password or not
* @param session, colon separated username and password string

View File

@ -73,6 +73,8 @@ void Request::success_response(int id)
arrayData.push_back(xmlrpc_c::value_boolean(true));
arrayData.push_back(xmlrpc_c::value_int(id));
arrayData.push_back(xmlrpc_c::value_int(SUCCESS));
xmlrpc_c::value_array arrayresult(arrayData);
@ -87,6 +89,7 @@ void Request::success_response(const string& val)
arrayData.push_back(xmlrpc_c::value_boolean(true));
arrayData.push_back(xmlrpc_c::value_string(val));
arrayData.push_back(xmlrpc_c::value_int(SUCCESS));
xmlrpc_c::value_array arrayresult(arrayData);

View File

@ -18,6 +18,9 @@
#include "NebulaLog.h"
#include <cerrno>
#include "RequestManagerPoolInfoFilter.h"
#include "RequestManagerPoolInfo.h"
#include <sys/signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
@ -213,6 +216,20 @@ void RequestManager::do_action(
void RequestManager::register_xml_methods()
{
// PoolInfo Methods
xmlrpc_c::methodPtr hostpool_info(new HostPoolInfo());
xmlrpc_c::methodPtr clusterpool_info(new ClusterPoolInfo());
xmlrpc_c::methodPtr grouppool_info(new GroupPoolInfo());
xmlrpc_c::methodPtr userpool_info(new UserPoolInfo());
// PoolInfo Methods with Filtering
xmlrpc_c::methodPtr vm_pool_info(new VirtualMachinePoolInfo());
xmlrpc_c::methodPtr template_pool_info(new TemplatePoolInfo());
xmlrpc_c::methodPtr vnpool_info(new VirtualNetworkPoolInfo());
xmlrpc_c::methodPtr imagepool_info(new ImagePoolInfo());
/* xmlrpc_c::methodPtr vm_allocate(new
RequestManager::VirtualMachineAllocate(vmpool,vnpool,ipool,tpool,upool));
@ -234,9 +251,6 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr vm_chown(new
RequestManager::GenericChown(this,VM));
xmlrpc_c::methodPtr vm_pool_info(new
RequestManager::VirtualMachinePoolInfo(vmpool,upool));
xmlrpc_c::methodPtr template_allocate(new
RequestManager::TemplateAllocate(tpool,upool));
@ -258,18 +272,12 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr template_chown(new
RequestManager::GenericChown(this,TEMPLATE));
xmlrpc_c::methodPtr template_pool_info(new
RequestManager::TemplatePoolInfo(tpool,upool));
xmlrpc_c::methodPtr host_allocate(new
RequestManager::HostAllocate(hpool,upool));
xmlrpc_c::methodPtr host_info(new
RequestManager::HostInfo(hpool, upool));
xmlrpc_c::methodPtr hostpool_info(new
RequestManager::HostPoolInfo(hpool,upool));
xmlrpc_c::methodPtr host_delete(new
RequestManager::HostDelete(hpool,upool));
@ -291,9 +299,6 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr cluster_remove(new
RequestManager::ClusterRemove(hpool,upool,cpool));
xmlrpc_c::methodPtr clusterpool_info(new
RequestManager::ClusterPoolInfo(upool,cpool));
xmlrpc_c::methodPtr group_allocate(new
RequestManager::GroupAllocate(upool,gpool));
@ -303,18 +308,12 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr group_delete(new
RequestManager::GroupDelete(upool,gpool));
xmlrpc_c::methodPtr grouppool_info(new
RequestManager::GroupPoolInfo(upool,gpool));
xmlrpc_c::methodPtr vn_allocate(new
RequestManager::VirtualNetworkAllocate(vnpool,upool));
xmlrpc_c::methodPtr vn_info(new
RequestManager::VirtualNetworkInfo(vnpool,upool));
xmlrpc_c::methodPtr vnpool_info(new
RequestManager::VirtualNetworkPoolInfo(vnpool,upool));
xmlrpc_c::methodPtr vn_publish(new
RequestManager::VirtualNetworkPublish(vnpool, upool));
@ -345,9 +344,6 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr user_chown(new
RequestManager::GenericChown(this,USER));
xmlrpc_c::methodPtr userpool_info(new
RequestManager::UserPoolInfo(upool));
xmlrpc_c::methodPtr image_allocate(new
RequestManager::ImageAllocate(ipool, upool));
@ -374,9 +370,6 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr image_chown(new
RequestManager::GenericChown(this,IMAGE));
xmlrpc_c::methodPtr imagepool_info(new
RequestManager::ImagePoolInfo(ipool, upool));
*/
/* VM related methods */
/*
@ -387,9 +380,9 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.vm.info", vm_info);
RequestManagerRegistry.addMethod("one.vm.savedisk", vm_savedisk);
RequestManagerRegistry.addMethod("one.vm.chown", vm_chown);
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
*/
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info);
/* VM Template related methods*/
/*
RequestManagerRegistry.addMethod("one.template.allocate",template_allocate);
@ -399,18 +392,18 @@ void RequestManager::register_xml_methods()
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.templatepool.info",template_pool_info);
*/
RequestManagerRegistry.addMethod("one.templatepool.info",template_pool_info);
/* Host related methods*/
/*
RequestManagerRegistry.addMethod("one.host.allocate", host_allocate);
RequestManagerRegistry.addMethod("one.host.info", host_info);
RequestManagerRegistry.addMethod("one.host.delete", host_delete);
RequestManagerRegistry.addMethod("one.host.enable", host_enable);
RequestManagerRegistry.addMethod("one.hostpool.info", hostpool_info);
*/
RequestManagerRegistry.addMethod("one.hostpool.info", hostpool_info);
/* Cluster related methods */
/*
RequestManagerRegistry.addMethod("one.cluster.allocate", cluster_allocate);
@ -418,17 +411,17 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.cluster.delete", cluster_delete);
RequestManagerRegistry.addMethod("one.cluster.add", cluster_add);
RequestManagerRegistry.addMethod("one.cluster.remove", cluster_remove);
RequestManagerRegistry.addMethod("one.clusterpool.info", clusterpool_info);
*/
RequestManagerRegistry.addMethod("one.clusterpool.info", clusterpool_info);
/* Group related methods */
/*
RequestManagerRegistry.addMethod("one.group.allocate", group_allocate);
RequestManagerRegistry.addMethod("one.group.info", group_info);
RequestManagerRegistry.addMethod("one.group.delete", group_delete);
RequestManagerRegistry.addMethod("one.grouppool.info", grouppool_info);
*/
RequestManagerRegistry.addMethod("one.grouppool.info", grouppool_info);
/* Network related methods*/
/*
RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate);
@ -438,9 +431,9 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.vn.addleases", vn_addleases);
RequestManagerRegistry.addMethod("one.vn.rmleases", vn_rmleases);
RequestManagerRegistry.addMethod("one.vn.chown", vn_chown);
RequestManagerRegistry.addMethod("one.vnpool.info", vnpool_info);
*/
RequestManagerRegistry.addMethod("one.vnpool.info", vnpool_info);
/* User related methods*/
/*
@ -449,9 +442,9 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.user.info", user_info);
RequestManagerRegistry.addMethod("one.user.passwd", user_change_password);
RequestManagerRegistry.addMethod("one.user.chown", user_chown);
RequestManagerRegistry.addMethod("one.userpool.info", userpool_info);
*/
RequestManagerRegistry.addMethod("one.userpool.info", userpool_info);
/* Image related methods*/
/*
RequestManagerRegistry.addMethod("one.image.allocate", image_allocate);
@ -464,8 +457,8 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.image.enable", image_enable);
RequestManagerRegistry.addMethod("one.image.chown", image_chown);
*/
RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info);
*/
};
/* -------------------------------------------------------------------------- */

View File

@ -14,148 +14,36 @@
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
#include "RequestManager.h"
#include "NebulaLog.h"
#include "RequestManagerPoolInfo.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
using namespace std;
void RequestManager::VirtualMachinePoolInfo::execute(
xmlrpc_c::paramList const& paramList,
xmlrpc_c::value * const retval)
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void RequestManagerPoolInfo::request_execute(
int uid,
int gid,
xmlrpc_c::paramList const& paramList)
{
string session;
string username;
string password;
int filter_flag;
int rc;
int state;
int gid;
User * user;
ostringstream oss;
ostringstream where_string;
int rc;
/* -- RPC specific vars -- */
vector<xmlrpc_c::value> arrayData;
xmlrpc_c::value_array * arrayresult;
const string method_name = "VirtualMachinePoolInfo";
NebulaLog::log("ReM",Log::DEBUG,"VirtualMachinePoolInfo method invoked");
// For backwards compatibility, 2 or 3 arguments can be present.
switch (paramList.size())
{
case 2:
state = -1;
break;
case 3:
state = xmlrpc_c::value_int (paramList.getInt(2));
break;
default:
paramList.verifyEnd(3);
return;
}
// Get the parameters
session = xmlrpc_c::value_string(paramList.getString(0));
filter_flag = xmlrpc_c::value_int (paramList.getInt(1));
// Check if it is a valid user
rc = VirtualMachinePoolInfo::upool->authenticate(session);
if ( rc == -1 )
{
goto error_authenticate;
}
/** Filter flag meaning table
* -3 :: User's VMs
* -2 :: All VMs
* -1 :: User's VMs and all ones that belong to his groups
* >= 0 :: UID User's Images
**/
if ( filter_flag < -3 )
{
goto error_filter_flag;
}
switch(filter_flag)
{
case -3:
where_string << "UID=" << rc;
break;
case -2:
break;
case -1:
// Get the User Group
user = VirtualMachinePoolInfo::upool->get(rc,true);
if ( user == 0 )
{
goto error_user_get;
}
gid = user->get_gid();
user->unlock();
where_string << "UID=" << rc << " OR GID=" << gid;
break;
default:
where_string << "UID=" << filter_flag;
}
rc = VirtualMachinePoolInfo::vmpool->dump(oss, state, where_string.str());
// Call the template pool dump
rc = pool->dump(oss,"");
if ( rc != 0 )
{
goto error_dump;
}
// All nice, return the vm info to the client
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS
arrayData.push_back(xmlrpc_c::value_string(oss.str()));
arrayresult = new xmlrpc_c::value_array(arrayData);
// Copy arrayresult into retval mem space
*retval = *arrayresult;
// and get rid of the original
delete arrayresult;
success_response(oss.str());
return;
error_authenticate:
oss.str(authenticate_error(method_name));
goto error_common;
error_filter_flag:
oss << "Incorrect filter_flag, must be >= -3.";
goto error_common;
error_user_get:
oss.str(get_error(method_name, "USER", rc));
goto error_common;
error_dump:
oss.str(get_error(method_name, "VM", -1));
goto error_common;
error_common:
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;
error_dump: //TBD Improve Error messages for DUMP
oss.str();
failure_response(INTERNAL,"Internal Error");
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -0,0 +1,90 @@
/* -------------------------------------------------------------------------- */
/* 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 "RequestManagerPoolInfoFilter.h"
using namespace std;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
const int RequestManagerPoolInfoFilter::ALL = -2;
const int RequestManagerPoolInfoFilter::MINE = -3;
const int RequestManagerPoolInfoFilter::MINE_GROUP = -1;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void RequestManagerPoolInfoFilter::request_execute(
int uid,
int gid,
xmlrpc_c::paramList const& paramList)
{
int filter_flag = xmlrpc_c::value_int(paramList.getInt(1));
ostringstream oss, where_string;
int rc;
switch(filter_flag)
{
case MINE:
where_string << "UID=" << uid;
break;
case ALL:
break;
case MINE_GROUP:
where_string << "UID=" << uid << " OR GID=" << gid;
break;
default:
if ( filter_flag >= 0 )
{
where_string << "UID=" << filter_flag;
}
else
{
goto error_filter;
}
break;
}
// Call the template pool dump
rc = pool->dump(oss,where_string.str());
if ( rc != 0 )
{
goto error_dump;
}
success_response(oss.str());
return;
error_filter:
failure_response(XML_RPC_API, "Incorrect filter_flag, must be >= -3.");
return;
error_dump: //TBD Improve Error messages for DUMP
oss.str();
failure_response(INTERNAL,"Internal Error");
return;
}

View File

@ -24,6 +24,8 @@ lib_name='nebula_rm'
source_files=[
'Request.cc',
'RequestManager.cc',
'RequestManagerPoolInfo.cc',
'RequestManagerPoolInfoFilter.cc',
# 'RequestManagerAction.cc',
# 'RequestManagerAllocate.cc',
# 'RequestManagerDeploy.cc',

View File

@ -262,7 +262,6 @@ bool UserPool::authenticate(const string& session, int& user_id, int& group_id)
mad_pass,
true,
error_str);
}
if ( user_id == -1 )