1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-22 22:03:39 +03:00

Bug #1306: Clusters can use the datastore set in SYSTEM_DS, Datastores can have SYSTEM = YES in the template

This commit is contained in:
Carlos Martín 2012-06-29 12:44:04 +02:00
parent a6b2c86bfb
commit 792dcf01b3
5 changed files with 72 additions and 10 deletions

View File

@ -31,6 +31,23 @@ class Cluster : public PoolObjectSQL
{
public:
/**
* Returns the SYSTEM_DS attribute, or the system DS id if it is not defined
*
* @return the SYSTEM_DS attribute, or the system DS id if it is not defined
*/
int get_ds_id()
{
int ds_id;
if ( obj_template->get("SYSTEM_DS", ds_id) == false )
{
ds_id = DatastorePool::SYSTEM_DS_ID;
}
return ds_id;
}
// *************************************************************************
// Object Collections (Public)
// *************************************************************************

View File

@ -134,6 +134,11 @@ private:
*/
string base_path;
/**
* 1 if this is a system DS
*/
int system_ds;
/**
* Disk types for the Images created in this datastore
*/

View File

@ -19,6 +19,8 @@
#include "NebulaLog.h"
#include "Nebula.h"
#define TO_UPPER(S) transform(S.begin(),S.end(),S.begin(),(int(*)(int))toupper)
const char * Datastore::table = "datastore_pool";
const char * Datastore::db_names =
@ -97,6 +99,7 @@ int Datastore::insert(SqlDB *db, string& error_str)
int rc;
ostringstream oss;
string s_disk_type;
string s_system_ds;
Nebula& nd = Nebula::instance();
@ -108,8 +111,22 @@ int Datastore::insert(SqlDB *db, string& error_str)
// NAME is checked in DatastorePool::allocate
get_template_attribute("DS_MAD", ds_mad);
get_template_attribute("SYSTEM", s_system_ds);
if ( ds_mad.empty() == true )
TO_UPPER(s_system_ds);
system_ds = (s_system_ds == "YES");
if ( system_ds == 1 )
{
if ( !ds_mad.empty() )
{
goto error_exclusive;
}
ds_mad = "-";
}
else if ( ds_mad.empty() == true )
{
goto error_ds;
}
@ -152,6 +169,10 @@ int Datastore::insert(SqlDB *db, string& error_str)
return rc;
error_exclusive:
error_str = "SYSTEM datastores cannot have DS_MAD defined.";
goto error_common;
error_ds:
error_str = "No DS_MAD in template.";
goto error_common;
@ -273,6 +294,7 @@ string& Datastore::to_xml(string& xml) const
"<DS_MAD>" << ds_mad << "</DS_MAD>" <<
"<TM_MAD>" << tm_mad << "</TM_MAD>" <<
"<BASE_PATH>" << base_path << "</BASE_PATH>" <<
"<SYSTEM>" << system_ds << "</SYSTEM>" <<
"<DISK_TYPE>" << disk_type << "</DISK_TYPE>" <<
"<CLUSTER_ID>" << cluster_id << "</CLUSTER_ID>" <<
"<CLUSTER>" << cluster << "</CLUSTER>" <<
@ -307,6 +329,7 @@ int Datastore::from_xml(const string& xml)
rc += xpath(ds_mad, "/DATASTORE/DS_MAD", "not_found");
rc += xpath(tm_mad, "/DATASTORE/TM_MAD", "not_found");
rc += xpath(base_path, "/DATASTORE/BASE_PATH", "not_found");
rc += xpath(system_ds, "/DATASTORE/SYSTEM", -1);
rc += xpath(int_disk_type,"/DATASTORE/DISK_TYPE", -1);
rc += xpath(cluster_id, "/DATASTORE/CLUSTER_ID", -1);
@ -354,14 +377,15 @@ int Datastore::from_xml(const string& xml)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Datastore::replace_template(const string& tmpl_str, string& error)
int Datastore::replace_template(const string& tmpl_str, string& error_str)
{
string new_ds_mad;
string new_tm_mad;
string s_system_ds;
int rc;
rc = PoolObjectSQL::replace_template(tmpl_str, error);
rc = PoolObjectSQL::replace_template(tmpl_str, error_str);
if ( rc != 0 )
{
@ -369,15 +393,32 @@ int Datastore::replace_template(const string& tmpl_str, string& error)
}
get_template_attribute("DS_MAD", new_ds_mad);
get_template_attribute("SYSTEM", s_system_ds);
TO_UPPER(s_system_ds);
if ( !s_system_ds.empty() )
{
system_ds = (s_system_ds == "YES");
}
if ( system_ds == 1 )
{
replace_template_attribute("SYSTEM", "YES");
new_ds_mad = "-";
}
else
{
obj_template->erase("SYSTEM");
}
if ( !new_ds_mad.empty() )
{
ds_mad = new_ds_mad;
}
else
{
replace_template_attribute("DS_MAD", ds_mad);
}
replace_template_attribute("DS_MAD", ds_mad);
get_template_attribute("TM_MAD", new_tm_mad);

View File

@ -53,7 +53,7 @@ DatastorePool::DatastorePool(SqlDB * db):
// ---------------------------------------------------------------------
oss << "NAME = " << SYSTEM_DS_NAME << endl
<< "DS_MAD = -" << endl
<< "SYSTEM = YES" << endl
<< "TM_MAD = shared";
ds_tmpl = new DatastoreTemplate;

View File

@ -145,8 +145,7 @@ int RequestManagerVirtualMachine::get_host_information(int hid,
return -1;
}
// TODO: ds_id = cluster->get_datastore()
ds_id = DatastorePool::SYSTEM_DS_ID;
ds_id = cluster->get_ds_id();
cluster->unlock();