mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-26 06:50:09 +03:00
Feature #4238: Add DS_MAD_CONF attributes to handle
mandatory attributes in Datastore templates
This commit is contained in:
parent
3c11db6872
commit
5db705deae
@ -373,6 +373,17 @@ private:
|
||||
return new DatastoreTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the proper definition of the DS_MAD by checking the attributes
|
||||
* related to the DS defined in DS_MAD_CONF specified in the Datastore
|
||||
* template
|
||||
*/
|
||||
int set_ds_mad(string &ds_mad, string &error_str);
|
||||
|
||||
/**
|
||||
* Verify the proper definition of the TM_MAD by checking the attributes
|
||||
* related to the TM defined in TM_MAD_CONF
|
||||
*/
|
||||
int set_tm_mad(string &tm_mad, string &error_str);
|
||||
|
||||
/**
|
||||
|
@ -497,6 +497,37 @@ public:
|
||||
nebula_configuration->Template::get(_name, value);
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a DS configuration attribute
|
||||
*/
|
||||
int get_ds_conf_attribute(
|
||||
const string& tm_name,
|
||||
const VectorAttribute* &value) const
|
||||
{
|
||||
vector<const Attribute*>::const_iterator it;
|
||||
vector<const Attribute*> values;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (value->vector_value("NAME") == tm_name)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
value = 0;
|
||||
return -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets a TM configuration attribute
|
||||
*/
|
||||
|
@ -198,6 +198,12 @@ private:
|
||||
*/
|
||||
void set_conf_single(const std::string& attr, const std::string& value);
|
||||
|
||||
/**
|
||||
* Sets a the defaults for a DS
|
||||
*/
|
||||
void set_conf_ds(const std::string& name,
|
||||
const std::string& required_attrs);
|
||||
|
||||
/**
|
||||
* Sets a the defaults for a TM
|
||||
*/
|
||||
|
@ -991,3 +991,49 @@ TM_MAD_CONF = [
|
||||
name = "dev", ln_target = "NONE", clone_target = "NONE", shared = "yes"
|
||||
]
|
||||
|
||||
#*******************************************************************************
|
||||
# Datastore Manager Driver Behavior Configuration
|
||||
#*******************************************************************************
|
||||
# The configuration for each driver is defined in DS_MAD_CONF. These
|
||||
# values are used when creating a new datastore and should not be modified
|
||||
# since they define the datastore behavior.
|
||||
# name : name of the transfer driver, listed in the -d option of the
|
||||
# DS_MAD section
|
||||
# required_attrs : comma separated list of required attributes in the DS
|
||||
# template
|
||||
#*******************************************************************************
|
||||
|
||||
|
||||
DS_MAD_CONF = [
|
||||
name = "ceph",
|
||||
required_attrs = "DISK_TYPE,BRIDGE_LIST,CEPH_HOST,CEPH_USER,CEPH_SECRET"
|
||||
]
|
||||
|
||||
DS_MAD_CONF = [
|
||||
name = "dev",
|
||||
required_attrs = "DISK_TYPE,ISCSI_HOST"
|
||||
]
|
||||
|
||||
DS_MAD_CONF = [
|
||||
name = "dummy", required_attrs = ""
|
||||
]
|
||||
|
||||
DS_MAD_CONF = [
|
||||
name = "fs", required_attrs = ""
|
||||
]
|
||||
|
||||
DS_MAD_CONF = [
|
||||
name = "lvm", required_attrs = "DISK_TYPE"
|
||||
]
|
||||
|
||||
DS_MAD_CONF = [
|
||||
name = "shared", required_attrs = ""
|
||||
]
|
||||
|
||||
DS_MAD_CONF = [
|
||||
name = "ssh", required_attrs = ""
|
||||
]
|
||||
|
||||
DS_MAD_CONF = [
|
||||
name = "vmfs", required_attrs = "BRIDGE_LIST"
|
||||
]
|
||||
|
@ -211,6 +211,67 @@ static int check_tm_target_type(string& tm_tt)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Datastore::set_ds_mad(std::string &tm_mad, std::string &error_str)
|
||||
{
|
||||
const VectorAttribute* vatt;
|
||||
std::vector <std::string> vrequired_attrs;
|
||||
|
||||
int rc;
|
||||
std::string required_attrs, required_attr, value;
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
rc = Nebula::instance().get_ds_conf_attribute(ds_mad, vatt);
|
||||
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
oss << "DS_MAD named \"" << ds_mad << "\" is not defined in oned.conf";
|
||||
|
||||
error_str = oss.str();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = vatt->vector_value("REQUIRED_ATTRS", required_attrs);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
// This DS_MAD has no required attributes: exit
|
||||
return 0;
|
||||
}
|
||||
|
||||
vrequired_attrs = one_util::split(required_attrs, ',');
|
||||
|
||||
for ( std::vector<std::string>::const_iterator it = vrequired_attrs.begin();
|
||||
it != vrequired_attrs.end(); it++ )
|
||||
{
|
||||
required_attr = *it;
|
||||
|
||||
required_attr = one_util::trim(required_attr);
|
||||
one_util::toupper(required_attr);
|
||||
|
||||
get_template_attribute(required_attr.c_str(), value);
|
||||
|
||||
if ( value.empty() )
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
oss << "Datastore template is missing the \"" << required_attr
|
||||
<< "\" attribute or it's empty.";
|
||||
|
||||
error_str = oss.str();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Datastore::set_tm_mad(string &tm_mad, string &error_str)
|
||||
{
|
||||
const VectorAttribute* vatt;
|
||||
@ -420,6 +481,11 @@ int Datastore::insert(SqlDB *db, string& error_str)
|
||||
goto error_ds;
|
||||
}
|
||||
|
||||
if (set_ds_mad(ds_mad, error_str) != 0)
|
||||
{
|
||||
goto error_common;
|
||||
}
|
||||
|
||||
get_template_attribute("TM_MAD", tm_mad);
|
||||
|
||||
if ( tm_mad.empty() == true )
|
||||
|
@ -115,6 +115,34 @@ void OpenNebulaTemplate::set_multiple_conf_default()
|
||||
set_conf_tm("dev", "NONE", "NONE", "yes", "no");
|
||||
|
||||
register_multiple_conf_default("TM_MAD_CONF");
|
||||
|
||||
|
||||
/*
|
||||
#*******************************************************************************
|
||||
# Datastore Manager Configuration
|
||||
#*******************************************************************************
|
||||
# ceph
|
||||
# dev
|
||||
# dummy
|
||||
# fs
|
||||
# lvm
|
||||
# shared
|
||||
# ssh
|
||||
# vmfs
|
||||
#******
|
||||
*/
|
||||
|
||||
set_conf_ds("ceph",
|
||||
"DISK_TYPE,BRIDGE_LIST,CEPH_HOST,CEPH_USER,CEPH_SECRET");
|
||||
set_conf_ds("dev", "DISK_TYPE,ISCSI_HOST");
|
||||
set_conf_ds("dummy", "");
|
||||
set_conf_ds("fs", "");
|
||||
set_conf_ds("lvm", "DISK_TYPE");
|
||||
set_conf_ds("shared", "");
|
||||
set_conf_ds("ssh", "");
|
||||
set_conf_ds("vmfs", "BRIDGE_LIST");
|
||||
|
||||
register_multiple_conf_default("DS_MAD_CONF");
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@ -207,6 +235,21 @@ void OpenNebulaTemplate::set_conf_single(const std::string& attr,
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void OpenNebulaTemplate::set_conf_ds(const std::string& name,
|
||||
const std::string& required_attrs)
|
||||
{
|
||||
VectorAttribute * vattribute;
|
||||
map<string,string> vvalue;
|
||||
|
||||
vvalue.insert(make_pair("NAME", name));
|
||||
vvalue.insert(make_pair("REQUIRED_ATTRS", required_attrs));
|
||||
|
||||
vattribute = new VectorAttribute("DS_MAD_CONF", vvalue);
|
||||
conf_default.insert(make_pair(vattribute->name(), vattribute));
|
||||
}
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void OpenNebulaTemplate::set_conf_tm(const std::string& name,
|
||||
const std::string& ln_target,
|
||||
const std::string& clone_target,
|
||||
|
Loading…
x
Reference in New Issue
Block a user