1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-03 01:17:41 +03:00

feature #622: VirtualNetwork methods uses a common base class

This commit is contained in:
Ruben S. Montero 2011-05-29 00:37:59 +02:00
parent ccced18ed9
commit 700d92738e
5 changed files with 219 additions and 10 deletions

View File

@ -0,0 +1,102 @@
/* -------------------------------------------------------------------------- */
/* 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_VIRTUAL_NETWORK_H
#define REQUEST_MANAGER_VIRTUAL_NETWORK_H
#include "Request.h"
#include "Nebula.h"
using namespace std;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerVirtualNetwork: public Request
{
protected:
RequestManagerVirtualNetwork(const string& method_name,
const string& help)
:Request(method_name,"A:sis",help)
{
Nebula& nd = Nebula::instance();
pool = nd.get_vnpool();
auth_object = AuthRequest::NET;
auth_op = AuthRequest::MANAGE;
};
~RequestManagerVirtualNetwork(){};
/* -------------------------------------------------------------------- */
void request_execute(xmlrpc_c::paramList const& _paramList);
virtual int leases_action(VirtualNetwork * vn,
VirtualNetworkTemplate * tmpl,
string& error_str) = 0;
/* -------------------------------------------------------------------- */
string leases_error (const string& error);
string leases_error (char * error);
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualNetworkAddLeases : public RequestManagerVirtualNetwork
{
public:
VirtualNetworkAddLeases():
RequestManagerVirtualNetwork("VirtualNetworkAddLeases",
"Adds leases to a virtual network"){};
~VirtualNetworkAddLeases(){};
int leases_action(VirtualNetwork * vn,
VirtualNetworkTemplate * tmpl,
string& error_str)
{
return vn->add_leases(tmpl, error_str);
}
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualNetworkRemoveLeases : public RequestManagerVirtualNetwork
{
public:
VirtualNetworkRemoveLeases():
RequestManagerVirtualNetwork("VirtualNetworkRemoveLeases",
"Removes leases from a virtual network"){};
~VirtualNetworkRemoveLeases(){};
int leases_action(VirtualNetwork * vn,
VirtualNetworkTemplate * tmpl,
string& error_str)
{
return vn->remove_leases(tmpl, error_str);
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#endif

View File

@ -25,6 +25,8 @@
#include "RequestManagerPublish.h"
#include "RequestManagerAllocate.h"
#include "RequestManagerVirtualNetwork.h"
#include <sys/signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
@ -220,6 +222,10 @@ void RequestManager::do_action(
void RequestManager::register_xml_methods()
{
// VirtualNetwork Methods
xmlrpc_c::methodPtr vn_addleases(new VirtualNetworkAddLeases());
xmlrpc_c::methodPtr vn_rmleases(new VirtualNetworkRemoveLeases());
// Allocate Methods
xmlrpc_c::methodPtr image_allocate(new ImageAllocate());
xmlrpc_c::methodPtr vn_allocate(new VirtualNetworkAllocate());
@ -321,11 +327,6 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr vn_addleases(new
RequestManager::VirtualNetworkAddLeases(vnpool, upool));
xmlrpc_c::methodPtr vn_rmleases(new
RequestManager::VirtualNetworkRemoveLeases(vnpool, upool));
xmlrpc_c::methodPtr vn_chown(new
RequestManager::GenericChown(this,NET));
@ -414,10 +415,10 @@ void RequestManager::register_xml_methods()
/* Network related 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.vn.addleases", vn_addleases);
RequestManagerRegistry.addMethod("one.vn.rmleases", vn_rmleases);
RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate);
RequestManagerRegistry.addMethod("one.vn.publish", vn_publish);
RequestManagerRegistry.addMethod("one.vn.delete", vn_delete);

View File

@ -44,8 +44,7 @@ string RequestManagerAllocate::allocate_error (char *error)
{
ostringstream oss;
oss << "[" << method_name << "]" << " Error allocating a new "
<< object_name(auth_object) << ". Parse error";
oss << "Parse error";
if ( error != 0 )
{
@ -57,7 +56,7 @@ string RequestManagerAllocate::allocate_error (char *error)
oss << ".";
}
return oss.str();
return allocate_error(oss.str());
}
/* -------------------------------------------------------------------------- */

View File

@ -0,0 +1,106 @@
/* -------------------------------------------------------------------------- */
/* 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 "RequestManagerVirtualNetwork.h"
#include "VirtualNetworkTemplate.h"
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();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string RequestManagerVirtualNetwork::leases_error (char *error)
{
ostringstream oss;
oss << "Parse error";
if ( error != 0 )
{
oss << ": " << error;
free(error);
}
return leases_error(oss.str());
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void RequestManagerVirtualNetwork::
request_execute(xmlrpc_c::paramList const& paramList)
{
int id = xmlrpc_c::value_int (paramList.getInt(1));
string str_tmpl = xmlrpc_c::value_string (paramList.getString(2));
VirtualNetworkTemplate tmpl;
VirtualNetwork * vn;
char * error_msg = 0;
string error_str;
int rc;
if ( basic_authorization(id) == false )
{
return;
}
rc = tmpl.parse(str_tmpl, &error_msg);
if ( rc != 0 )
{
failure_response(INTERNAL, leases_error(error_msg));
return;
}
vn = static_cast<VirtualNetwork *>(pool->get(id,true));
if ( vn == 0 )
{
failure_response(NO_EXISTS, get_error(object_name(auth_object),id));
return;
}
rc = leases_action(vn,&tmpl,error_str);
if ( rc < 0 )
{
failure_response(INTERNAL, leases_error(error_str));
}
vn->unlock();
success_response(id);
}

View File

@ -30,6 +30,7 @@ source_files=[
'RequestManagerDelete.cc',
'RequestManagerPublish.cc',
'RequestManagerAllocate.cc',
'RequestManagerVirtualNetwork.cc',
# 'RequestManagerAction.cc',
# 'RequestManagerAllocate.cc',