2011-05-28 06:03:09 +04:00
/* -------------------------------------------------------------------------- */
2012-01-12 15:29:18 +04:00
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
2011-05-28 06:03:09 +04: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 22:37:08 +04:00
# include "DatastoreTemplate.h"
2011-05-28 06:03:09 +04:00
using namespace std ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerAllocate : public Request
{
protected :
RequestManagerAllocate ( const string & method_name ,
const string & help ,
const string & xml_args ,
2012-03-01 20:14:52 +04:00
bool dt )
: Request ( method_name , xml_args , help ) , do_template ( dt )
2011-05-28 06:03:09 +04:00
{
auth_op = AuthRequest : : CREATE ;
2012-02-29 19:06:29 +04:00
2012-03-01 20:14:52 +04:00
Nebula & nd = Nebula : : instance ( ) ;
clpool = nd . get_clpool ( ) ;
2011-05-28 06:03:09 +04:00
} ;
~ RequestManagerAllocate ( ) { } ;
/* -------------------------------------------------------------------- */
2012-02-15 19:47:52 +04:00
virtual void request_execute ( xmlrpc_c : : paramList const & _paramList ,
2011-07-07 14:45:13 +04:00
RequestAttributes & att ) ;
2011-05-28 06:03:09 +04:00
2012-02-29 19:06:29 +04:00
virtual bool allocate_authorization ( Template * obj_template ,
RequestAttributes & att ,
PoolObjectAuth * cluster_perms ) ;
2011-05-28 06:03:09 +04:00
/* -------------------------------------------------------------------- */
virtual Template * get_object_template ( ) { return 0 ; } ;
virtual int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 14:45:13 +04:00
string & error_str ,
2012-02-15 19:47:52 +04:00
RequestAttributes & att )
{
return - 1 ;
} ;
2012-02-29 19:06:29 +04:00
virtual int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
string & error_str ,
RequestAttributes & att ,
int cluster_id ,
const string & cluster_name )
{
return pool_allocate ( _paramList , tmpl , id , error_str , att ) ;
} ;
virtual int get_cluster_id ( xmlrpc_c : : paramList const & paramList )
{
2012-03-01 20:14:52 +04:00
return ClusterPool : : NONE_CLUSTER_ID ;
2012-02-29 19:06:29 +04:00
} ;
virtual int add_to_cluster ( Cluster * cluster , int id , string & error_msg )
{
return - 1 ;
} ;
protected :
ClusterPool * clpool ;
2011-05-28 06:03:09 +04:00
private :
bool do_template ;
} ;
2011-06-01 14:37:39 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualMachineAllocate : public RequestManagerAllocate
{
public :
VirtualMachineAllocate ( ) :
RequestManagerAllocate ( " VirtualMachineAllocate " ,
" Allocates a new virtual machine " ,
" A:ss " ,
true )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vmpool ( ) ;
2012-01-03 05:58:23 +04:00
auth_object = PoolObjectSQL : : VM ;
2011-06-01 14:37:39 +04:00
} ;
~ VirtualMachineAllocate ( ) { } ;
2012-02-29 19:06:29 +04:00
2011-06-01 14:37:39 +04:00
/* --------------------------------------------------------------------- */
Template * get_object_template ( )
{
return new VirtualMachineTemplate ;
} ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 14:45:13 +04:00
string & error_str ,
RequestAttributes & att ) ;
2011-06-01 14:37:39 +04:00
2012-02-29 19:06:29 +04:00
bool allocate_authorization ( Template * obj_template ,
RequestAttributes & att ,
PoolObjectAuth * cluster_perms ) ;
2011-06-01 14:37:39 +04:00
} ;
2011-05-28 06:03:09 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualNetworkAllocate : public RequestManagerAllocate
{
public :
VirtualNetworkAllocate ( ) :
2011-06-29 14:50:16 +04:00
RequestManagerAllocate ( " VirtualNetworkAllocate " ,
2011-05-28 06:03:09 +04:00
" Allocates a new virtual network " ,
2012-03-09 18:49:45 +04:00
" A:ssi " ,
2011-05-28 06:03:09 +04:00
true )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vnpool ( ) ;
2012-01-03 05:58:23 +04:00
auth_object = PoolObjectSQL : : NET ;
2011-05-28 06:03:09 +04:00
} ;
~ VirtualNetworkAllocate ( ) { } ;
/* --------------------------------------------------------------------- */
Template * get_object_template ( )
{
return new VirtualNetworkTemplate ;
} ;
2012-02-29 21:09:47 +04:00
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
2011-05-28 06:03:09 +04:00
Template * tmpl ,
2012-02-29 21:09:47 +04:00
int & id ,
2011-07-07 14:45:13 +04:00
string & error_str ,
2012-02-29 21:09:47 +04:00
RequestAttributes & att ,
int cluster_id ,
const string & cluster_name ) ;
2012-03-09 18:49:45 +04:00
int get_cluster_id ( xmlrpc_c : : paramList const & paramList )
{
return xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
} ;
int add_to_cluster ( Cluster * cluster , int id , string & error_msg )
{
return cluster - > add_datastore ( id , error_msg ) ;
} ;
2011-05-28 06:03:09 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ImageAllocate : public RequestManagerAllocate
{
public :
ImageAllocate ( ) :
RequestManagerAllocate ( " ImageAllocate " ,
" Allocates a new image " ,
2012-03-09 18:49:45 +04:00
" A:ssi " ,
2011-05-28 06:03:09 +04:00
true )
2012-02-15 19:47:52 +04:00
{
2011-05-28 06:03:09 +04:00
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_ipool ( ) ;
2012-01-03 05:58:23 +04:00
auth_object = PoolObjectSQL : : IMAGE ;
2011-05-28 06:03:09 +04:00
} ;
~ ImageAllocate ( ) { } ;
/* --------------------------------------------------------------------- */
2012-02-15 19:47:52 +04:00
void request_execute ( xmlrpc_c : : paramList const & _paramList ,
RequestAttributes & att ) ;
2012-03-09 20:32:54 +04:00
bool allocate_authorization ( Template * obj_template ,
RequestAttributes & att ,
PoolObjectAuth * cluster_perms ) ;
2011-05-28 06:03:09 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class TemplateAllocate : public RequestManagerAllocate
{
public :
TemplateAllocate ( ) :
RequestManagerAllocate ( " TemplateAllocate " ,
" Allocates a new virtual machine template " ,
" A:ss " ,
true )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_tpool ( ) ;
2012-01-03 05:58:23 +04:00
auth_object = PoolObjectSQL : : TEMPLATE ;
2011-05-28 06:03:09 +04:00
} ;
~ TemplateAllocate ( ) { } ;
/* --------------------------------------------------------------------- */
Template * get_object_template ( )
{
return new VirtualMachineTemplate ;
} ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 14:45:13 +04:00
string & error_str ,
RequestAttributes & att ) ;
2011-05-28 06:03:09 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class HostAllocate : public RequestManagerAllocate
{
public :
HostAllocate ( ) :
2011-06-29 14:50:16 +04:00
RequestManagerAllocate ( " HostAllocate " ,
2011-05-28 06:03:09 +04:00
" Allocates a new host " ,
2012-02-28 20:30:07 +04:00
" A:sssssi " ,
2012-03-01 20:14:52 +04:00
false )
2011-05-28 06:03:09 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_hpool ( ) ;
2012-01-03 05:58:23 +04:00
auth_object = PoolObjectSQL : : HOST ;
2011-05-28 06:03:09 +04:00
} ;
~ HostAllocate ( ) { } ;
2012-02-28 20:30:07 +04:00
/* --------------------------------------------------------------------- */
2012-02-29 19:06:29 +04:00
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
string & error_str ,
RequestAttributes & att ,
int cluster_id ,
const string & cluster_name ) ;
2012-03-01 20:14:52 +04:00
int get_cluster_id ( xmlrpc_c : : paramList const & paramList )
{
return xmlrpc_c : : value_int ( paramList . getInt ( 5 ) ) ;
} ;
2012-02-29 19:06:29 +04:00
2012-03-01 20:14:52 +04:00
int add_to_cluster ( Cluster * cluster , int id , string & error_msg )
{
return cluster - > add_host ( id , error_msg ) ;
} ;
2011-05-28 06:03:09 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class UserAllocate : public RequestManagerAllocate
{
public :
UserAllocate ( ) :
2011-06-29 14:50:16 +04:00
RequestManagerAllocate ( " UserAllocate " ,
2011-05-28 06:03:09 +04:00
" Returns user information " ,
2011-11-02 20:36:53 +04:00
" A:ssss " ,
2011-05-28 06:03:09 +04:00
false )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_upool ( ) ;
2012-01-03 05:58:23 +04:00
auth_object = PoolObjectSQL : : USER ;
2011-05-28 06:03:09 +04:00
} ;
~ UserAllocate ( ) { } ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 14:45:13 +04:00
string & error_str ,
RequestAttributes & att ) ;
2011-05-28 06:03:09 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class GroupAllocate : public RequestManagerAllocate
{
public :
GroupAllocate ( ) :
2011-06-01 14:37:39 +04:00
RequestManagerAllocate ( " GroupAllocate " ,
2011-05-28 06:03:09 +04:00
" Allocates a new group " ,
" A:ss " ,
false )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_gpool ( ) ;
2012-01-03 05:58:23 +04:00
auth_object = PoolObjectSQL : : GROUP ;
2011-05-28 06:03:09 +04:00
} ;
~ GroupAllocate ( ) { } ;
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
2011-07-07 14:45:13 +04:00
string & error_str ,
RequestAttributes & att ) ;
2011-05-28 06:03:09 +04:00
} ;
2012-02-09 20:56:47 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class DatastoreAllocate : public RequestManagerAllocate
{
public :
DatastoreAllocate ( ) :
RequestManagerAllocate ( " DatastoreAllocate " ,
" Allocates a new Datastore " ,
2012-02-29 19:30:52 +04:00
" A:ssi " ,
2012-02-16 22:37:08 +04:00
true )
2012-02-09 20:56:47 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_dspool ( ) ;
auth_object = PoolObjectSQL : : DATASTORE ;
} ;
~ DatastoreAllocate ( ) { } ;
2012-02-16 22:37:08 +04:00
/* -------------------------------------------------------------------- */
Template * get_object_template ( )
{
return new DatastoreTemplate ;
} ;
2012-02-09 20:56:47 +04:00
int pool_allocate ( xmlrpc_c : : paramList const & _paramList ,
Template * tmpl ,
int & id ,
string & error_str ,
2012-02-29 19:30:52 +04:00
RequestAttributes & att ,
int cluster_id ,
const string & cluster_name ) ;
2012-03-01 20:14:52 +04:00
int get_cluster_id ( xmlrpc_c : : paramList const & paramList )
{
return xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
} ;
2012-02-29 19:30:52 +04:00
2012-03-01 20:14:52 +04:00
int add_to_cluster ( Cluster * cluster , int id , string & error_msg )
{
return cluster - > add_datastore ( id , error_msg ) ;
} ;
2012-02-09 20:56:47 +04:00
} ;
2012-02-24 18:53:53 +04: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 ,
RequestAttributes & att ) ;
} ;
2011-05-28 06:03:09 +04:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
# endif