2012-12-07 21:32:38 +04:00
/* -------------------------------------------------------------------------- */
2019-01-16 13:27:59 +03:00
/* Copyright 2002-2019, 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"
using namespace std ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerRename : public Request
{
protected :
RequestManagerRename ( const string & method_name ,
const string & help ,
const string & params = " A:sis " )
: Request ( method_name , params , help )
{
2013-09-04 20:43:23 +04:00
pthread_mutex_init ( & mutex , 0 ) ;
2012-12-07 21:32:38 +04:00
auth_op = AuthRequest : : MANAGE ;
} ;
2019-07-05 18:23:21 +03:00
~ RequestManagerRename ( ) { } ;
2012-12-07 21:32:38 +04:00
/* -------------------------------------------------------------------- */
void request_execute ( xmlrpc_c : : paramList const & _paramList ,
2019-07-05 18:23:21 +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
*/
2018-03-18 01:31:52 +03:00
virtual int exist ( const string & name , int uid ) = 0 ;
2013-09-04 20:43:23 +04:00
/**
* Batch rename of related objects . Default implementation does nothing
*/
virtual void batch_rename ( int oid ) { } ;
/**
* 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 )
{
pair < set < int > : : iterator , bool > rc ;
pthread_mutex_lock ( & mutex ) ;
rc = rename_ids . insert ( oid ) ;
pthread_mutex_unlock ( & mutex ) ;
return rc . second = = true ;
}
/**
* Clear the rename .
*/
void clear_rename ( int oid )
{
pthread_mutex_lock ( & mutex ) ;
rename_ids . erase ( oid ) ;
pthread_mutex_unlock ( & mutex ) ;
}
2019-06-12 18:20:50 +03:00
/**
* Method por updating custom values not included in PoolSQL : : update
* mainly used for updating search information in the VMs .
* @ param object to be updated
* @ return 0 on success
*/
virtual int extra_updates ( PoolObjectSQL * obj )
{
return 0 ;
} ;
2013-09-04 20:43:23 +04:00
private :
/**
* Mutex to control concurrent access to the ongoing rename operations
*/
pthread_mutex_t mutex ;
/**
* Set of IDs being renamed ;
*/
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 ( ) :
2017-05-07 22:52:34 +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
2019-07-05 18:23:21 +03:00
int exist ( const string & name , int uid ) override
2018-03-18 01:31:52 +03:00
{
return - 1 ;
}
2019-06-12 18:20:50 +03:00
2019-07-05 18:23:21 +03:00
int extra_updates ( PoolObjectSQL * obj ) override
2019-06-12 18:20:50 +03:00
{
VirtualMachine * vm ;
VirtualMachinePool * vmpool = static_cast < VirtualMachinePool * > ( pool ) ;
if ( obj = = 0 )
{
return - 1 ;
}
vm = static_cast < VirtualMachine * > ( obj ) ;
return vmpool - > update_search ( vm ) ;
2019-09-09 14:13:52 +03:00
}
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 ;
} ;
~ TemplateRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ VirtualNetworkTemplateRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ( ) :
2017-05-07 22:52:34 +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 ;
} ;
~ VirtualNetworkRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ ImageRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ DocumentRename ( ) { } ;
2018-03-18 01:31:52 +03:00
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ ClusterRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ DatastoreRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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
} ;
~ HostRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ ZoneRename ( ) { } ;
2018-03-18 01:31:52 +03:00
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ SecurityGroupRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ VdcRename ( ) { } ;
2018-03-18 01:31:52 +03:00
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ VirtualRouterRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ MarketPlaceRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ MarketPlaceAppRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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 ;
} ;
~ VMGroupRename ( ) { } ;
2019-07-05 18:23:21 +03:00
int exist ( const 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
} ;
2012-12-07 21:32:38 +04:00
# endif