2012-02-09 20:56:47 +04:00
/* -------------------------------------------------------------------------- */
2018-01-02 20:27:37 +03:00
/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */
2012-02-09 20:56:47 +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 DATASTORE_POOL_H_
# define DATASTORE_POOL_H_
# include "Datastore.h"
# include "SqlDB.h"
using namespace std ;
class DatastorePool : public PoolSQL
{
public :
2016-02-04 15:10:42 +03:00
DatastorePool ( SqlDB * db , const vector < const SingleAttribute * > & _inherit_attrs ) ;
2012-02-09 20:56:47 +04:00
~ DatastorePool ( ) { } ;
/* ---------------------------------------------------------------------- */
/* Constants for DB management */
/* ---------------------------------------------------------------------- */
2012-02-15 20:17:32 +04:00
/**
2012-02-22 15:19:47 +04:00
* Name for the system datastore
2012-02-15 20:17:32 +04:00
*/
static const string SYSTEM_DS_NAME ;
/**
2012-02-22 15:19:47 +04:00
* Identifier for the system datastore
2012-02-15 20:17:32 +04:00
*/
static const int SYSTEM_DS_ID ;
2012-02-22 15:19:47 +04:00
/**
* Name for the default datastore
*/
static const string DEFAULT_DS_NAME ;
/**
* Identifier for the default datastore
*/
static const int DEFAULT_DS_ID ;
2012-11-18 03:47:48 +04:00
/**
* Name for the file datastore
*/
static const string FILE_DS_NAME ;
/**
* Identifier for the file datastore
*/
static const int FILE_DS_ID ;
2012-02-09 20:56:47 +04:00
/* ---------------------------------------------------------------------- */
/* Methods for DB management */
/* ---------------------------------------------------------------------- */
/**
* Allocates a new Datastore , writing it in the pool database . No memory is
* allocated for the object .
2012-03-01 21:50:17 +04:00
* @ param uid the user id of the Datastore owner
* @ param gid the id of the group this object is assigned to
* @ param uname name of the user
* @ param gname name of the group
2013-01-18 21:34:51 +04:00
* @ param umask permissions umask
2012-02-16 22:37:08 +04:00
* @ param ds_template Datastore definition template
2012-02-09 20:56:47 +04:00
* @ param oid the id assigned to the Datastore
2016-03-10 18:28:33 +03:00
* @ param cluster_ids the ids of the clusters this Datastore will belong to
2012-02-09 20:56:47 +04:00
* @ param error_str Returns the error reason , if any
*
* @ return the oid assigned to the object , - 1 in case of failure
*/
2012-03-01 21:50:17 +04:00
int allocate (
int uid ,
int gid ,
const string & uname ,
const string & gname ,
2013-01-18 21:34:51 +04:00
int umask ,
2012-03-01 21:50:17 +04:00
DatastoreTemplate * ds_template ,
int * oid ,
2016-03-10 18:28:33 +03:00
const set < int > & cluster_ids ,
2012-03-01 21:50:17 +04:00
string & error_str ) ;
2012-02-09 20:56:47 +04:00
/**
* Function to get a Datastore from the pool , if the object is not in memory
* it is loaded from the DB
* @ param oid Datastore unique id
* @ param lock locks the Datastore mutex
* @ return a pointer to the Datastore , 0 if the Datastore could not be loaded
*/
2018-03-18 01:31:52 +03:00
Datastore * get ( int oid )
2012-02-09 20:56:47 +04:00
{
2018-03-18 01:31:52 +03:00
return static_cast < Datastore * > ( PoolSQL : : get ( oid ) ) ;
2012-02-09 20:56:47 +04:00
} ;
/**
* Drops the Datastore data in the data base . The object mutex SHOULD be
* locked .
* @ param objsql a pointer to the Datastore object
* @ param error_msg Error reason , if any
* @ return 0 on success , - 1 DB error
* - 3 Datastore ' s Image IDs set is not empty
*/
int drop ( PoolObjectSQL * objsql , string & error_msg ) ;
/**
* Bootstraps the database table ( s ) associated to the Datastore pool
* @ return 0 on success
*/
static int bootstrap ( SqlDB * _db )
{
return Datastore : : bootstrap ( _db ) ;
} ;
/**
* Dumps the Datastore pool in XML format . A filter can be also added to the
* query
* @ param oss the output stream to dump the pool contents
* @ param where filter for the objects , defaults to all
2014-01-13 19:30:43 +04:00
* @ param limit parameters used for pagination
2018-07-24 12:41:41 +03:00
* @ param desc descending order of pool elements
2012-02-09 20:56:47 +04:00
*
* @ return 0 on success
*/
2018-07-24 12:41:41 +03:00
int dump ( ostringstream & oss , const string & where , const string & limit ,
bool desc )
2012-02-09 20:56:47 +04:00
{
2014-01-13 19:30:43 +04:00
return PoolSQL : : dump ( oss , " DATASTORE_POOL " , Datastore : : table , where ,
2018-07-24 12:41:41 +03:00
limit , desc ) ;
2012-02-09 20:56:47 +04:00
} ;
2013-06-27 03:11:41 +04:00
/**
* Lists the Datastore ids
* @ param oids a vector with the oids of the objects .
*
* @ return 0 on success
*/
int list ( vector < int > & oids )
{
return PoolSQL : : list ( oids , Datastore : : table ) ;
}
2015-10-28 20:05:53 +03:00
/**
* Adds to the disk the datastore inherit attributes and conf values
* @ param ds_id of the datastore to use
* @ para disk vector attribute for the disk
*
* @ return - 1 if the DS does not exists
*/
2016-12-11 23:05:07 +03:00
int disk_attribute ( int ds_id , VirtualMachineDisk * disk ) ;
2015-10-28 20:05:53 +03:00
2012-02-09 20:56:47 +04:00
private :
2015-10-28 20:05:53 +03:00
/**
* Datastore attributes to be inherited into the VM disk
*/
vector < string > inherit_attrs ;
2012-02-09 20:56:47 +04:00
/**
* Factory method to produce objects
* @ return a pointer to the new object
*/
PoolObjectSQL * create ( )
{
2016-03-10 18:28:33 +03:00
set < int > empty ;
return new Datastore ( - 1 , - 1 , " " , " " , 0 , 0 , empty ) ;
2012-02-09 20:56:47 +04:00
} ;
} ;
# endif /*DATASTORE_POOL_H_*/