2012-12-07 21:32:38 +04:00
/* -------------------------------------------------------------------------- */
2024-07-29 15:25:20 +03:00
/* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems */
2012-12-07 21:32:38 +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_RENAME_H_
# define REQUEST_MANAGER_RENAME_H_
# include "Request.h"
# include "Nebula.h"
2023-07-03 19:15:52 +03:00
# include "BackupJobPool.h"
2019-12-10 13:45:15 +03:00
# include "ClusterPool.h"
# include "DatastorePool.h"
# include "DocumentPool.h"
# include "HookPool.h"
# include "HostPool.h"
# include "ImagePool.h"
# include "MarketPlacePool.h"
# include "MarketPlaceAppPool.h"
# include "SecurityGroupPool.h"
# include "VdcPool.h"
# include "VirtualMachinePool.h"
# include "VirtualNetworkPool.h"
# include "VirtualRouterPool.h"
# include "VMGroupPool.h"
# include "VMTemplatePool.h"
# include "VNTemplatePool.h"
# include "ZonePool.h"
2012-12-07 21:32:38 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerRename : public Request
{
protected :
2020-07-02 23:42:10 +03:00
RequestManagerRename ( const std : : string & method_name ,
const std : : string & help ,
const std : : string & params = " A:sis " )
2024-06-03 12:40:24 +03:00
: Request ( method_name , params , help )
2012-12-07 21:32:38 +04:00
{
auth_op = AuthRequest : : MANAGE ;
2020-09-10 14:32:52 +03:00
}
2012-12-07 21:32:38 +04:00
2019-12-10 13:45:15 +03:00
~ RequestManagerRename ( ) = default ;
2012-12-07 21:32:38 +04:00
/* -------------------------------------------------------------------- */
void request_execute ( xmlrpc_c : : paramList const & _paramList ,
2024-06-03 12:40:24 +03:00
RequestAttributes & att ) override ;
2012-12-07 21:32:38 +04:00
2013-09-04 20:43:23 +04:00
/**
* Gets and object by name and owner . Default implementation returns no
* object
*/
2020-07-02 23:42:10 +03:00
virtual int exist ( const std : : string & name , int uid ) = 0 ;
2013-09-04 20:43:23 +04:00
/**
* Batch rename of related objects . Default implementation does nothing
*/
2024-06-03 12:40:24 +03:00
virtual void batch_rename ( int oid ) { } ;
2013-09-04 20:43:23 +04:00
/**
* Test if a rename is being perform on a given object . If not it set it .
* @ return true if the rename can be performed ( no ongoing rename )
*/
bool test_and_set_rename ( int oid )
{
2020-09-10 14:32:52 +03:00
std : : lock_guard < std : : mutex > lock ( _mutex ) ;
2013-09-04 20:43:23 +04:00
2020-09-10 14:32:52 +03:00
auto rc = rename_ids . insert ( oid ) ;
2013-09-04 20:43:23 +04:00
return rc . second = = true ;
}
/**
* Clear the rename .
*/
void clear_rename ( int oid )
{
2020-09-10 14:32:52 +03:00
std : : lock_guard < std : : mutex > lock ( _mutex ) ;
2013-09-04 20:43:23 +04:00
rename_ids . erase ( oid ) ;
}
private :
/**
* Mutex to control concurrent access to the ongoing rename operations
*/
2020-09-10 14:32:52 +03:00
std : : mutex _mutex ;
2013-09-04 20:43:23 +04:00
/**
* Set of IDs being renamed ;
*/
2020-07-02 23:42:10 +03:00
std : : set < int > rename_ids ;
2013-09-02 14:53:54 +04:00
2012-12-07 21:32:38 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualMachineRename : public RequestManagerRename
{
public :
VirtualMachineRename ( ) :
2024-06-03 12:40:24 +03:00
RequestManagerRename ( " one.vm.rename " , " Renames a virtual machine " )
2012-12-15 07:19:52 +04:00
{
2012-12-07 21:32:38 +04:00
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vmpool ( ) ;
auth_object = PoolObjectSQL : : VM ;
2019-09-09 14:13:52 +03:00
vm_action = VMActions : : RENAME_ACTION ;
}
2017-01-30 15:46:05 +03:00
2019-09-09 14:13:52 +03:00
~ VirtualMachineRename ( ) = default ;
2018-03-18 01:31:52 +03:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2018-03-18 01:31:52 +03:00
{
return - 1 ;
}
2012-12-07 21:32:38 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class TemplateRename : public RequestManagerRename
{
public :
TemplateRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.template.rename " ,
2012-12-15 07:19:52 +04:00
" Renames a virtual machine template " )
2012-12-07 21:32:38 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_tpool ( ) ;
auth_object = PoolObjectSQL : : TEMPLATE ;
} ;
2019-12-10 13:45:15 +03:00
~ TemplateRename ( ) = default ;
2012-12-07 21:32:38 +04:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2012-12-07 21:32:38 +04:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name , uid ) ;
}
2012-12-07 21:32:38 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2018-11-20 19:24:59 +03:00
class VirtualNetworkTemplateRename : public RequestManagerRename
{
public :
VirtualNetworkTemplateRename ( ) :
RequestManagerRename ( " one.vntemplate.rename " ,
" Renames a virtual network template " )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vntpool ( ) ;
auth_object = PoolObjectSQL : : VNTEMPLATE ;
} ;
2019-12-10 13:45:15 +03:00
~ VirtualNetworkTemplateRename ( ) = default ;
2018-11-20 19:24:59 +03:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2018-11-20 19:24:59 +03:00
{
return pool - > exist ( name , uid ) ;
}
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
2012-12-07 21:32:38 +04:00
class VirtualNetworkRename : public RequestManagerRename
{
public :
VirtualNetworkRename ( ) :
2024-06-03 12:40:24 +03:00
RequestManagerRename ( " one.vn.rename " , " Renames a virtual network " )
2012-12-15 07:19:52 +04:00
{
2012-12-07 21:32:38 +04:00
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vnpool ( ) ;
auth_object = PoolObjectSQL : : NET ;
} ;
2019-12-10 13:45:15 +03:00
~ VirtualNetworkRename ( ) = default ;
2012-12-07 21:32:38 +04:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2012-12-07 21:32:38 +04:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name , uid ) ;
}
2012-12-07 21:32:38 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ImageRename : public RequestManagerRename
{
public :
ImageRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.image.rename " , " Renames an image " )
2012-12-15 07:19:52 +04:00
{
2012-12-07 21:32:38 +04:00
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_ipool ( ) ;
auth_object = PoolObjectSQL : : IMAGE ;
} ;
2019-12-10 13:45:15 +03:00
~ ImageRename ( ) = default ;
2012-12-07 21:32:38 +04:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2012-12-07 21:32:38 +04:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name , uid ) ;
}
2012-12-07 21:32:38 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class DocumentRename : public RequestManagerRename
{
public :
DocumentRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.document.rename " , " Renames a generic document " )
2012-12-07 21:32:38 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_docpool ( ) ;
auth_object = PoolObjectSQL : : DOCUMENT ;
} ;
2019-12-10 13:45:15 +03:00
~ DocumentRename ( ) = default ;
2018-03-18 01:31:52 +03:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2018-03-18 01:31:52 +03:00
{
return - 1 ;
}
2012-12-07 21:32:38 +04:00
} ;
2013-09-02 14:53:54 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ClusterRename : public RequestManagerRename
{
public :
ClusterRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.cluster.rename " , " Renames a cluster " )
2013-09-02 14:53:54 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_clpool ( ) ;
auth_object = PoolObjectSQL : : CLUSTER ;
} ;
2019-12-10 13:45:15 +03:00
~ ClusterRename ( ) = default ;
2013-09-02 14:53:54 +04:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2013-09-02 14:53:54 +04:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name ) ;
}
2013-09-02 14:53:54 +04:00
2019-07-05 18:23:21 +03:00
void batch_rename ( int oid ) override ;
2013-09-02 14:53:54 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class DatastoreRename : public RequestManagerRename
{
public :
DatastoreRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.datastore.rename " , " Renames a datastore " )
2013-09-02 14:53:54 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_dspool ( ) ;
auth_object = PoolObjectSQL : : DATASTORE ;
} ;
2019-12-10 13:45:15 +03:00
~ DatastoreRename ( ) = default ;
2013-09-02 14:53:54 +04:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2013-09-02 14:53:54 +04:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name ) ;
}
2013-09-02 14:53:54 +04:00
2019-07-05 18:23:21 +03:00
void batch_rename ( int oid ) override ;
2013-09-02 14:53:54 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class HostRename : public RequestManagerRename
{
public :
HostRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.host.rename " , " Renames a host " )
2013-09-02 14:53:54 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_hpool ( ) ;
auth_object = PoolObjectSQL : : HOST ;
2013-11-23 21:56:41 +04:00
auth_op = AuthRequest : : ADMIN ;
2013-09-02 14:53:54 +04:00
} ;
2019-12-10 13:45:15 +03:00
~ HostRename ( ) = default ;
2013-09-02 14:53:54 +04:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2013-09-02 14:53:54 +04:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name ) ;
}
2013-09-02 14:53:54 +04:00
2019-07-05 18:23:21 +03:00
void batch_rename ( int oid ) override ;
2013-09-02 14:53:54 +04:00
} ;
2014-01-28 17:47:57 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ZoneRename : public RequestManagerRename
{
public :
ZoneRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.zone.rename " , " Renames a zone " )
2014-01-28 17:47:57 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_zonepool ( ) ;
auth_object = PoolObjectSQL : : ZONE ;
} ;
2019-12-10 13:45:15 +03:00
~ ZoneRename ( ) = default ;
2018-03-18 01:31:52 +03:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2018-03-18 01:31:52 +03:00
{
return pool - > exist ( name ) ;
}
2014-01-28 17:47:57 +04:00
} ;
2014-09-08 13:50:25 +04:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class SecurityGroupRename : public RequestManagerRename
{
public :
SecurityGroupRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.secgroup.rename " , " Renames a security group " )
2014-09-08 13:50:25 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_secgrouppool ( ) ;
auth_object = PoolObjectSQL : : SECGROUP ;
} ;
2019-12-10 13:45:15 +03:00
~ SecurityGroupRename ( ) = default ;
2014-09-08 13:50:25 +04:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2014-09-08 13:50:25 +04:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name , uid ) ;
}
2014-09-08 13:50:25 +04:00
} ;
2014-12-19 19:30:00 +03:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VdcRename : public RequestManagerRename
{
public :
VdcRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.vdc.rename " , " Renames a VDC " )
2014-12-19 19:30:00 +03:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vdcpool ( ) ;
auth_object = PoolObjectSQL : : VDC ;
} ;
2019-12-10 13:45:15 +03:00
~ VdcRename ( ) = default ;
2018-03-18 01:31:52 +03:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2018-03-18 01:31:52 +03:00
{
return pool - > exist ( name ) ;
}
2014-12-19 19:30:00 +03:00
} ;
2015-11-30 18:50:23 +03:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualRouterRename : public RequestManagerRename
{
public :
VirtualRouterRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.vrouter.rename " , " Renames a virtual router " )
2015-11-30 18:50:23 +03:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vrouterpool ( ) ;
auth_object = PoolObjectSQL : : VROUTER ;
} ;
2019-12-10 13:45:15 +03:00
~ VirtualRouterRename ( ) = default ;
2015-11-30 18:50:23 +03:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2015-11-30 18:50:23 +03:00
{
2018-03-18 01:31:52 +03:00
return - 1 ;
}
2015-11-30 18:50:23 +03:00
} ;
2015-12-06 01:52:28 +03:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class MarketPlaceRename : public RequestManagerRename
{
public :
MarketPlaceRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.market.rename " , " Renames a marketplace " )
2015-12-06 01:52:28 +03:00
{
Nebula & nd = Nebula : : instance ( ) ;
2015-12-11 17:53:19 +03:00
pool = nd . get_marketpool ( ) ;
2015-12-06 01:52:28 +03:00
auth_object = PoolObjectSQL : : MARKETPLACE ;
} ;
2019-12-10 13:45:15 +03:00
~ MarketPlaceRename ( ) = default ;
2015-12-06 01:52:28 +03:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2015-12-06 01:52:28 +03:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name ) ;
}
2015-12-06 01:52:28 +03:00
2019-07-05 18:23:21 +03:00
void batch_rename ( int oid ) override ;
2015-12-06 01:52:28 +03:00
} ;
2015-12-11 17:53:19 +03:00
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class MarketPlaceAppRename : public RequestManagerRename
{
public :
MarketPlaceAppRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.marketapp.rename " , " Renames a marketplace app " )
2015-12-11 17:53:19 +03:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_apppool ( ) ;
auth_object = PoolObjectSQL : : MARKETPLACEAPP ;
} ;
2019-12-10 13:45:15 +03:00
~ MarketPlaceAppRename ( ) = default ;
2015-12-11 17:53:19 +03:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2015-12-11 17:53:19 +03:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name , uid ) ;
}
2015-12-11 17:53:19 +03:00
} ;
2012-12-07 21:32:38 +04:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
2017-01-03 23:12:27 +03:00
class VMGroupRename : public RequestManagerRename
{
public :
VMGroupRename ( ) :
2017-05-07 22:52:34 +03:00
RequestManagerRename ( " one.vmgroup.rename " , " Renames a vm group " )
2017-01-03 23:12:27 +03:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_vmgrouppool ( ) ;
auth_object = PoolObjectSQL : : VMGROUP ;
} ;
2019-12-10 13:45:15 +03:00
~ VMGroupRename ( ) = default ;
2017-01-03 23:12:27 +03:00
2020-07-02 23:42:10 +03:00
int exist ( const std : : string & name , int uid ) override
2017-01-03 23:12:27 +03:00
{
2018-03-18 01:31:52 +03:00
return pool - > exist ( name , uid ) ;
}
2017-01-03 23:12:27 +03:00
} ;
2019-09-09 15:43:51 +03:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class HookRename : public RequestManagerRename
{
public :
HookRename ( ) :
RequestManagerRename ( " one.hook.rename " , " Renames a hook " )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_hkpool ( ) ;
auth_object = PoolObjectSQL : : HOOK ;
} ;
2019-12-10 13:45:15 +03:00
~ HookRename ( ) = default ;
2019-09-09 15:43:51 +03:00
2023-02-07 10:50:30 +03:00
int exist ( const std : : string & name , int uid ) override
2019-09-09 15:43:51 +03:00
{
return pool - > exist ( name , uid ) ;
}
} ;
2023-07-03 19:15:52 +03:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class BackupJobRename : public RequestManagerRename
{
public :
BackupJobRename ( ) :
RequestManagerRename ( " one.backupjob.rename " , " Renames a Backup Job " )
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_bjpool ( ) ;
auth_object = PoolObjectSQL : : BACKUPJOB ;
}
int exist ( const std : : string & name , int uid ) override
{
return pool - > exist ( name , uid ) ;
}
} ;
2012-12-07 21:32:38 +04:00
# endif