mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
feature #360: Split NebulaTemplate class to support addtional configuration files for OpenNebula daemons
This commit is contained in:
parent
1efe63ce68
commit
52819b7909
@ -407,7 +407,7 @@ private:
|
||||
// Configuration
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
NebulaTemplate * nebula_configuration;
|
||||
OpenNebulaTemplate * nebula_configuration;
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// Nebula Pools
|
||||
|
@ -20,16 +20,25 @@
|
||||
#include "Template.h"
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
* This class provides the basic abstraction for OpenNebula configuration files
|
||||
*/
|
||||
class NebulaTemplate : public Template
|
||||
{
|
||||
{
|
||||
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
|
||||
{
|
||||
string _name(name);
|
||||
@ -53,38 +62,83 @@ public:
|
||||
|
||||
void get(const char * name, time_t& values) const
|
||||
{
|
||||
const SingleAttribute * sattr;
|
||||
vector<const Attribute *> attr;
|
||||
const SingleAttribute * sattr;
|
||||
vector<const Attribute *> attr;
|
||||
|
||||
string _name(name);
|
||||
string _name(name);
|
||||
|
||||
if ( Template::get(_name,attr) == 0 )
|
||||
{
|
||||
values = 0;
|
||||
return;
|
||||
values = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
sattr = dynamic_cast<const SingleAttribute *>(attr[0]);
|
||||
|
||||
if ( sattr != 0 )
|
||||
{
|
||||
istringstream is;
|
||||
|
||||
is.str(sattr->value());
|
||||
is >> values;
|
||||
istringstream is;
|
||||
|
||||
is.str(sattr->value());
|
||||
is >> values;
|
||||
}
|
||||
else
|
||||
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;
|
||||
|
||||
/**
|
||||
* Defaults for the configuration file
|
||||
*/
|
||||
map<string, Attribute*> conf_default;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{};
|
||||
|
||||
int load_configuration();
|
||||
~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();
|
||||
};
|
||||
|
||||
|
||||
|
@ -56,7 +56,7 @@ void Nebula::start()
|
||||
// Configuration
|
||||
// -----------------------------------------------------------
|
||||
|
||||
nebula_configuration = new NebulaTemplate(etc_location, var_location);
|
||||
nebula_configuration = new OpenNebulaTemplate(etc_location, var_location);
|
||||
|
||||
rc = nebula_configuration->load_configuration();
|
||||
|
||||
|
@ -15,33 +15,76 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "NebulaTemplate.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
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;
|
||||
SingleAttribute * attribute;
|
||||
VectorAttribute * vattribute;
|
||||
string value;
|
||||
|
||||
conf_file = etc_location + conf_name;
|
||||
|
||||
// MANAGER_TIMER
|
||||
value = "15";
|
||||
|
||||
attribute = new SingleAttribute("MANAGER_TIMER",value);
|
||||
conf_default.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
/*
|
||||
#*******************************************************************************
|
||||
# Daemon configuration attributes
|
||||
@ -170,49 +213,3 @@ NebulaTemplate::NebulaTemplate(string& etc_location, string& var_location)
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user