2012-02-24 21:55:21 +04:00
/* -------------------------------------------------------------------------- */
2023-01-09 14:23:19 +03:00
/* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems */
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"
2019-12-10 13:45:15 +03:00
# include "ClusterPool.h"
# include "DatastorePool.h"
# include "VirtualNetworkPool.h"
2012-02-24 21:55:21 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerCluster : public Request
{
protected :
2020-07-02 23:42:10 +03:00
RequestManagerCluster ( const std : : string & method_name ,
const std : : string & help ,
const std : : string & params )
2012-02-24 21:55:21 +04:00
: Request ( method_name , params , help )
{
Nebula & nd = Nebula : : instance ( ) ;
clpool = nd . get_clpool ( ) ;
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 ;
DatastorePool * dspool ;
2012-02-29 21:09:47 +04:00
VirtualNetworkPool * vnpool ;
2012-02-24 21:55:21 +04:00
/* --------------------------------------------------------------------- */
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 ,
2016-03-10 18:28:33 +03:00
PoolObjectSQL : : ObjectType type )
{
action_generic ( cluster_id , object_id , att , pool , type , true ) ;
}
void del_generic (
int cluster_id ,
int object_id ,
RequestAttributes & att ,
PoolSQL * pool ,
PoolObjectSQL : : ObjectType type )
{
action_generic ( cluster_id , object_id , att , pool , type , false ) ;
}
void action_generic (
int cluster_id ,
int object_id ,
RequestAttributes & att ,
PoolSQL * pool ,
PoolObjectSQL : : ObjectType type ,
bool add ) ;
2012-02-27 21:55:15 +04:00
2012-12-17 19:54:17 +04:00
/**
* 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 ,
2020-07-02 23:42:10 +03:00
std : : string & error_msg ) = 0 ;
2012-02-27 21:55:15 +04:00
2020-07-02 23:42:10 +03:00
virtual int del_object ( Cluster * cluster , int id , std : : string & error_msg ) = 0 ;
2012-02-27 21:55:15 +04:00
2020-09-10 10:08:29 +03:00
virtual void get ( int oid , std : : unique_ptr < PoolObjectSQL > & object ,
Clusterable * * cluster_obj ) = 0 ;
2012-02-24 21:55:21 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2016-03-15 18:37:36 +03:00
class RequestManagerClusterHost : public Request
2012-02-24 21:55:21 +04:00
{
2016-03-15 18:37:36 +03:00
protected :
2012-03-01 20:14:52 +04:00
RequestManagerClusterHost (
2020-07-02 23:42:10 +03:00
const std : : string & method_name ,
const std : : string & help ,
const std : : string & params )
2016-03-15 18:37:36 +03:00
: Request ( method_name , params , help )
{
Nebula & nd = Nebula : : instance ( ) ;
clpool = nd . get_clpool ( ) ;
hpool = nd . get_hpool ( ) ;
auth_object = PoolObjectSQL : : CLUSTER ;
auth_op = AuthRequest : : ADMIN ;
} ;
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
2016-03-15 18:37:36 +03:00
/* --------------------------------------------------------------------- */
2012-02-27 21:55:15 +04:00
2016-03-15 18:37:36 +03:00
ClusterPool * clpool ;
HostPool * hpool ;
2012-02-27 21:55:15 +04:00
2016-03-15 18:37:36 +03:00
/* --------------------------------------------------------------------- */
2012-02-27 21:55:15 +04:00
2016-03-15 18:37:36 +03:00
void add_generic (
int cluster_id ,
int host_id ,
RequestAttributes & att ) ;
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 ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerClusterHost ( " one.cluster.addhost " ,
2012-03-01 20:14:52 +04:00
" 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 ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override
2012-02-28 15:17:33 +04:00
{
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 ) ) ;
2016-03-15 18:37:36 +03:00
return add_generic ( cluster_id , object_id , att ) ;
2012-02-28 15:17:33 +04:00
}
2012-03-01 20:14:52 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterDelHost : public RequestManagerClusterHost
{
public :
ClusterDelHost ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerClusterHost ( " one.cluster.delhost " ,
2012-03-01 20:14:52 +04:00
" Deletes a host from its cluster " ,
" A:sii " ) { } ;
~ ClusterDelHost ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & paramList ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override
2012-03-01 20:14:52 +04:00
{
2016-03-15 18:37:36 +03:00
// First param is ignored, as objects can be assigned to only
// one cluster
2016-03-16 15:31:10 +03:00
int cluster_id = ClusterPool : : DEFAULT_CLUSTER_ID ;
2012-03-01 20:14:52 +04:00
int object_id = xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
2016-03-15 18:37:36 +03:00
return add_generic ( cluster_id , object_id , att ) ;
2012-03-01 20:14:52 +04:00
}
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerClusterDatastore : public RequestManagerCluster
{
public :
RequestManagerClusterDatastore (
2020-07-02 23:42:10 +03:00
const std : : string & method_name ,
const std : : string & help ,
const std : : string & params ) :
2012-03-01 20:14:52 +04:00
RequestManagerCluster ( method_name , help , params ) { } ;
~ RequestManagerClusterDatastore ( ) { } ;
2012-02-28 15:17:33 +04:00
2020-09-10 10:08:29 +03:00
int add_object (
2012-12-17 19:54:17 +04:00
Cluster * cluster ,
int id ,
2020-07-02 23:42:10 +03:00
std : : string & error_msg ) override
2012-02-28 15:17:33 +04:00
{
2019-02-13 19:44:02 +03:00
return clpool - > add_to_cluster ( PoolObjectSQL : : DATASTORE , cluster , id , error_msg ) ;
2020-09-10 10:08:29 +03:00
}
2012-02-28 15:17:33 +04:00
2020-09-10 10:08:29 +03:00
int del_object ( Cluster * cluster , int id , std : : string & error_msg ) override
2012-02-28 15:17:33 +04:00
{
2019-02-13 19:44:02 +03:00
return clpool - > del_from_cluster ( PoolObjectSQL : : DATASTORE , cluster , id , error_msg ) ;
2020-09-10 10:08:29 +03:00
}
2012-02-28 15:17:33 +04:00
2020-09-10 10:08:29 +03:00
void get ( int oid , std : : unique_ptr < PoolObjectSQL > & object ,
Clusterable * * cluster_obj ) override
2012-02-28 15:17:33 +04:00
{
2020-09-10 10:08:29 +03:00
auto ds = dspool - > get ( oid ) ;
2012-02-28 15:17:33 +04:00
2020-09-10 10:08:29 +03:00
* cluster_obj = static_cast < Clusterable * > ( ds . get ( ) ) ;
object = std : : move ( ds ) ;
}
2012-02-28 15:17:33 +04:00
} ;
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 ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerClusterDatastore ( " one.cluster.adddatastore " ,
2012-03-01 20:14:52 +04:00
" 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 ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override
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 ,
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 ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerClusterDatastore ( " one.cluster.deldatastore " ,
2012-03-01 20:14:52 +04:00
" Deletes a datastore from its cluster " ,
" A:sii " ) { } ;
~ ClusterDelDatastore ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & paramList ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override
2012-02-29 21:09:47 +04:00
{
2016-03-10 18:28:33 +03:00
int cluster_id = xmlrpc_c : : value_int ( paramList . getInt ( 1 ) ) ;
2012-03-01 20:14:52 +04:00
int object_id = xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
2016-03-10 18:28:33 +03:00
return del_generic ( cluster_id , object_id , att ,
2012-03-01 20:14:52 +04:00
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 (
2020-07-02 23:42:10 +03:00
const std : : string & method_name ,
const std : : string & help ,
const std : : string & params ) :
2012-03-01 20:14:52 +04:00
RequestManagerCluster ( method_name , help , params ) { } ;
~ RequestManagerClusterVNet ( ) { } ;
2012-02-29 21:09:47 +04:00
2020-09-10 10:08:29 +03:00
int add_object (
2012-12-17 19:54:17 +04:00
Cluster * cluster ,
int id ,
2020-07-02 23:42:10 +03:00
std : : string & error_msg ) override
2012-02-29 21:09:47 +04:00
{
2019-02-13 19:44:02 +03:00
return clpool - > add_to_cluster ( PoolObjectSQL : : NET , cluster , id , error_msg ) ;
2020-09-10 10:08:29 +03:00
}
2012-02-29 21:09:47 +04:00
2020-09-10 10:08:29 +03:00
int del_object ( Cluster * cluster , int id , std : : string & error_msg ) override
2012-02-29 21:09:47 +04:00
{
2019-02-13 19:44:02 +03:00
return clpool - > del_from_cluster ( PoolObjectSQL : : NET , cluster , id , error_msg ) ;
2020-09-10 10:08:29 +03:00
}
2012-02-29 21:09:47 +04:00
2020-09-10 10:08:29 +03:00
void get ( int oid , std : : unique_ptr < PoolObjectSQL > & object ,
Clusterable * * cluster_obj ) override
2012-02-29 21:09:47 +04:00
{
2020-09-10 10:08:29 +03:00
auto vnet = vnpool - > get ( oid ) ;
2012-02-29 21:09:47 +04:00
2020-09-10 10:08:29 +03:00
* cluster_obj = static_cast < Clusterable * > ( vnet . get ( ) ) ;
object = std : : move ( vnet ) ;
}
2012-02-29 21:09:47 +04:00
} ;
2012-03-01 20:14:52 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterAddVNet : public RequestManagerClusterVNet
{
public :
ClusterAddVNet ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerClusterVNet ( " one.cluster.addvnet " ,
2012-03-01 20:14:52 +04:00
" Adds a virtual network to the cluster " ,
" A:sii " ) { } ;
~ ClusterAddVNet ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & paramList ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override
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 ,
vnpool , PoolObjectSQL : : NET ) ;
}
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterDelVNet : public RequestManagerClusterVNet
{
public :
ClusterDelVNet ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerClusterVNet ( " one.cluster.delvnet " ,
2012-03-01 20:14:52 +04:00
" Deletes a virtual network from its cluster " ,
" A:sii " ) { } ;
~ ClusterDelVNet ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & paramList ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override
2012-03-01 20:14:52 +04:00
{
2016-03-10 18:28:33 +03:00
int cluster_id = xmlrpc_c : : value_int ( paramList . getInt ( 1 ) ) ;
2012-03-01 20:14:52 +04:00
int object_id = xmlrpc_c : : value_int ( paramList . getInt ( 2 ) ) ;
2016-03-10 18:28:33 +03:00
return del_generic ( cluster_id , object_id , att ,
2012-03-01 20:14:52 +04:00
vnpool , PoolObjectSQL : : NET ) ;
}
} ;
2012-02-24 21:55:21 +04:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
# endif