2012-06-08 18:00:16 +04:00
/* -------------------------------------------------------------------------- */
2014-01-09 14:51:20 +04:00
/* Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs */
2012-06-08 18:00:16 +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_CLONE_H
# define REQUEST_MANAGER_CLONE_H
# include "Request.h"
# include "Nebula.h"
using namespace std ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class RequestManagerClone : public Request
{
protected :
RequestManagerClone ( const string & method_name ,
const string & help ,
2012-06-22 14:17:50 +04:00
const string & params = " A:sis " )
2012-06-08 18:00:16 +04:00
: Request ( method_name , params , help )
{ } ;
~ RequestManagerClone ( ) { } ;
/* -------------------------------------------------------------------- */
virtual void request_execute ( xmlrpc_c : : paramList const & _paramList ,
RequestAttributes & att ) ;
virtual Template * clone_template ( PoolObjectSQL * obj ) = 0 ;
virtual int pool_allocate (
2012-06-22 14:17:50 +04:00
int source_id ,
2012-06-08 18:00:16 +04:00
Template * tmpl ,
int & id ,
string & error_str ,
2014-05-27 14:58:46 +04:00
RequestAttributes & att ) = 0 ;
2012-06-08 18:00:16 +04:00
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VMTemplateClone : public RequestManagerClone
{
public :
VMTemplateClone ( ) :
RequestManagerClone ( " VMTemplateClone " ,
2012-06-22 14:17:50 +04:00
" Clone an existing virtual machine template " )
2012-06-08 18:00:16 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_tpool ( ) ;
auth_object = PoolObjectSQL : : TEMPLATE ;
auth_op = AuthRequest : : USE ;
} ;
~ VMTemplateClone ( ) { } ;
/* -------------------------------------------------------------------- */
Template * clone_template ( PoolObjectSQL * obj )
{
return static_cast < VMTemplate * > ( obj ) - > clone_template ( ) ;
} ;
int pool_allocate (
2012-06-22 14:17:50 +04:00
int source_id ,
2012-06-08 18:00:16 +04:00
Template * tmpl ,
int & id ,
string & error_str ,
2014-05-27 14:58:46 +04:00
RequestAttributes & att )
2012-06-08 18:00:16 +04:00
{
VMTemplatePool * tpool = static_cast < VMTemplatePool * > ( pool ) ;
VirtualMachineTemplate * ttmpl =
static_cast < VirtualMachineTemplate * > ( tmpl ) ;
2014-05-27 14:58:46 +04:00
return tpool - > allocate ( att . uid , att . gid , att . uname , att . gname , att . umask ,
2013-01-18 21:34:51 +04:00
ttmpl , & id , error_str ) ;
2012-06-08 18:00:16 +04:00
} ;
} ;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class DocumentClone : public RequestManagerClone
{
public :
DocumentClone ( ) :
RequestManagerClone ( " DocumentClone " ,
2012-06-22 14:17:50 +04:00
" Clone an existing generic document " )
2012-06-08 18:00:16 +04:00
{
Nebula & nd = Nebula : : instance ( ) ;
pool = nd . get_docpool ( ) ;
auth_object = PoolObjectSQL : : DOCUMENT ;
auth_op = AuthRequest : : USE ;
} ;
~ DocumentClone ( ) { } ;
/* -------------------------------------------------------------------- */
Template * clone_template ( PoolObjectSQL * obj )
{
return static_cast < Document * > ( obj ) - > clone_template ( ) ;
} ;
int pool_allocate (
2012-06-22 14:17:50 +04:00
int source_id ,
2012-06-08 18:00:16 +04:00
Template * tmpl ,
int & id ,
string & error_str ,
2014-05-27 14:58:46 +04:00
RequestAttributes & att )
2012-06-08 18:00:16 +04:00
{
DocumentPool * docpool = static_cast < DocumentPool * > ( pool ) ;
2012-06-22 14:17:50 +04:00
Document * doc = docpool - > get ( source_id , true ) ;
2012-06-08 18:00:16 +04:00
2014-05-27 14:58:46 +04:00
return docpool - > allocate ( att . uid , att . gid , att . uname , att . gname ,
att . umask , doc - > get_document_type ( ) , tmpl , & id , error_str ) ;
2012-06-08 18:00:16 +04:00
} ;
} ;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
# endif