2011-05-28 04:03:09 +02:00
/* -------------------------------------------------------------------------- */
2014-01-09 11:51:20 +01:00
/* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs */
2011-05-28 04:03:09 +02:00
/* */
/* 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_H_
# define REQUEST_MANAGER_ALLOCATE_H_
# include "Request.h"
# include "Nebula.h"
# include "VirtualNetworkTemplate.h"
# include "ImageTemplate.h"
# include "VirtualMachineTemplate.h"
2012-02-16 19:37:08 +01:00
# include "DatastoreTemplate.h"
2011-05-28 04:03:09 +02:00
using namespace std ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerAllocate : public Request
{
protected :
RequestManagerAllocate ( const string & method_name ,
const string & help ,
const string & xml_args ,
2013-12-12 19:08:59 +01:00
bool _do_template )
: Request ( method_name , xml_args , help ) , do_template ( _do_template )
2011-05-28 04:03:09 +02:00
{
auth_op = AuthRequest : : CREATE ;
2012-02-29 16:06:29 +01:00
2012-03-01 17:14:52 +01:00
Nebula & nd = Nebula : : instance ( ) ;
clpool = nd . get_clpool ( ) ;
2011-05-28 04:03:09 +02:00
} ;
~ RequestManagerAllocate ( ) { } ;
/* -------------------------------------------------------------------- */
2012-02-15 16:47:52 +01:00
virtual void request_execute ( xmlrpc_c : : paramList const & _paramList ,
2011-07-07 12:45:13 +02:00
RequestAttributes & att ) ;
2011-05-28 04:03:09 +02:00
2012-02-29 16:06:29 +01:00
virtual bool allocate_authorization ( Template * obj_template ,
RequestAttributes & att ,
PoolObjectAuth * cluster_perms ) ;
2011-05-28 04:03:09 +02:00
/* -------------------------------------------------------------------- */
virtual Template * get_object_template ( ) { return 0 ; } ;
virtual int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 12:45:13 +02:00
string & error_str ,
2013-01-18 18:34:51 +01:00
RequestAttributes & att ,
int umask )
2012-02-15 16:47:52 +01:00
{
return - 1 ;
} ;
2012-02-29 16:06:29 +01:00
virtual int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
string & error_str ,
RequestAttributes & att ,
int cluster_id ,
2013-01-18 18:34:51 +01:00
const string & cluster_name ,
int umask )
2012-02-29 16:06:29 +01:00
{
2013-01-18 18:34:51 +01:00
return pool_allocate ( _paramList , tmpl , id , error_str , att , umask ) ;
2012-02-29 16:06:29 +01:00
} ;
virtual int get_cluster_id ( xmlrpc_c : : paramList const & paramList )
{
2012-03-01 17:14:52 +01:00
return ClusterPool : : NONE_CLUSTER_ID ;
2012-02-29 16:06:29 +01:00
} ;
2012-12-17 16:54:17 +01:00
virtual int add_to_cluster (
Cluster * cluster ,
int id ,
Datastore : : DatastoreType ds_type ,
string & error_msg )
2012-02-29 16:06:29 +01:00
{
return - 1 ;
} ;
2012-12-17 16:54:17 +01:00
virtual Datastore : : DatastoreType get_ds_type ( int oid )
{
return Datastore : : FILE_DS ;
} ;
2012-02-29 16:06:29 +01:00
protected :
ClusterPool * clpool ;
2011-05-28 04:03:09 +02:00
private :
bool do_template ;
} ;
2011-06-01 12:37:39 +02:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualMachineAllocate : public RequestManagerAllocate
{
public :
VirtualMachineAllocate ( ) :
RequestManagerAllocate ( " VirtualMachineAllocate " ,
" Allocates a new virtual machine " ,
2012-12-20 17:45:27 +01:00
" A:ssb " ,
2011-06-01 12:37:39 +02:00
true )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vmpool ( ) ;
2012-01-03 02:58:23 +01:00
auth_object = PoolObjectSQL : : VM ;
2011-06-01 12:37:39 +02:00
} ;
~ VirtualMachineAllocate ( ) { } ;
2012-02-29 16:06:29 +01:00
2011-06-01 12:37:39 +02:00
/* --------------------------------------------------------------------- */
Template * get_object_template ( )
{
return new VirtualMachineTemplate ;
} ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 12:45:13 +02:00
string & error_str ,
2013-01-18 18:34:51 +01:00
RequestAttributes & att ,
int umask ) ;
2011-06-01 12:37:39 +02:00
2012-02-29 16:06:29 +01:00
bool allocate_authorization ( Template * obj_template ,
RequestAttributes & att ,
PoolObjectAuth * cluster_perms ) ;
2011-06-01 12:37:39 +02:00
} ;
2011-05-28 04:03:09 +02:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualNetworkAllocate : public RequestManagerAllocate
{
public :
VirtualNetworkAllocate ( ) :
2011-06-29 12:50:16 +02:00
RequestManagerAllocate ( " VirtualNetworkAllocate " ,
2011-05-28 04:03:09 +02:00
" Allocates a new virtual network " ,
2012-03-09 15:49:45 +01:00
" A:ssi " ,
2011-05-28 04:03:09 +02:00
true )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vnpool ( ) ;
2012-01-03 02:58:23 +01:00
auth_object = PoolObjectSQL : : NET ;
2011-05-28 04:03:09 +02:00
} ;
~ VirtualNetworkAllocate ( ) { } ;
/* --------------------------------------------------------------------- */
Template * get_object_template ( )
{
return new VirtualNetworkTemplate ;
} ;
2012-02-29 18:09:47 +01:00
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
2011-05-28 04:03:09 +02:00
Template * tmpl ,
2012-02-29 18:09:47 +01:00
int & id ,
2011-07-07 12:45:13 +02:00
string & error_str ,
2012-02-29 18:09:47 +01:00
RequestAttributes & att ,
int cluster_id ,
2013-01-18 18:34:51 +01:00
const string & cluster_name ,
int umask ) ;
2012-03-09 15:49:45 +01:00
int get_cluster_id ( xmlrpc_c : : paramList const & paramList )
{
return xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
} ;
2012-12-17 16:54:17 +01:00
int add_to_cluster (
Cluster * cluster ,
int id ,
Datastore : : DatastoreType ds_type ,
string & error_msg )
2012-03-09 15:49:45 +01:00
{
2012-03-13 18:38:50 +01:00
return cluster - > add_vnet ( id , error_msg ) ;
2012-03-09 15:49:45 +01:00
} ;
2011-05-28 04:03:09 +02:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ImageAllocate : public RequestManagerAllocate
{
public :
ImageAllocate ( ) :
RequestManagerAllocate ( " ImageAllocate " ,
" Allocates a new image " ,
2012-03-09 15:49:45 +01:00
" A:ssi " ,
2011-05-28 04:03:09 +02:00
true )
2012-02-15 16:47:52 +01:00
{
2011-05-28 04:03:09 +02:00
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_ipool ( ) ;
2012-01-03 02:58:23 +01:00
auth_object = PoolObjectSQL : : IMAGE ;
2011-05-28 04:03:09 +02:00
} ;
~ ImageAllocate ( ) { } ;
/* --------------------------------------------------------------------- */
2012-02-15 16:47:52 +01:00
void request_execute ( xmlrpc_c : : paramList const & _paramList ,
RequestAttributes & att ) ;
2011-05-28 04:03:09 +02:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class TemplateAllocate : public RequestManagerAllocate
{
public :
2012-06-08 11:43:55 +02:00
TemplateAllocate ( ) :
2011-05-28 04:03:09 +02:00
RequestManagerAllocate ( " TemplateAllocate " ,
" Allocates a new virtual machine template " ,
" A:ss " ,
true )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_tpool ( ) ;
2012-01-03 02:58:23 +01:00
auth_object = PoolObjectSQL : : TEMPLATE ;
2011-05-28 04:03:09 +02:00
} ;
~ TemplateAllocate ( ) { } ;
/* --------------------------------------------------------------------- */
Template * get_object_template ( )
2012-06-08 11:43:55 +02:00
{
2011-05-28 04:03:09 +02:00
return new VirtualMachineTemplate ;
} ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 12:45:13 +02:00
string & error_str ,
2013-01-18 18:34:51 +01:00
RequestAttributes & att ,
int umask ) ;
2011-05-28 04:03:09 +02:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class HostAllocate : public RequestManagerAllocate
{
public :
HostAllocate ( ) :
2011-06-29 12:50:16 +02:00
RequestManagerAllocate ( " HostAllocate " ,
2011-05-28 04:03:09 +02:00
" Allocates a new host " ,
2012-02-28 17:30:07 +01:00
" A:sssssi " ,
2012-03-01 17:14:52 +01:00
false )
2011-05-28 04:03:09 +02:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_hpool ( ) ;
2012-01-03 02:58:23 +01:00
auth_object = PoolObjectSQL : : HOST ;
2011-05-28 04:03:09 +02:00
} ;
~ HostAllocate ( ) { } ;
2012-02-28 17:30:07 +01:00
/* --------------------------------------------------------------------- */
2012-02-29 16:06:29 +01:00
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
string & error_str ,
RequestAttributes & att ,
int cluster_id ,
2013-01-18 18:34:51 +01:00
const string & cluster_name ,
int umask ) ;
2012-02-29 16:06:29 +01:00
2012-03-01 17:14:52 +01:00
int get_cluster_id ( xmlrpc_c : : paramList const & paramList )
{
return xmlrpc_c : : value_int ( paramList . getInt ( 5 ) ) ;
} ;
2012-02-29 16:06:29 +01:00
2012-12-17 16:54:17 +01:00
int add_to_cluster (
Cluster * cluster ,
int id ,
Datastore : : DatastoreType ds_type ,
string & error_msg )
2012-03-01 17:14:52 +01:00
{
return cluster - > add_host ( id , error_msg ) ;
} ;
2011-05-28 04:03:09 +02:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class UserAllocate : public RequestManagerAllocate
{
public :
UserAllocate ( ) :
2011-06-29 12:50:16 +02:00
RequestManagerAllocate ( " UserAllocate " ,
2011-05-28 04:03:09 +02:00
" Returns user information " ,
2011-11-02 17:36:53 +01:00
" A:ssss " ,
2011-05-28 04:03:09 +02:00
false )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_upool ( ) ;
2012-01-03 02:58:23 +01:00
auth_object = PoolObjectSQL : : USER ;
2011-05-28 04:03:09 +02:00
} ;
~ UserAllocate ( ) { } ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 12:45:13 +02:00
string & error_str ,
2013-01-18 18:34:51 +01:00
RequestAttributes & att ,
int umask ) ;
2012-10-02 16:25:57 +02:00
void log_xmlrpc_param (
const xmlrpc_c : : value & v ,
ostringstream & oss ,
const int & index ) ;
2011-05-28 04:03:09 +02:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class GroupAllocate : public RequestManagerAllocate
{
public :
GroupAllocate ( ) :
2011-06-01 12:37:39 +02:00
RequestManagerAllocate ( " GroupAllocate " ,
2011-05-28 04:03:09 +02:00
" Allocates a new group " ,
" A:ss " ,
false )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_gpool ( ) ;
2012-01-03 02:58:23 +01:00
auth_object = PoolObjectSQL : : GROUP ;
2011-05-28 04:03:09 +02:00
} ;
~ GroupAllocate ( ) { } ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 12:45:13 +02:00
string & error_str ,
2013-01-18 18:34:51 +01:00
RequestAttributes & att ,
int umask ) ;
2011-05-28 04:03:09 +02:00
} ;
2012-02-09 17:56:47 +01:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class DatastoreAllocate : public RequestManagerAllocate
{
public :
DatastoreAllocate ( ) :
RequestManagerAllocate ( " DatastoreAllocate " ,
" Allocates a new Datastore " ,
2012-02-29 16:30:52 +01:00
" A:ssi " ,
2012-02-16 19:37:08 +01:00
true )
2012-02-09 17:56:47 +01:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_dspool ( ) ;
auth_object = PoolObjectSQL : : DATASTORE ;
} ;
~ DatastoreAllocate ( ) { } ;
2012-02-16 19:37:08 +01:00
/* -------------------------------------------------------------------- */
Template * get_object_template ( )
{
return new DatastoreTemplate ;
} ;
2012-02-09 17:56:47 +01:00
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
string & error_str ,
2012-02-29 16:30:52 +01:00
RequestAttributes & att ,
int cluster_id ,
2013-01-18 18:34:51 +01:00
const string & cluster_name ,
int umask ) ;
2012-02-29 16:30:52 +01:00
2012-03-01 17:14:52 +01:00
int get_cluster_id ( xmlrpc_c : : paramList const & paramList )
{
return xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
} ;
2012-02-29 16:30:52 +01:00
2012-12-17 16:54:17 +01:00
virtual Datastore : : DatastoreType get_ds_type ( int oid )
{
Datastore : : DatastoreType ds_type = Datastore : : FILE_DS ;
Datastore * ds = static_cast < DatastorePool * > ( pool ) - > get ( oid , true ) ;
if ( ds ! = 0 )
{
ds_type = ds - > get_type ( ) ;
ds - > unlock ( ) ;
}
return ds_type ;
} ;
int add_to_cluster (
Cluster * cluster ,
int id ,
Datastore : : DatastoreType ds_type ,
string & error_msg )
2012-03-01 17:14:52 +01:00
{
2012-12-17 16:54:17 +01:00
return cluster - > add_datastore ( id , ds_type , error_msg ) ;
2012-03-01 17:14:52 +01:00
} ;
2012-02-09 17:56:47 +01:00
} ;
2012-02-24 15:53:53 +01:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterAllocate : public RequestManagerAllocate
{
public :
ClusterAllocate ( ) :
RequestManagerAllocate ( " ClusterAllocate " ,
" Allocates a new cluster " ,
" A:ss " ,
false )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_clpool ( ) ;
auth_object = PoolObjectSQL : : CLUSTER ;
} ;
~ ClusterAllocate ( ) { } ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
string & error_str ,
2013-01-18 18:34:51 +01:00
RequestAttributes & att ,
int umask ) ;
2012-02-24 15:53:53 +01:00
} ;
2012-06-08 16:00:16 +02:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class DocumentAllocate : public RequestManagerAllocate
{
public :
DocumentAllocate ( ) :
RequestManagerAllocate ( " DocumentAllocate " ,
" Allocates a new generic document " ,
" A:ssi " ,
true )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_docpool ( ) ;
auth_object = PoolObjectSQL : : DOCUMENT ;
} ;
~ DocumentAllocate ( ) { } ;
/* --------------------------------------------------------------------- */
Template * get_object_template ( )
{
return new Template ;
} ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
string & error_str ,
2013-01-18 18:34:51 +01:00
RequestAttributes & att ,
int umask ) ;
2012-06-08 16:00:16 +02:00
} ;
2013-12-12 19:08:59 +01:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ZoneAllocate : public RequestManagerAllocate
{
public :
ZoneAllocate ( ) :
RequestManagerAllocate ( " ZoneAllocate " ,
" Allocates a new zone " ,
" A:ss " ,
true )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_zonepool ( ) ;
auth_object = PoolObjectSQL : : ZONE ;
} ;
~ ZoneAllocate ( ) { } ;
/* --------------------------------------------------------------------- */
2014-02-12 19:27:38 +01:00
void request_execute ( xmlrpc_c : : paramList const & _paramList ,
RequestAttributes & att ) ;
2013-12-12 19:08:59 +01:00
Template * get_object_template ( )
{
return new Template ;
} ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
string & error_str ,
RequestAttributes & att ,
int umask ) ;
} ;
2011-05-28 04:03:09 +02:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
# endif