1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-24 21:34:01 +03:00
one/include/RequestManagerAllocateDB.h
Ruben S. Montero 217ff30a76
B #1815: Remove resource from VDC when erased
L #-: Derived virtual methods use override keyword

Co-authored-by: Pavel Czerny <pczerny@opennebula.systems>
2019-07-05 17:23:21 +02:00

119 lines
3.9 KiB
C++

/* -------------------------------------------------------------------------- */
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
/* */
/* 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_ALLOCATE_DB_H
#define REQUEST_MANAGER_ALLOCATE_DB_H
#include "Request.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class RequestManagerAllocateDB: public Request
{
protected:
RequestManagerAllocateDB(const string& name): Request(name, "A:ss",
"Allocates a new object from its template representation")
{
auth_op = AuthRequest::MANAGE;
};
~RequestManagerAllocateDB(){};
virtual PoolObjectSQL * create(const std::string& xml) = 0;
/* -------------------------------------------------------------------- */
void request_execute(xmlrpc_c::paramList const& pl, RequestAttributes& att) override
{
std::string xml = xmlrpc_c::value_string(pl.getString(1));
if (!att.is_oneadmin())
{
failure_response(AUTHORIZATION, att);
return;
}
PoolObjectSQL * obj = create(xml);
int rc = pool->allocate(obj, att.resp_msg);
if ( rc == -1 )
{
failure_response(INTERNAL, att);
return;
}
success_response(rc, att);
return;
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class MarketPlaceAppAllocateDB: public RequestManagerAllocateDB
{
public:
MarketPlaceAppAllocateDB():RequestManagerAllocateDB("one.marketapp.allocatedb")
{
auth_object = PoolObjectSQL::MARKETPLACEAPP;
pool = Nebula::instance().get_apppool();
};
~MarketPlaceAppAllocateDB(){};
/* -------------------------------------------------------------------- */
PoolObjectSQL * create(const std::string& xml) override
{
PoolObjectSQL * app = static_cast<MarketPlaceAppPool *>(pool)->create();
app->from_xml(xml);
return app;
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class MarketPlaceAllocateDB: public RequestManagerAllocateDB
{
public:
MarketPlaceAllocateDB(): RequestManagerAllocateDB("one.market.allocatedb")
{
auth_object = PoolObjectSQL::MARKETPLACE;
pool = Nebula::instance().get_marketpool();
};
~MarketPlaceAllocateDB(){};
/* -------------------------------------------------------------------- */
PoolObjectSQL * create(const std::string& xml) override
{
PoolObjectSQL * mp = static_cast<MarketPlacePool *>(pool)->create();
mp->from_xml(xml);
return mp;
}
};
#endif /* REQUEST_MANAGER_ALLOCATE_DB_H */