1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

feature #360: Split NebulaTemplate class to support addtional configuration files for OpenNebula daemons

This commit is contained in:
Ruben S. Montero 2011-12-13 23:57:56 +01:00
parent 1efe63ce68
commit 52819b7909
4 changed files with 124 additions and 73 deletions

View File

@ -407,7 +407,7 @@ private:
// Configuration // Configuration
// --------------------------------------------------------------- // ---------------------------------------------------------------
NebulaTemplate * nebula_configuration; OpenNebulaTemplate * nebula_configuration;
// --------------------------------------------------------------- // ---------------------------------------------------------------
// Nebula Pools // Nebula Pools

View File

@ -20,15 +20,24 @@
#include "Template.h" #include "Template.h"
#include <map> #include <map>
/**
* This class provides the basic abstraction for OpenNebula configuration files
*/
class NebulaTemplate : public Template class NebulaTemplate : public Template
{ {
public: public:
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
NebulaTemplate(string& etc_location, string& var_location); NebulaTemplate(const string& etc_location, const char * _conf_name)
{
conf_file = etc_location + _conf_name;
}
~NebulaTemplate(){}; virtual ~NebulaTemplate(){};
static const char * conf_name; // -----------------------------------------------------------------------
// -----------------------------------------------------------------------
int get(const char * name, vector<const Attribute*>& values) const int get(const char * name, vector<const Attribute*>& values) const
{ {
@ -77,14 +86,59 @@ public:
values = 0; values = 0;
}; };
private: // -----------------------------------------------------------------------
friend class Nebula; // -----------------------------------------------------------------------
/**
* Parse and loads the configuration in the template
*/
int load_configuration();
protected:
/**
* Full path to the configuration file
*/
string conf_file; string conf_file;
/**
* Defaults for the configuration file
*/
map<string, Attribute*> conf_default; map<string, Attribute*> conf_default;
int load_configuration(); /**
* Sets the defaults value for the template
*/
virtual void set_conf_default() = 0;
};
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
class OpenNebulaTemplate : public NebulaTemplate
{
public:
OpenNebulaTemplate(const string& etc_location, const string& _var_location):
NebulaTemplate(etc_location, conf_name), var_location(_var_location)
{};
~OpenNebulaTemplate(){};
private:
/**
* Name for the configuration file, oned.conf
*/
static const char * conf_name;
/**
* Path for the var directory, for defaults
*/
string var_location;
/**
* Sets the defaults value for the template
*/
void set_conf_default();
}; };

View File

@ -56,7 +56,7 @@ void Nebula::start()
// Configuration // Configuration
// ----------------------------------------------------------- // -----------------------------------------------------------
nebula_configuration = new NebulaTemplate(etc_location, var_location); nebula_configuration = new OpenNebulaTemplate(etc_location, var_location);
rc = nebula_configuration->load_configuration(); rc = nebula_configuration->load_configuration();

View File

@ -15,33 +15,76 @@
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
#include "NebulaTemplate.h" #include "NebulaTemplate.h"
#include "Nebula.h"
using namespace std; using namespace std;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
const char * NebulaTemplate::conf_name="oned.conf"; int NebulaTemplate::load_configuration()
{
char * error = 0;
int rc;
string aname;
Attribute * attr;
map<string, Attribute *>::iterator iter, j;
set_conf_default();
rc = parse(conf_file.c_str(), &error);
if ( rc != 0 && error != 0)
{
cout << "\nError while parsing configuration file:\n" << error << endl;
free(error);
return -1;
}
for(iter=conf_default.begin();iter!=conf_default.end();)
{
aname = iter->first;
attr = iter->second;
j = attributes.find(aname);
if ( j == attributes.end() )
{
attributes.insert(make_pair(aname,attr));
iter++;
}
else
{
delete iter->second;
conf_default.erase(iter++);
}
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
const char * OpenNebulaTemplate::conf_name="oned.conf";
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location) void OpenNebulaTemplate::set_conf_default()
{ {
ostringstream os; ostringstream os;
SingleAttribute * attribute; SingleAttribute * attribute;
VectorAttribute * vattribute; VectorAttribute * vattribute;
string value; string value;
conf_file = etc_location + conf_name;
// MANAGER_TIMER // MANAGER_TIMER
value = "15"; value = "15";
attribute = new SingleAttribute("MANAGER_TIMER",value); attribute = new SingleAttribute("MANAGER_TIMER",value);
conf_default.insert(make_pair(attribute->name(),attribute)); conf_default.insert(make_pair(attribute->name(),attribute));
/* /*
#******************************************************************************* #*******************************************************************************
# Daemon configuration attributes # Daemon configuration attributes
@ -170,49 +213,3 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location)
conf_default.insert(make_pair(attribute->name(),attribute)); conf_default.insert(make_pair(attribute->name(),attribute));
} }
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int NebulaTemplate::load_configuration()
{
char * error = 0;
map<string, Attribute *>::iterator iter, j;
int rc;
string aname;
Attribute * attr;
rc = parse(conf_file.c_str(), &error);
if ( rc != 0 && error != 0)
{
cout << "\nError while parsing configuration file:\n" << error << endl;
free(error);
return -1;
}
for(iter=conf_default.begin();iter!=conf_default.end();)
{
aname = iter->first;
attr = iter->second;
j = attributes.find(aname);
if ( j == attributes.end() )
{
attributes.insert(make_pair(aname,attr));
iter++;
}
else
{
delete iter->second;
conf_default.erase(iter++);
}
}
return 0;
}