2012-02-24 21:55:21 +04:00
/* -------------------------------------------------------------------------- */
2013-01-24 19:18:30 +04:00
/* Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs */
2012-02-24 21:55:21 +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_CLUSTER_H
# define REQUEST_MANAGER_CLUSTER_H
# include "Request.h"
# include "Nebula.h"
using namespace std ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerCluster : public Request
{
protected :
RequestManagerCluster ( const string & method_name ,
const string & help ,
const string & params )
: Request ( method_name , params , help )
{
Nebula & nd = Nebula : : instance ( ) ;
clpool = nd . get_clpool ( ) ;
hpool = nd . get_hpool ( ) ;
2012-02-28 15:17:33 +04:00
dspool = nd . get_dspool ( ) ;
2012-02-29 21:09:47 +04:00
vnpool = nd . get_vnpool ( ) ;
2012-02-24 21:55:21 +04:00
auth_object = PoolObjectSQL : : CLUSTER ;
2012-02-28 18:29:32 +04:00
auth_op = AuthRequest : : ADMIN ;
2012-02-24 21:55:21 +04:00
} ;
~ RequestManagerCluster ( ) { } ;
/* --------------------------------------------------------------------- */
2012-02-28 15:17:33 +04:00
ClusterPool * clpool ;
HostPool * hpool ;
DatastorePool * dspool ;
2012-02-29 21:09:47 +04:00
VirtualNetworkPool * vnpool ;
2012-02-24 21:55:21 +04:00
/* --------------------------------------------------------------------- */
2012-03-01 20:14:52 +04:00
virtual void request_execute ( xmlrpc_c : : paramList const & paramList ,
2012-02-24 21:55:21 +04:00
RequestAttributes & att ) = 0 ;
2012-02-27 21:55:15 +04:00
void add_generic (
2012-03-01 20:14:52 +04:00
int cluster_id ,
int object_id ,
2012-02-27 21:55:15 +04:00
RequestAttributes & att ,
PoolSQL * pool ,
PoolObjectSQL : : ObjectType type ) ;
2012-12-17 19:54:17 +04:00
virtual Datastore : : DatastoreType get_ds_type ( PoolObjectSQL * obj )
{
return Datastore : : FILE_DS ;
} ;
/**
* Add object to cluster id collection
* @ param cluster where to add the object
* @ param id of the object
* @ param ds_type Datastore type , will be ignored for different objects
* @ param error_msg Error reason , if any
* @ return 0 on success
*/
virtual int add_object (
Cluster * cluster ,
int id ,
Datastore : : DatastoreType ds_type ,
string & error_msg ) = 0 ;
2012-02-27 21:55:15 +04:00
virtual int del_object ( Cluster * cluster , int id , string & error_msg ) = 0 ;
virtual void get ( int oid , bool lock , PoolObjectSQL * * object , Clusterable * * cluster_obj ) = 0 ;
2012-02-24 21:55:21 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2012-03-01 20:14:52 +04:00
class RequestManagerClusterHost : public RequestManagerCluster
2012-02-24 21:55:21 +04:00
{
public :
2012-03-01 20:14:52 +04:00
RequestManagerClusterHost (
const string & method_name ,
const string & help ,
const string & params ) :
RequestManagerCluster ( method_name , help , params ) { } ;
2012-02-24 21:55:21 +04:00
2012-03-01 20:14:52 +04:00
~ RequestManagerClusterHost ( ) { } ;
2012-02-27 21:55:15 +04:00
2012-12-17 19:54:17 +04:00
virtual int add_object (
Cluster * cluster ,
int id ,
Datastore : : DatastoreType ds_type ,
string & error_msg )
2012-02-27 21:55:15 +04:00
{
return cluster - > add_host ( id , error_msg ) ;
} ;
virtual int del_object ( Cluster * cluster , int id , string & error_msg )
{
return cluster - > del_host ( id , error_msg ) ;
} ;
virtual void get ( int oid , bool lock , PoolObjectSQL * * object , Clusterable * * cluster_obj )
{
Host * host = hpool - > get ( oid , lock ) ;
* object = static_cast < PoolObjectSQL * > ( host ) ;
* cluster_obj = static_cast < Clusterable * > ( host ) ;
} ;
2012-02-24 21:55:21 +04:00
} ;
2012-02-28 15:17:33 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2012-03-01 20:14:52 +04:00
class ClusterAddHost : public RequestManagerClusterHost
2012-02-28 15:17:33 +04:00
{
public :
2012-03-01 20:14:52 +04:00
ClusterAddHost ( ) :
RequestManagerClusterHost ( " ClusterAddHost " ,
" Adds a host to the cluster " ,
2012-02-28 15:17:33 +04:00
" A:sii " ) { } ;
2012-03-01 20:14:52 +04:00
~ ClusterAddHost ( ) { } ;
2012-02-28 15:17:33 +04:00
2012-03-01 20:14:52 +04:00
void request_execute ( xmlrpc_c : : paramList const & paramList ,
2012-02-28 15:17:33 +04:00
RequestAttributes & att )
{
2012-03-01 20:14:52 +04:00
int cluster_id = xmlrpc_c : : value_int ( paramList . getInt ( 1 ) ) ;
int object_id = xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
return add_generic ( cluster_id , object_id , att ,
hpool , PoolObjectSQL : : HOST ) ;
2012-02-28 15:17:33 +04:00
}
2012-03-01 20:14:52 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterDelHost : public RequestManagerClusterHost
{
public :
ClusterDelHost ( ) :
RequestManagerClusterHost ( " ClusterDelHost " ,
" Deletes a host from its cluster " ,
" A:sii " ) { } ;
~ ClusterDelHost ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & paramList ,
RequestAttributes & att )
{
// First param is ignored, as objects can be assigned to only
// one cluster
int cluster_id = ClusterPool : : NONE_CLUSTER_ID ;
int object_id = xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
return add_generic ( cluster_id , object_id , att ,
hpool , PoolObjectSQL : : HOST ) ;
}
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerClusterDatastore : public RequestManagerCluster
{
public :
RequestManagerClusterDatastore (
const string & method_name ,
const string & help ,
const string & params ) :
RequestManagerCluster ( method_name , help , params ) { } ;
~ RequestManagerClusterDatastore ( ) { } ;
2012-02-28 15:17:33 +04:00
2012-12-17 19:54:17 +04:00
virtual Datastore : : DatastoreType get_ds_type ( PoolObjectSQL * obj )
{
return static_cast < Datastore * > ( obj ) - > get_type ( ) ;
} ;
virtual int add_object (
Cluster * cluster ,
int id ,
Datastore : : DatastoreType ds_type ,
string & error_msg )
2012-02-28 15:17:33 +04:00
{
2012-12-17 19:54:17 +04:00
return cluster - > add_datastore ( id , ds_type , error_msg ) ;
2012-02-28 15:17:33 +04:00
} ;
virtual int del_object ( Cluster * cluster , int id , string & error_msg )
{
return cluster - > del_datastore ( id , error_msg ) ;
} ;
virtual void get ( int oid , bool lock , PoolObjectSQL * * object , Clusterable * * cluster_obj )
{
Datastore * ds = dspool - > get ( oid , lock ) ;
* object = static_cast < PoolObjectSQL * > ( ds ) ;
* cluster_obj = static_cast < Clusterable * > ( ds ) ;
} ;
} ;
2012-02-29 21:09:47 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2012-03-01 20:14:52 +04:00
class ClusterAddDatastore : public RequestManagerClusterDatastore
2012-02-29 21:09:47 +04:00
{
public :
2012-03-01 20:14:52 +04:00
ClusterAddDatastore ( ) :
RequestManagerClusterDatastore ( " ClusterAddDatastore " ,
" Adds a datastore to the cluster " ,
2012-02-29 21:09:47 +04:00
" A:sii " ) { } ;
2012-03-01 20:14:52 +04:00
~ ClusterAddDatastore ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & paramList ,
RequestAttributes & att )
{
int cluster_id = xmlrpc_c : : value_int ( paramList . getInt ( 1 ) ) ;
int object_id = xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
return add_generic ( cluster_id , object_id , att ,
dspool , PoolObjectSQL : : DATASTORE ) ;
}
} ;
2012-02-29 21:09:47 +04:00
2012-03-01 20:14:52 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterDelDatastore : public RequestManagerClusterDatastore
{
public :
ClusterDelDatastore ( ) :
RequestManagerClusterDatastore ( " ClusterDelDatastore " ,
" Deletes a datastore from its cluster " ,
" A:sii " ) { } ;
~ ClusterDelDatastore ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & paramList ,
2012-02-29 21:09:47 +04:00
RequestAttributes & att )
{
2012-03-01 20:14:52 +04:00
// First param is ignored, as objects can be assigned to only
// one cluster
int cluster_id = ClusterPool : : NONE_CLUSTER_ID ;
int object_id = xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
return add_generic ( cluster_id , object_id , att ,
dspool , PoolObjectSQL : : DATASTORE ) ;
2012-02-29 21:09:47 +04:00
}
2012-03-01 20:14:52 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerClusterVNet : public RequestManagerCluster
{
public :
RequestManagerClusterVNet (
const string & method_name ,
const string & help ,
const string & params ) :
RequestManagerCluster ( method_name , help , params ) { } ;
~ RequestManagerClusterVNet ( ) { } ;
2012-02-29 21:09:47 +04:00
2012-12-17 19:54:17 +04:00
virtual int add_object (
Cluster * cluster ,
int id ,
Datastore : : DatastoreType ds_type ,
string & error_msg )
2012-02-29 21:09:47 +04:00
{
return cluster - > add_vnet ( id , error_msg ) ;
} ;
virtual int del_object ( Cluster * cluster , int id , string & error_msg )
{
return cluster - > del_vnet ( id , error_msg ) ;
} ;
virtual void get ( int oid , bool lock , PoolObjectSQL * * object , Clusterable * * cluster_obj )
{
VirtualNetwork * vnet = vnpool - > get ( oid , lock ) ;
* object = static_cast < PoolObjectSQL * > ( vnet ) ;
* cluster_obj = static_cast < Clusterable * > ( vnet ) ;
} ;
} ;
2012-03-01 20:14:52 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterAddVNet : public RequestManagerClusterVNet
{
public :
ClusterAddVNet ( ) :
RequestManagerClusterVNet ( " ClusterAddVNet " ,
" Adds a virtual network to the cluster " ,
" A:sii " ) { } ;
~ ClusterAddVNet ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & paramList ,
RequestAttributes & att )
{
int cluster_id = xmlrpc_c : : value_int ( paramList . getInt ( 1 ) ) ;
int object_id = xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
return add_generic ( cluster_id , object_id , att ,
vnpool , PoolObjectSQL : : NET ) ;
}
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterDelVNet : public RequestManagerClusterVNet
{
public :
ClusterDelVNet ( ) :
RequestManagerClusterVNet ( " ClusterDelVNet " ,
" Deletes a virtual network from its cluster " ,
" A:sii " ) { } ;
~ ClusterDelVNet ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & paramList ,
RequestAttributes & att )
{
// First param is ignored, as objects can be assigned to only
// one cluster
int cluster_id = ClusterPool : : NONE_CLUSTER_ID ;
int object_id = xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
return add_generic ( cluster_id , object_id , att ,
vnpool , PoolObjectSQL : : NET ) ;
}
} ;
2012-02-24 21:55:21 +04:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
# endif