2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2015-02-24 14:27:59 +03:00
/* Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs */
2008-06-17 20:27:32 +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 POOL_OBJECT_SQL_H_
# define POOL_OBJECT_SQL_H_
# include "ObjectSQL.h"
2011-02-24 20:12:26 +03:00
# include "ObjectXML.h"
2011-04-08 03:02:55 +04:00
# include "Template.h"
2012-01-03 00:17:20 +04:00
2008-06-17 20:27:32 +04:00
# include <pthread.h>
2011-02-24 20:12:26 +03:00
# include <string.h>
2008-06-17 20:27:32 +04:00
using namespace std ;
2012-01-03 00:17:20 +04:00
class PoolObjectAuth ;
2012-01-02 22:21:54 +04:00
2008-06-17 20:27:32 +04:00
/**
2010-04-03 18:54:54 +04:00
* PoolObject class . Provides a SQL backend interface for Pool components . Each
2008-06-17 20:27:32 +04:00
* object is identified with and unique OID
2010-04-03 18:54:54 +04:00
*
* Note : The PoolObject provides a synchronization mechanism ( mutex ) . This
2008-06-17 20:27:32 +04:00
* implementation assumes that the mutex IS LOCKED when the class destructor
2010-04-03 18:54:54 +04:00
* is called .
2008-06-17 20:27:32 +04:00
*/
2011-02-24 20:12:26 +03:00
class PoolObjectSQL : public ObjectSQL , public ObjectXML
2008-06-17 20:27:32 +04:00
{
public :
2012-01-03 05:58:23 +04:00
/* ---------------------------------------------------------------------- */
/* Class Constructors & Constants */
/* ---------------------------------------------------------------------- */
/**
* OpenNebula objects . This definitions are used by other core components
* like the AuthZ / AuthN module
*/
enum ObjectType
{
2012-02-09 20:56:47 +04:00
VM = 0x0000001000000000LL ,
HOST = 0x0000002000000000LL ,
NET = 0x0000004000000000LL ,
IMAGE = 0x0000008000000000LL ,
USER = 0x0000010000000000LL ,
TEMPLATE = 0x0000020000000000LL ,
GROUP = 0x0000040000000000LL ,
ACL = 0x0000080000000000LL ,
2012-02-24 18:53:53 +04:00
DATASTORE = 0x0000100000000000LL ,
2012-06-08 17:41:59 +04:00
CLUSTER = 0x0000200000000000LL ,
2013-12-12 22:08:59 +04:00
DOCUMENT = 0x0000400000000000LL ,
2014-09-08 13:50:25 +04:00
ZONE = 0x0000800000000000LL ,
2014-12-19 19:30:00 +03:00
SECGROUP = 0x0001000000000000LL ,
VDC = 0x0002000000000000LL
2012-01-03 05:58:23 +04:00
} ;
static string type_to_str ( ObjectType ob )
{
switch ( ob )
{
2012-02-10 17:55:29 +04:00
case VM : return " VM " ; break ;
case HOST : return " HOST " ; break ;
case NET : return " NET " ; break ;
case IMAGE : return " IMAGE " ; break ;
case USER : return " USER " ; break ;
case TEMPLATE : return " TEMPLATE " ; break ;
case GROUP : return " GROUP " ; break ;
case ACL : return " ACL " ; break ;
case DATASTORE : return " DATASTORE " ; break ;
2012-02-24 18:53:53 +04:00
case CLUSTER : return " CLUSTER " ; break ;
2012-06-08 17:41:59 +04:00
case DOCUMENT : return " DOCUMENT " ; break ;
2013-12-12 22:08:59 +04:00
case ZONE : return " ZONE " ; break ;
2014-09-08 13:50:25 +04:00
case SECGROUP : return " SECGROUP " ; break ;
2014-12-19 19:30:00 +03:00
case VDC : return " VDC " ; break ;
2012-02-10 17:55:29 +04:00
default : return " " ;
2012-01-03 05:58:23 +04:00
}
} ;
/* ---------------------------------------------------------------------- */
PoolObjectSQL ( int id ,
ObjectType _obj_type ,
const string & _name ,
int _uid ,
int _gid ,
const string & _uname ,
const string & _gname ,
const char * _table )
2011-06-30 13:31:00 +04:00
: ObjectSQL ( ) ,
ObjectXML ( ) ,
oid ( id ) ,
2012-01-03 05:58:23 +04:00
obj_type ( _obj_type ) ,
2011-06-30 13:31:00 +04:00
name ( _name ) ,
uid ( _uid ) ,
gid ( _gid ) ,
uname ( _uname ) ,
gname ( _gname ) ,
valid ( true ) ,
2011-12-29 21:14:20 +04:00
owner_u ( 1 ) ,
owner_m ( 1 ) ,
owner_a ( 0 ) ,
group_u ( 0 ) ,
group_m ( 0 ) ,
group_a ( 0 ) ,
other_u ( 0 ) ,
other_m ( 0 ) ,
other_a ( 0 ) ,
2013-01-18 02:14:34 +04:00
obj_template ( 0 ) ,
2011-06-30 13:31:00 +04:00
table ( _table )
2008-06-17 20:27:32 +04:00
{
pthread_mutex_init ( & mutex , 0 ) ;
} ;
virtual ~ PoolObjectSQL ( )
{
pthread_mutex_unlock ( & mutex ) ;
2010-04-03 18:54:54 +04:00
2008-06-17 20:27:32 +04:00
pthread_mutex_destroy ( & mutex ) ;
} ;
2010-04-03 18:54:54 +04:00
2011-03-05 00:37:21 +03:00
/* --------------------------------------------------------------------- */
2008-06-17 20:27:32 +04:00
int get_oid ( ) const
{
return oid ;
} ;
2012-01-05 04:45:53 +04:00
ObjectType get_type ( ) const
{
return obj_type ;
} ;
2013-04-10 14:56:06 +04:00
/**
* Check if the object name contains invalid characters or exceed the max .
* length . By Default these are not allowed " &|: \ ;/'#{}()$
* @ param obj_name for this object
* @ param extra_chars aditional invalid characters to test
* @ param error_str describing the error
* @ return true if the name is valid
*/
static bool name_is_valid ( const string & obj_name , const string & extra_chars ,
string & error_str ) ;
/**
* Check if the object name is valid , no extra characters needed to be
* tested .
*/
static bool name_is_valid ( const string & obj_name , string & error_str )
{
return name_is_valid ( obj_name , " " , error_str ) ;
}
2011-03-05 00:37:21 +03:00
const string & get_name ( ) const
{
return name ;
} ;
2013-04-10 17:37:07 +04:00
/**
* Set the name of the object and check if it is valid .
* @ param _name the new name
* @ param error_str describing the error if any
*
* @ return 0 if the name was changed
*/
int set_name ( const string & _name , string & error_str )
2012-12-07 21:32:38 +04:00
{
2013-04-10 17:37:07 +04:00
if ( ! name_is_valid ( _name , error_str ) )
{
return - 1 ;
}
2012-12-07 21:32:38 +04:00
name = _name ;
2013-04-10 17:37:07 +04:00
return 0 ;
2012-12-07 21:32:38 +04:00
} ;
2012-01-05 04:45:53 +04:00
int get_uid ( ) const
2011-06-03 20:26:59 +04:00
{
return uid ;
} ;
2012-01-05 04:45:53 +04:00
int get_gid ( ) const
2011-06-09 02:58:57 +04:00
{
return gid ;
} ;
2012-08-28 18:52:03 +04:00
const string & get_uname ( ) const
{
return uname ;
} ;
const string & get_gname ( ) const
{
return gname ;
} ;
2013-01-18 02:14:34 +04:00
2011-06-07 18:55:23 +04:00
/**
2011-06-30 14:09:25 +04:00
* Changes the object ' s owner
2011-06-07 18:55:23 +04:00
* @ param _uid New User ID
2011-06-30 14:09:25 +04:00
* @ param _uname Name of the new user
2011-06-07 18:55:23 +04:00
*/
2011-06-30 14:09:25 +04:00
void set_user ( int _uid , const string & _uname )
2011-05-17 21:13:59 +04:00
{
2011-06-30 14:09:25 +04:00
uid = _uid ;
uname = _uname ;
2011-05-17 21:13:59 +04:00
}
2011-06-07 18:55:23 +04:00
/**
* Changes the object ' s group id
* @ param _gid New Group ID
2011-06-30 14:09:25 +04:00
* @ param _gname Name of the new group
2011-06-07 18:55:23 +04:00
*/
2011-06-30 14:09:25 +04:00
void set_group ( int _gid , const string & _gname )
Feature #407: Add 'GID' attribute to some pool objects; change *pool.info XML-RPC flag meaning; update onedb migrator; fix tests.
* VM, VMTEMPLATE, VNET & IMAGE objects have a GID attribute, and a table column. The group id is inherited from the user creating the object, except for VMs created from Templates, that inherit the Template's group.
* The new flag meaning has been modified in src/rm sources and CLI commands for one.(vm,template,vnet,image)pool.info . It changes from
-2 all, -1 mine & public, >=0 UID
to
-3 mine, -2 all, -1 mine & group
* USER has a group, but not secondary ones. The user_pool table doesn't have a GID column, we'll deal with it later when the group-users relations are implemented.
* onedb migrator 1.rb: deleted USERNAME, and GID added.
2011-05-16 19:00:27 +04:00
{
2011-06-30 14:09:25 +04:00
gid = _gid ;
gname = _gname ;
Feature #407: Add 'GID' attribute to some pool objects; change *pool.info XML-RPC flag meaning; update onedb migrator; fix tests.
* VM, VMTEMPLATE, VNET & IMAGE objects have a GID attribute, and a table column. The group id is inherited from the user creating the object, except for VMs created from Templates, that inherit the Template's group.
* The new flag meaning has been modified in src/rm sources and CLI commands for one.(vm,template,vnet,image)pool.info . It changes from
-2 all, -1 mine & public, >=0 UID
to
-3 mine, -2 all, -1 mine & group
* USER has a group, but not secondary ones. The user_pool table doesn't have a GID column, we'll deal with it later when the group-users relations are implemented.
* onedb migrator 1.rb: deleted USERNAME, and GID added.
2011-05-16 19:00:27 +04:00
} ;
2012-01-04 23:14:09 +04:00
/**
* Changes the object ' s permissions
*
* @ param _owner_u New permission : 1 allow , 0 deny , - 1 do not change
* @ param _owner_m New permission : 1 allow , 0 deny , - 1 do not change
* @ param _owner_a New permission : 1 allow , 0 deny , - 1 do not change
* @ param _group_u New permission : 1 allow , 0 deny , - 1 do not change
* @ param _group_m New permission : 1 allow , 0 deny , - 1 do not change
* @ param _group_a New permission : 1 allow , 0 deny , - 1 do not change
* @ param _other_u New permission : 1 allow , 0 deny , - 1 do not change
* @ param _other_m New permission : 1 allow , 0 deny , - 1 do not change
* @ param _other_a New permission : 1 allow , 0 deny , - 1 do not change
* @ param error_str Returns the error reason , if any
*
* @ return 0 on success
*/
2012-01-06 04:36:57 +04:00
virtual int set_permissions ( int _owner_u ,
int _owner_m ,
int _owner_a ,
int _group_u ,
int _group_m ,
int _group_a ,
int _other_u ,
int _other_m ,
int _other_a ,
string & error_str ) ;
2012-01-04 23:14:09 +04:00
2011-03-05 00:37:21 +03:00
/* --------------------------------------------------------------------- */
2009-07-13 16:21:14 +04:00
/**
* Check if the object is valid
* @ return true if object is valid
*/
const bool & isValid ( ) const
{
return valid ;
} ;
/**
2010-04-03 18:54:54 +04:00
* Set the object valid flag
2009-07-13 16:21:14 +04:00
* @ param _valid new valid flag
*/
void set_valid ( const bool _valid )
{
valid = _valid ;
2011-02-24 20:12:26 +03:00
} ;
2009-07-13 16:21:14 +04:00
2008-06-17 20:27:32 +04:00
/**
* Function to lock the object
*/
void lock ( )
{
pthread_mutex_lock ( & mutex ) ;
} ;
/**
* Function to unlock the object
*/
void unlock ( )
{
pthread_mutex_unlock ( & mutex ) ;
} ;
2010-04-03 18:54:54 +04:00
2011-05-13 02:47:21 +04:00
/**
* Function to print the object into a string in XML format
* base64 encoded
* @ param xml the resulting XML string
* @ return a reference to the generated string
*/
virtual string & to_xml64 ( string & xml64 ) ;
2011-02-24 20:12:26 +03:00
/**
* Function to print the object into a string in XML format
* @ param xml the resulting XML string
* @ return a reference to the generated string
*/
2011-03-04 19:04:28 +03:00
virtual string & to_xml ( string & xml ) const = 0 ;
2011-02-24 20:12:26 +03:00
/**
* Rebuilds the object from an xml formatted string
* @ param xml_str The xml - formatted string
*
* @ return 0 on success , - 1 otherwise
*/
2011-03-04 19:04:28 +03:00
virtual int from_xml ( const string & xml_str ) = 0 ;
2011-02-24 20:12:26 +03:00
2011-04-08 03:02:55 +04:00
// ------------------------------------------------------------------------
// Template
// ------------------------------------------------------------------------
/**
* Gets the values of a template attribute
* @ param name of the attribute
* @ param values of the attribute
* @ return the number of values
*/
int get_template_attribute (
2011-10-11 14:47:30 +04:00
const char * name ,
2011-04-08 03:02:55 +04:00
vector < const Attribute * > & values ) const
{
return obj_template - > get ( name , values ) ;
} ;
/**
2011-10-11 14:47:30 +04:00
* Gets a string based attribute ( single )
2011-04-08 03:02:55 +04:00
* @ param name of the attribute
2011-10-11 14:47:30 +04:00
* @ param value of the attribute ( a string ) , will be " " if not defined or
* not a single attribute
2011-04-08 03:02:55 +04:00
*/
2011-10-11 14:47:30 +04:00
void get_template_attribute (
const char * name ,
string & value ) const
2011-04-08 03:02:55 +04:00
{
2011-10-11 14:47:30 +04:00
obj_template - > get ( name , value ) ;
}
2011-04-08 03:02:55 +04:00
/**
2013-08-22 17:04:25 +04:00
* Gets and removes a string based attribute ( single )
2011-04-08 03:02:55 +04:00
* @ param name of the attribute
* @ param value of the attribute ( a string ) , will be " " if not defined or
* not a single attribute
2011-10-11 14:47:30 +04:00
* @ return the number of attributes erased
2011-04-08 03:02:55 +04:00
*/
2011-10-11 14:47:30 +04:00
int erase_template_attribute (
const char * name ,
2011-10-11 17:46:58 +04:00
string & value )
2011-04-08 03:02:55 +04:00
{
2011-10-11 14:47:30 +04:00
obj_template - > get ( name , value ) ;
return obj_template - > erase ( name ) ;
2011-04-08 03:02:55 +04:00
}
2013-08-22 17:04:25 +04:00
/**
* Gets and removes a float based attribute ( single )
* @ param name of the attribute
* @ param value of the attribute ( a float ) , will be 0 if not defined or
* not a single attribute
* @ return the number of attributes erased
*/
int erase_template_attribute (
const char * name ,
float & value )
{
obj_template - > get ( name , value ) ;
return obj_template - > erase ( name ) ;
}
2013-10-22 19:12:06 +04:00
/**
* Gets and removes a long long based attribute ( single )
* @ param name of the attribute
* @ param value of the attribute ( a long long ) , will be 0 if not defined or
* not a single attribute
* @ return the number of attributes erased
*/
int erase_template_attribute (
const char * name ,
long long & value )
{
obj_template - > get ( name , value ) ;
return obj_template - > erase ( name ) ;
}
2013-10-22 19:20:23 +04:00
/**
* Gets and removes a boolean based attribute ( single )
* @ param name of the attribute
* @ param value of the attribute ( a boolean ) , will be false if not defined or
* not a single attribute
* @ return the number of attributes erased
*/
int erase_template_attribute (
const char * name ,
bool & value )
{
obj_template - > get ( name , value ) ;
return obj_template - > erase ( name ) ;
}
2011-04-08 03:02:55 +04:00
/**
* Gets an int based attribute ( single )
* @ param name of the attribute
* @ param value of the attribute ( an int ) , will be 0 if not defined or
* not a single attribute
2012-07-17 17:51:50 +04:00
*
* @ return True if the Single attribute was found and is a valid integer
* value
2011-04-08 03:02:55 +04:00
*/
2012-07-17 17:51:50 +04:00
bool get_template_attribute (
2011-04-08 03:02:55 +04:00
const char * name ,
int & value ) const
{
2012-07-17 17:51:50 +04:00
return obj_template - > get ( name , value ) ;
}
2013-10-17 14:35:19 +04:00
/**
* Gets a long long based attribute ( single )
* @ param name of the attribute
* @ param value of the attribute ( long long ) , will be 0 if not defined or
* not a single attribute
*
* @ return True if the Single attribute was found and is a valid integer
* value
*/
bool get_template_attribute (
const char * name ,
long long & value ) const
{
return obj_template - > get ( name , value ) ;
}
2012-07-17 17:51:50 +04:00
/**
* Gets a float based attribute ( single )
* @ param name of the attribute
* @ param value of the attribute ( a float ) , will be 0 if not defined or
* not a single attribute
*
* @ return True if the Single attribute was found and is a valid float
* value
*/
bool get_template_attribute (
const char * name ,
float & value ) const
{
return obj_template - > get ( name , value ) ;
2011-04-08 03:02:55 +04:00
}
2013-01-18 02:14:34 +04:00
/**
* Gets a boolean attribute ( single ) ( YES = true )
* @ param name of the attribute
* @ param value of the attribute ( True if " YES " , false otherwise )
*
* @ return True if the Single attribute was found and is a valid boolean
* value
*/
bool get_template_attribute (
const char * name ,
bool & value ) const
{
return obj_template - > get ( name , value ) ;
}
2011-04-08 03:02:55 +04:00
/**
* Adds a new attribute to the template ( replacing it if
* already defined ) , the object ' s mutex SHOULD be locked
* @ param name of the new attribute
* @ param value of the new attribute
* @ return 0 on success
*/
int replace_template_attribute (
const string & name ,
const string & value )
{
2012-05-25 14:56:51 +04:00
return obj_template - > replace ( name , value ) ;
2011-04-08 03:02:55 +04:00
}
2014-05-10 03:22:02 +04:00
/**
* Removes an attribute from the template . The attributes are returned , and
* MUST be freed by the calling funtion
* @ param name of the attribute
* @ param values a vector containing a pointer to the attributes
* @ return the number of attributes removed
*/
int remove_template_attribute (
const string & name ,
vector < Attribute * > & values )
{
return obj_template - > remove ( name , values ) ;
}
2011-04-08 03:02:55 +04:00
/**
* Generates a XML string for the template of the Object
* @ param xml the string to store the XML description .
*/
2011-11-10 14:15:58 +04:00
string & template_to_xml ( string & xml ) const
2011-04-08 03:02:55 +04:00
{
2011-11-10 14:15:58 +04:00
return obj_template - > to_xml ( xml ) ;
2011-04-08 03:02:55 +04:00
}
/**
2014-11-20 17:14:45 +03:00
* Removes an attribute
2011-04-08 03:02:55 +04:00
* @ param name of the attribute
*/
int remove_template_attribute ( const string & name )
{
return obj_template - > erase ( name ) ;
}
2011-04-15 03:51:38 +04:00
/**
2013-02-13 21:06:20 +04:00
* Sets an error message with timestamp in the template
* @ param message Message string
2011-04-15 03:51:38 +04:00
*/
2013-04-26 19:26:09 +04:00
virtual void set_template_error_message ( const string & message ) ;
2011-04-15 03:51:38 +04:00
2013-02-14 19:55:47 +04:00
/**
* Deletes the error message from the template
*/
2013-04-26 19:26:09 +04:00
virtual void clear_template_error_message ( ) ;
2013-02-14 19:55:47 +04:00
2013-02-13 21:06:20 +04:00
/**
2013-02-16 05:55:17 +04:00
* Adds a string attribute
2013-02-13 21:06:20 +04:00
* @ param att_name Name for the attribute
2013-02-16 05:55:17 +04:00
* @ param att_val Message string
*/
void add_template_attribute ( const string & name , const string & value )
{
obj_template - > add ( name , value ) ;
}
/**
* Adds an int attribute
* @ param att_name Name for the attribute
* @ param att_val integer
2013-02-13 21:06:20 +04:00
*/
2013-02-16 05:55:17 +04:00
void add_template_attribute ( const string & name , int value )
{
obj_template - > add ( name , value ) ;
}
2013-02-13 21:06:20 +04:00
2013-02-23 22:49:06 +04:00
/**
* Adds a float attribute
* @ param att_name Name for the attribute
* @ param att_val integer
*/
void add_template_attribute ( const string & name , float value )
{
obj_template - > add ( name , value ) ;
}
2011-06-02 01:53:09 +04:00
/**
* Factory method for templates , it should be implemented
* by classes that uses templates
* @ return a new template
*/
2012-03-14 18:48:06 +04:00
virtual Template * get_new_template ( ) const
2011-06-02 01:53:09 +04:00
{
return 0 ;
}
/**
2011-06-02 02:51:42 +04:00
* Replace template for this object . Object should be updated
* after calling this method
2014-09-03 13:36:46 +04:00
* @ param tmpl_str new contents
* @ param keep_restricted If true , the restricted attributes of the
* current template will override the new template
* @ param error string describing the error if any
* @ return 0 on success
2011-06-02 01:53:09 +04:00
*/
2014-09-03 13:36:46 +04:00
virtual int replace_template ( const string & tmpl_str , bool keep_restricted , string & error ) ;
2011-06-02 01:53:09 +04:00
2013-06-28 20:00:26 +04:00
/**
* Append new attributes to this object ' s template . Object should be updated
* after calling this method
2014-09-03 13:36:46 +04:00
* @ param tmpl_str new contents
* @ param keep_restricted If true , the restricted attributes of the
* current template will override the new template
* @ param error string describing the error if any
* @ return 0 on success
2013-06-28 20:00:26 +04:00
*/
2014-09-03 13:36:46 +04:00
virtual int append_template ( const string & tmpl_str , bool keep_restricted , string & error ) ;
2011-12-30 01:05:11 +04:00
2012-01-03 05:58:23 +04:00
/**
* Fills a auth class to perform an authZ / authN request based on the object
* attributes
* @ param auths to be filled
*/
2014-09-17 19:05:01 +04:00
virtual void get_permissions ( PoolObjectAuth & auths ) ;
2011-12-30 01:05:11 +04:00
2008-06-17 20:27:32 +04:00
protected :
2010-04-03 18:54:54 +04:00
2008-06-17 20:27:32 +04:00
/**
2011-02-24 20:12:26 +03:00
* Callback function to unmarshall a PoolObjectSQL
* @ param num the number of columns read from the DB
* @ param names the column names
* @ param vaues the column values
* @ return 0 on success
2008-06-17 20:27:32 +04:00
*/
2011-02-24 20:12:26 +03:00
int select_cb ( void * nil , int num , char * * values , char * * names )
{
if ( ( ! values [ 0 ] ) | | ( num ! = 1 ) )
{
return - 1 ;
}
2011-02-25 01:30:39 +03:00
return from_xml ( values [ 0 ] ) ;
2011-02-24 20:12:26 +03:00
} ;
2009-07-13 16:21:14 +04:00
/**
2011-02-24 20:12:26 +03:00
* Reads the PoolObjectSQL ( identified by its OID ) from the database .
* @ param db pointer to the db
* @ return 0 on success
2009-07-13 16:21:14 +04:00
*/
2011-03-09 14:44:39 +03:00
virtual int select ( SqlDB * db ) ;
2011-02-24 20:12:26 +03:00
2011-03-05 05:24:11 +03:00
/**
* Reads the PoolObjectSQL ( identified by its OID ) from the database .
* @ param db pointer to the db
* @ return 0 on success
*/
2011-03-09 14:44:39 +03:00
virtual int select ( SqlDB * db , const string & _name , int _uid ) ;
2011-03-05 05:24:11 +03:00
2011-02-24 20:12:26 +03:00
/**
* Drops object from the database
* @ param db pointer to the db
* @ return 0 on success
*/
2011-03-09 14:44:39 +03:00
virtual int drop ( SqlDB * db ) ;
2011-02-24 20:12:26 +03:00
/**
* Function to output a pool object into a stream in XML format
* @ param oss the output stream
* @ param num the number of columns read from the DB
* @ param names the column names
* @ param vaues the column values
* @ return 0 on success
*/
static int dump ( ostringstream & oss , int num , char * * values , char * * names )
{
if ( ( ! values [ 0 ] ) | | ( num ! = 1 ) )
{
return - 1 ;
}
oss < < values [ 0 ] ;
return 0 ;
} ;
2011-12-29 21:14:20 +04:00
/**
* Prints the permissions into a string in XML format
* @ param xml the resulting XML string
* @ return a reference to the generated string
*/
string & perms_to_xml ( string & xml ) const ;
/**
* Rebuilds the object permissions from the xml . ObjectXML : : update_from_str
* must be called before this method
*
* @ return 0 on success , - 1 otherwise
*/
int perms_from_xml ( ) ;
2012-01-04 23:14:09 +04:00
/**
* Sets the permission attribute to the new_perm value , if it is different
* from - 1
*
* @ param perm the permissions attribute , must be - 1 , 0 or 1 , its value
* must be checked before
* @ param new_perm the new value . If it is - 1 , it will be ignored
*/
void set_perm ( int & perm , const int & new_perm )
{
if ( new_perm ! = - 1 )
{
perm = new_perm ;
}
} ;
2013-01-18 21:34:51 +04:00
/**
* Initializes the object ' s permissions , according to the provided umask .
*
* @ param umask Permission mask , similar to unix umask .
* For example a umask of 137 will set the permissions " um- u-- --- "
*/
void set_umask ( int umask ) ;
2013-03-15 20:37:47 +04:00
/**
* Sets an error message with timestamp in the template
* @ param name of the error attribute
* @ param message Message string
*/
2013-04-26 19:26:09 +04:00
virtual void set_template_error_message ( const string & name , const string & message ) ;
2013-03-15 20:37:47 +04:00
2014-10-20 18:05:44 +04:00
/**
* Child classes can process the new template set with replace_template or
* append_template with this method
* @ param error string describing the error if any
* @ return 0 on success
*/
virtual int post_update_template ( string & error )
{
return 0 ;
} ;
2011-02-24 20:12:26 +03:00
/**
* The object ' s unique ID
2008-06-17 20:27:32 +04:00
*/
2011-03-05 00:37:21 +03:00
int oid ;
2012-01-03 05:58:23 +04:00
/**
* The object type
*/
ObjectType obj_type ;
2011-03-05 00:37:21 +03:00
/**
* The object ' s name
*/
string name ;
/**
2011-03-05 05:24:11 +03:00
* Object ' s owner , set it to - 1 if owner is not used
2011-03-05 00:37:21 +03:00
*/
int uid ;
2009-07-13 16:21:14 +04:00
Feature #407: Add 'GID' attribute to some pool objects; change *pool.info XML-RPC flag meaning; update onedb migrator; fix tests.
* VM, VMTEMPLATE, VNET & IMAGE objects have a GID attribute, and a table column. The group id is inherited from the user creating the object, except for VMs created from Templates, that inherit the Template's group.
* The new flag meaning has been modified in src/rm sources and CLI commands for one.(vm,template,vnet,image)pool.info . It changes from
-2 all, -1 mine & public, >=0 UID
to
-3 mine, -2 all, -1 mine & group
* USER has a group, but not secondary ones. The user_pool table doesn't have a GID column, we'll deal with it later when the group-users relations are implemented.
* onedb migrator 1.rb: deleted USERNAME, and GID added.
2011-05-16 19:00:27 +04:00
/**
* Object ' s group , set it to - 1 if group is not used
*/
int gid ;
2011-06-30 13:31:00 +04:00
/**
* Name of the object ' s owner , empty if owner is not used
*/
string uname ;
/**
* Name of the object ' s group , , empty if group is not used
*/
string gname ;
2009-07-13 16:21:14 +04:00
/**
2011-02-24 20:12:26 +03:00
* The contents of this object are valid
2009-07-13 16:21:14 +04:00
*/
2011-03-05 00:37:21 +03:00
bool valid ;
2008-06-17 20:27:32 +04:00
2011-12-29 21:14:20 +04:00
/**
* Permissions for the owner user
*/
int owner_u ;
int owner_m ;
int owner_a ;
/**
* Permissions for users in the object ' s group
*/
int group_u ;
int group_m ;
int group_a ;
/**
* Permissions for the rest
*/
int other_u ;
int other_m ;
int other_a ;
2011-04-08 03:02:55 +04:00
/**
* Template for this object , will be allocated if needed
*/
Template * obj_template ;
2008-06-17 20:27:32 +04:00
private :
2013-04-10 14:56:06 +04:00
/**
* Characters that can not be in a name
*/
static const string INVALID_NAME_CHARS ;
2008-06-17 20:27:32 +04:00
/**
* The PoolSQL , friend to easily manipulate its Objects
*/
friend class PoolSQL ;
/**
2010-04-03 18:54:54 +04:00
* The mutex for the PoolObject . This implementation assumes that the mutex
* IS LOCKED when the class destructor is called .
2008-06-17 20:27:32 +04:00
*/
pthread_mutex_t mutex ;
2011-02-25 01:30:39 +03:00
/**
* Pointer to the SQL table for the PoolObjectSQL
*/
const char * table ;
2008-06-17 20:27:32 +04:00
} ;
# endif /*POOL_OBJECT_SQL_H_*/