1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-11 05:17:41 +03:00

feature #4238: Checks in Datastore post-update

This commit is contained in:
Ruben S. Montero 2016-01-04 11:29:20 +01:00
parent 3b3ca99860
commit e9c671fd8b
3 changed files with 216 additions and 188 deletions

View File

@ -193,57 +193,13 @@ public:
* Returns the value of LOG->DEBUG_LEVEL in oned.conf file
* @return the debug level, to instantiate Log'ers
*/
Log::MessageType get_debug_level() const
{
Log::MessageType clevel = Log::ERROR;
vector<const Attribute *> logs;
int rc;
int log_level_int;
rc = nebula_configuration->get("LOG", logs);
if ( rc != 0 )
{
string value;
const VectorAttribute * log = static_cast<const VectorAttribute *>
(logs[0]);
value = log->vector_value("DEBUG_LEVEL");
log_level_int = atoi(value.c_str());
if ( Log::ERROR <= log_level_int && log_level_int <= Log::DDDEBUG )
{
clevel = static_cast<Log::MessageType>(log_level_int);
}
}
return clevel;
}
Log::MessageType get_debug_level() const;
/**
* Returns the value of LOG->SYSTEM in oned.conf file
* @return the logging system CERR, FILE_TS or SYSLOG
*/
NebulaLog::LogType get_log_system() const
{
vector<const Attribute *> logs;
int rc;
NebulaLog::LogType log_system = NebulaLog::UNDEFINED;
rc = nebula_configuration->get("LOG", logs);
if ( rc != 0 )
{
string value;
const VectorAttribute * log = static_cast<const VectorAttribute *>
(logs[0]);
value = log->vector_value("SYSTEM");
log_system = NebulaLog::str_to_type(value);
}
return log_system;
};
NebulaLog::LogType get_log_system() const;
/**
* Returns the value of ONE_LOCATION env variable. When this variable is
@ -301,28 +257,7 @@ public:
*
*
*/
int get_ds_location(int cluster_id, string& dsloc)
{
if ( cluster_id != -1 )
{
Cluster * cluster = clpool->get(cluster_id, true);
if ( cluster == 0 )
{
return -1;
}
cluster->get_ds_location(dsloc);
cluster->unlock();
}
else
{
get_configuration_attribute("DATASTORE_LOCATION", dsloc);
}
return 0;
}
int get_ds_location(int cluster_id, string& dsloc);
/**
* Returns the default vms location. When ONE_LOCATION is defined this path
@ -344,21 +279,7 @@ public:
* /var/log/one/$VM_ID.log
* @return the log location for the VM.
*/
string get_vm_log_filename(int oid)
{
ostringstream oss;
if (nebula_location == "/")
{
oss << log_location << oid << ".log";
}
else
{
oss << vms_location << oid << "/vm.log";
}
return oss.str();
};
string get_vm_log_filename(int oid);
/**
* Returns the name of the host running oned
@ -413,7 +334,10 @@ public:
/**
* Initialize the database
*/
void bootstrap_db();
void bootstrap_db()
{
start(true);
}
// --------------------------------------------------------------
// Federation
@ -502,78 +426,14 @@ public:
*/
int get_ds_conf_attribute(
const std::string& ds_name,
const VectorAttribute* &value) const
{
std::vector<const Attribute*>::const_iterator it;
std::vector<const Attribute*> values;
std::string template_ds_name;
std::string ds_name_upper;
nebula_configuration->Template::get("DS_MAD_CONF", values);
for (it = values.begin(); it != values.end(); it ++)
{
value = dynamic_cast<const VectorAttribute*>(*it);
if (value == 0)
{
continue;
}
template_ds_name = value->vector_value("NAME");
ds_name_upper = ds_name;
one_util::toupper(ds_name_upper);
one_util::toupper(template_ds_name);
if ( template_ds_name == ds_name_upper)
{
return 0;
}
}
value = 0;
return -1;
};
const VectorAttribute* &value) const;
/**
* Gets a TM configuration attribute
*/
int get_tm_conf_attribute(
const string& tm_name,
const VectorAttribute* &value) const
{
vector<const Attribute*>::const_iterator it;
vector<const Attribute*> values;
std::string template_tm_name;
std::string tm_name_upper;
nebula_configuration->Template::get("TM_MAD_CONF", values);
for (it = values.begin(); it != values.end(); it ++)
{
value = dynamic_cast<const VectorAttribute*>(*it);
if (value == 0)
{
continue;
}
template_tm_name = value->vector_value("NAME");
tm_name_upper = tm_name;
one_util::toupper(tm_name_upper);
one_util::toupper(template_tm_name);
if ( tm_name_upper == template_tm_name)
{
return 0;
}
}
value = 0;
return -1;
};
const VectorAttribute* &value) const;
/**
* Gets an XML document with all of the configuration attributes

View File

@ -211,7 +211,7 @@ static int check_tm_target_type(string& tm_tt)
/* -------------------------------------------------------------------------- */
int Datastore::set_ds_mad(std::string &tm_mad, std::string &error_str)
int Datastore::set_ds_mad(std::string &mad, std::string &error_str)
{
const VectorAttribute* vatt;
std::vector <std::string> vrequired_attrs;
@ -221,23 +221,22 @@ int Datastore::set_ds_mad(std::string &tm_mad, std::string &error_str)
std::ostringstream oss;
rc = Nebula::instance().get_ds_conf_attribute(ds_mad, vatt);
if ( type == SYSTEM_DS ) //No ds_mad for SYSTEM_DS
{
return 0;
}
rc = Nebula::instance().get_ds_conf_attribute(mad, vatt);
if ( rc != 0 )
{
oss << "DS_MAD named \"" << ds_mad << "\" is not defined in oned.conf";
error_str = oss.str();
return -1;
goto error_conf;
}
rc = vatt->vector_value("REQUIRED_ATTRS", required_attrs);
if ( rc == -1 )
if ( rc == -1 ) //No required attributes
{
// This DS_MAD has no required attributes: exit
return 0;
}
@ -255,18 +254,22 @@ int Datastore::set_ds_mad(std::string &tm_mad, std::string &error_str)
if ( value.empty() )
{
goto error;
goto error_required;
}
}
return 0;
error:
error_conf:
oss << "DS_MAD named \"" << mad << "\" is not defined in oned.conf";
goto error_common;
error_required:
oss << "Datastore template is missing the \"" << required_attr
<< "\" attribute or it's empty.";
error_common:
error_str = oss.str();
return -1;
}
@ -276,20 +279,13 @@ int Datastore::set_tm_mad(string &tm_mad, string &error_str)
{
const VectorAttribute* vatt;
int rc;
string st;
ostringstream oss;
rc = Nebula::instance().get_tm_conf_attribute(tm_mad, vatt);
if (rc != 0)
if ( Nebula::instance().get_tm_conf_attribute(tm_mad, vatt) != 0 )
{
oss << "TM_MAD named \"" << tm_mad << "\" is not defined in oned.conf";
error_str = oss.str();
return -1;
goto error_conf;
}
if (type == SYSTEM_DS)
@ -353,12 +349,16 @@ int Datastore::set_tm_mad(string &tm_mad, string &error_str)
return 0;
error_conf:
oss << "TM_MAD named \"" << tm_mad << "\" is not defined in oned.conf";
goto error_common;
error:
oss << "Attribute shared, ln_target or clone_target in TM_MAD_CONF for "
<< tm_mad << " is missing or has wrong value in oned.conf";
error_common:
error_str = oss.str();
return -1;
}
@ -761,8 +761,6 @@ int Datastore::from_xml(const string& xml)
int Datastore::post_update_template(string& error_str)
{
int rc;
string new_ds_mad;
string new_tm_mad;
string s_ds_type;
@ -773,13 +771,13 @@ int Datastore::post_update_template(string& error_str)
DatastoreType old_ds_type = type;
Image::DiskType old_disk_type = disk_type;
string old_tm_mad = tm_mad;
string old_ds_mad = ds_mad;
/* ---------------------------------------------------------------------- */
/* Set the TYPE of the Datastore (class & template) */
/* ---------------------------------------------------------------------- */
old_ds_type = type;
get_template_attribute("TYPE", s_ds_type);
if (!s_ds_type.empty())
@ -884,11 +882,14 @@ int Datastore::post_update_template(string& error_str)
/* Verify that the template has the required attributees */
/* ---------------------------------------------------------------------- */
rc = set_ds_mad(ds_mad, error_str);
if ( rc != 0 )
if ( set_ds_mad(ds_mad, error_str) != 0 )
{
return rc;
type = old_ds_type;
disk_type = old_disk_type;
tm_mad = old_tm_mad;
ds_mad = old_ds_mad;
return -1;
}
/* ---------------------------------------------------------------------- */

View File

@ -36,14 +36,6 @@ using namespace std;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Nebula::bootstrap_db()
{
start(true);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Nebula::start(bool bootstrap_only)
{
int rc;
@ -968,3 +960,178 @@ error_mad:
throw runtime_error("Could not load an OpenNebula driver");
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
Log::MessageType Nebula::get_debug_level() const
{
Log::MessageType clevel = Log::ERROR;
vector<const Attribute *> logs;
int rc;
int log_level_int;
rc = nebula_configuration->get("LOG", logs);
if ( rc != 0 )
{
string value;
const VectorAttribute * log = static_cast<const VectorAttribute *>
(logs[0]);
value = log->vector_value("DEBUG_LEVEL");
log_level_int = atoi(value.c_str());
if ( Log::ERROR <= log_level_int && log_level_int <= Log::DDDEBUG )
{
clevel = static_cast<Log::MessageType>(log_level_int);
}
}
return clevel;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
NebulaLog::LogType Nebula::get_log_system() const
{
vector<const Attribute *> logs;
int rc;
NebulaLog::LogType log_system = NebulaLog::UNDEFINED;
rc = nebula_configuration->get("LOG", logs);
if ( rc != 0 )
{
string value;
const VectorAttribute * log = static_cast<const VectorAttribute *>
(logs[0]);
value = log->vector_value("SYSTEM");
log_system = NebulaLog::str_to_type(value);
}
return log_system;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Nebula::get_ds_location(int cluster_id, string& dsloc)
{
if ( cluster_id != -1 )
{
Cluster * cluster = clpool->get(cluster_id, true);
if ( cluster == 0 )
{
return -1;
}
cluster->get_ds_location(dsloc);
cluster->unlock();
}
else
{
get_configuration_attribute("DATASTORE_LOCATION", dsloc);
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string Nebula::get_vm_log_filename(int oid)
{
ostringstream oss;
if (nebula_location == "/")
{
oss << log_location << oid << ".log";
}
else
{
oss << vms_location << oid << "/vm.log";
}
return oss.str();
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Nebula::get_ds_conf_attribute(
const std::string& ds_name,
const VectorAttribute* &value) const
{
std::vector<const Attribute*>::const_iterator it;
std::vector<const Attribute*> values;
std::string template_ds_name;
std::string ds_name_upper;
nebula_configuration->Template::get("DS_MAD_CONF", values);
for (it = values.begin(); it != values.end(); it ++)
{
value = dynamic_cast<const VectorAttribute*>(*it);
if (value == 0)
{
continue;
}
template_ds_name = value->vector_value("NAME");
ds_name_upper = ds_name;
one_util::toupper(ds_name_upper);
one_util::toupper(template_ds_name);
if ( template_ds_name == ds_name_upper)
{
return 0;
}
}
value = 0;
return -1;
};
int Nebula::get_tm_conf_attribute(
const string& tm_name,
const VectorAttribute* &value) const
{
vector<const Attribute*>::const_iterator it;
vector<const Attribute*> values;
std::string template_tm_name;
std::string tm_name_upper;
nebula_configuration->Template::get("TM_MAD_CONF", values);
for (it = values.begin(); it != values.end(); it ++)
{
value = dynamic_cast<const VectorAttribute*>(*it);
if (value == 0)
{
continue;
}
template_tm_name = value->vector_value("NAME");
tm_name_upper = tm_name;
one_util::toupper(tm_name_upper);
one_util::toupper(template_tm_name);
if ( tm_name_upper == template_tm_name)
{
return 0;
}
}
value = 0;
return -1;
};