2011-05-29 02:37:59 +04:00
/* -------------------------------------------------------------------------- */
2022-04-07 20:49:58 +03:00
/* Copyright 2002-2022, OpenNebula Project, OpenNebula Systems */
2011-05-29 02:37:59 +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_VIRTUAL_NETWORK_H
# define REQUEST_MANAGER_VIRTUAL_NETWORK_H
# include "Request.h"
# include "Nebula.h"
2019-12-10 13:45:15 +03:00
# include "VirtualNetworkPool.h"
2011-05-29 02:37:59 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerVirtualNetwork : public Request
{
protected :
2020-07-02 23:42:10 +03:00
RequestManagerVirtualNetwork ( const std : : string & method_name ,
const std : : string & help )
2011-05-29 02:37:59 +04:00
: Request ( method_name , " A:sis " , help )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vnpool ( ) ;
2012-01-03 05:58:23 +04:00
auth_object = PoolObjectSQL : : NET ;
2011-05-29 02:37:59 +04:00
auth_op = AuthRequest : : MANAGE ;
} ;
~ RequestManagerVirtualNetwork ( ) { } ;
/* -------------------------------------------------------------------- */
2011-07-07 14:45:13 +04:00
void request_execute ( xmlrpc_c : : paramList const & _paramList ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override ;
2011-05-29 02:37:59 +04:00
virtual int leases_action ( VirtualNetwork * vn ,
VirtualNetworkTemplate * tmpl ,
2014-05-27 19:19:36 +04:00
RequestAttributes & att ,
2020-07-02 23:42:10 +03:00
std : : string & error_str ) = 0 ;
2011-05-29 02:37:59 +04:00
/* -------------------------------------------------------------------- */
2020-07-02 23:42:10 +03:00
std : : string leases_error ( const std : : string & error ) ;
2011-05-29 02:37:59 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2014-05-22 22:20:33 +04:00
class VirtualNetworkAddAddressRange : public RequestManagerVirtualNetwork
2011-05-29 02:37:59 +04:00
{
public :
2014-05-22 22:20:33 +04:00
VirtualNetworkAddAddressRange ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerVirtualNetwork ( " one.vn.add_ar " ,
2014-05-30 18:22:26 +04:00
" Adds address ranges to a virtual network " )
{
auth_op = AuthRequest : : ADMIN ;
} ;
2014-05-22 22:20:33 +04:00
~ VirtualNetworkAddAddressRange ( ) { } ;
2011-05-29 02:37:59 +04:00
int leases_action ( VirtualNetwork * vn ,
VirtualNetworkTemplate * tmpl ,
2014-05-27 19:19:36 +04:00
RequestAttributes & att ,
2020-07-02 23:42:10 +03:00
std : : string & error_str ) override
2011-05-29 02:37:59 +04:00
{
2014-05-22 22:20:33 +04:00
return vn - > add_ar ( tmpl , error_str ) ;
2011-05-29 02:37:59 +04:00
}
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2014-05-22 22:20:33 +04:00
class VirtualNetworkRmAddressRange : public Request
2011-05-29 02:37:59 +04:00
{
public :
2017-05-07 22:52:34 +03:00
2014-06-02 03:39:22 +04:00
VirtualNetworkRmAddressRange (
2020-07-02 23:42:10 +03:00
const std : : string & name = " one.vn.rm_ar " ,
const std : : string & sign = " A:sii " ,
const std : : string & help = " Removes an address range from a virtual network " )
2014-06-02 03:39:22 +04:00
: Request ( name , sign , help )
2011-05-29 02:37:59 +04:00
{
2014-05-22 22:20:33 +04:00
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vnpool ( ) ;
auth_object = PoolObjectSQL : : NET ;
2014-05-30 18:22:26 +04:00
auth_op = AuthRequest : : ADMIN ;
2014-05-22 22:20:33 +04:00
} ;
2019-07-05 18:23:21 +03:00
~ VirtualNetworkRmAddressRange ( ) { } ;
2014-05-22 22:20:33 +04:00
void request_execute ( xmlrpc_c : : paramList const & _paramList ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override ;
2011-05-29 02:37:59 +04:00
} ;
2011-11-29 19:12:00 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2014-06-02 03:39:22 +04:00
class VirtualNetworkFreeAddressRange : public VirtualNetworkRmAddressRange
{
public :
VirtualNetworkFreeAddressRange ( ) : VirtualNetworkRmAddressRange (
2017-05-07 22:52:34 +03:00
" one.vn.free_ar " ,
2014-06-02 03:39:22 +04:00
" A:sii " ,
" Frees a reserved address range from a virtual network " )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vnpool ( ) ;
auth_object = PoolObjectSQL : : NET ;
auth_op = AuthRequest : : MANAGE ;
} ;
~ VirtualNetworkFreeAddressRange ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & _paramList ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override
2014-06-02 03:39:22 +04:00
{
VirtualNetworkRmAddressRange : : request_execute ( _paramList , att ) ;
}
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2014-05-23 02:24:14 +04:00
class VirtualNetworkUpdateAddressRange : public RequestManagerVirtualNetwork
{
public :
VirtualNetworkUpdateAddressRange ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerVirtualNetwork ( " one.vn.update_ar " ,
2014-05-30 18:22:26 +04:00
" Updates address ranges to a virtual network " )
{
2014-09-04 15:38:11 +04:00
auth_op = AuthRequest : : MANAGE ;
2014-05-30 18:22:26 +04:00
} ;
2014-05-23 02:24:14 +04:00
~ VirtualNetworkUpdateAddressRange ( ) { } ;
int leases_action ( VirtualNetwork * vn ,
VirtualNetworkTemplate * tmpl ,
2014-05-27 19:19:36 +04:00
RequestAttributes & att ,
2020-07-02 23:42:10 +03:00
std : : string & error_str ) override
2014-05-23 02:24:14 +04:00
{
2018-05-23 15:42:57 +03:00
if ( ! att . is_admin ( ) )
2014-09-04 15:38:11 +04:00
{
return vn - > update_ar ( tmpl , true , error_str ) ;
}
else
{
return vn - > update_ar ( tmpl , false , error_str ) ;
}
2014-05-23 02:24:14 +04:00
} ;
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2011-11-29 19:12:00 +04:00
class VirtualNetworkHold : public RequestManagerVirtualNetwork
{
public :
VirtualNetworkHold ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerVirtualNetwork ( " one.vn.hold " ,
2011-11-29 19:12:00 +04:00
" Holds a virtual network Lease as used " ) { } ;
~ VirtualNetworkHold ( ) { } ;
int leases_action ( VirtualNetwork * vn ,
VirtualNetworkTemplate * tmpl ,
2014-05-27 19:19:36 +04:00
RequestAttributes & att ,
2020-07-02 23:42:10 +03:00
std : : string & error_str ) override
2011-11-29 19:12:00 +04:00
{
return vn - > hold_leases ( tmpl , error_str ) ;
}
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualNetworkRelease : public RequestManagerVirtualNetwork
{
public :
VirtualNetworkRelease ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerVirtualNetwork ( " one.vn.release " ,
2011-11-29 19:12:00 +04:00
" Releases a virtual network Lease on hold " ) { } ;
~ VirtualNetworkRelease ( ) { } ;
int leases_action ( VirtualNetwork * vn ,
VirtualNetworkTemplate * tmpl ,
2014-05-27 19:19:36 +04:00
RequestAttributes & att ,
2020-07-02 23:42:10 +03:00
std : : string & error_str ) override
2011-11-29 19:12:00 +04:00
{
return vn - > free_leases ( tmpl , error_str ) ;
}
} ;
2014-05-27 19:19:36 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualNetworkReserve : public Request
{
public :
2017-05-07 22:52:34 +03:00
VirtualNetworkReserve ( ) : Request ( " one.vn.reserve " , " A:sis " ,
2014-05-27 19:19:36 +04:00
" Reserve network addresses " )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vnpool ( ) ;
auth_object = PoolObjectSQL : : NET ;
auth_op = AuthRequest : : USE ;
} ;
~ VirtualNetworkReserve ( ) { } ;
void request_execute ( xmlrpc_c : : paramList const & _paramList ,
2019-07-05 18:23:21 +03:00
RequestAttributes & att ) override ;
2014-05-27 19:19:36 +04:00
} ;
2011-05-29 02:37:59 +04:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
# endif