2008-06-17 16:27:32 +00:00
/* -------------------------------------------------------------------------- */
2023-01-09 12:23:19 +01:00
/* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems */
2008-06-17 16:27:32 +00: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 NEBULA_TEMPLATE_H_
# define NEBULA_TEMPLATE_H_
# include "Template.h"
2017-01-29 23:46:59 +01:00
2008-06-17 16:27:32 +00:00
# include <map>
2013-12-21 01:35:51 +01:00
/**
2011-12-13 23:57:56 +01:00
* This class provides the basic abstraction for OpenNebula configuration files
*/
2008-06-17 16:27:32 +00:00
class NebulaTemplate : public Template
2011-12-13 23:57:56 +01:00
{
2008-06-17 16:27:32 +00:00
public :
2020-07-02 22:42:10 +02:00
NebulaTemplate ( const std : : string & etc_location , const char * _conf_name ,
2022-03-29 14:20:13 +02:00
const char * root_name )
: Template ( false , ' = ' , root_name )
2024-01-08 13:56:40 +01:00
, hidden_attributes {
{ " DB " , { " BACKEND " , " SERVER " , " PORT " , " USER " , " PASSWD " , " DB_NAME " } }
}
2011-12-13 23:57:56 +01:00
{
2022-12-08 10:33:45 +01:00
if ( _conf_name [ 0 ] = = ' / ' )
{
conf_file = _conf_name ;
}
else
{
conf_file = etc_location + _conf_name ;
}
2011-12-13 23:57:56 +01:00
}
2013-12-21 01:35:51 +01:00
2020-03-04 16:05:57 +01:00
virtual ~ NebulaTemplate ( ) = default ;
2011-12-13 23:57:56 +01:00
/**
* Parse and loads the configuration in the template
*/
2017-01-29 23:46:59 +01:00
virtual int load_configuration ( ) ;
2011-12-13 23:57:56 +01:00
2022-03-29 14:20:13 +02:00
std : : string & to_str ( std : : string & str ) const override ;
2024-01-08 13:56:40 +01:00
std : : string & to_xml_hidden ( std : : string & str ) const ;
2011-12-13 23:57:56 +01:00
protected :
/**
2013-12-21 01:35:51 +01:00
* Full path to the configuration file
2011-12-13 23:57:56 +01:00
*/
2024-01-08 13:56:40 +01:00
std : : string conf_file ;
2013-12-21 01:35:51 +01:00
2011-12-13 23:57:56 +01:00
/**
* Defaults for the configuration file
*/
2020-07-02 22:42:10 +02:00
std : : multimap < std : : string , Attribute * > conf_default ;
2011-12-13 23:57:56 +01:00
2022-03-29 14:20:13 +02:00
/**
* Hidden attributes , which shouldn ' t be displayed to non - admin users
2024-01-08 13:56:40 +01:00
* For Simple attributes use { " PORT " , { } }
* For Vector attributes use { " DB " , { " USER " , " PASSWD " } }
2022-03-29 14:20:13 +02:00
*/
std : : map < std : : string , std : : set < std : : string > > hidden_attributes ;
2011-12-13 23:57:56 +01:00
/**
* Sets the defaults value for the template
*/
virtual void set_conf_default ( ) = 0 ;
2015-12-21 16:45:09 +01:00
/**
* Sets the defaults value for multiple attributes
*/
virtual void set_multiple_conf_default ( ) = 0 ;
2015-12-21 17:02:05 +01:00
2015-12-18 16:22:53 +01:00
/**
* Sets a default single attribute value
*/
2015-12-21 16:45:09 +01:00
void set_conf_single ( const std : : string & attr , const std : : string & value ) ;
2008-06-17 16:27:32 +00:00
} ;
# endif /*NEBULA_TEMPLATE_H_*/