1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-26 06:50:09 +03:00

B #2246: Added new attribute for datastores to set compatible system datastores

Author: juanmont <juanmont@ucm.es>
This commit is contained in:
Ruben S. Montero 2018-09-14 21:15:58 +02:00
parent fb5cb1057c
commit 8fe6f55daa
5 changed files with 184 additions and 12 deletions

View File

@ -248,6 +248,18 @@ public:
*/
int enable(bool enable, string& error_str);
/**
* Return a set with compatible system ds for an image ds
*/
void get_compatible_system_ds(set<int> &compatible_sys_ds)
{
string compatible_sys_ds_str;
get_template_attribute("COMPATIBLE_SYS_DS", compatible_sys_ds_str);
one_util::split_unique(compatible_sys_ds_str, ',', compatible_sys_ds);
}
private:
// -------------------------------------------------------------------------

View File

@ -1010,7 +1010,12 @@ public:
* @param error_str Returns the error reason, if any
* @return 0 on success
*/
int automatic_requirements(set<int>& cluster_ids, string& error_str);
int automatic_requirements(set<int>& cluster_ids, string& error_str)
{
std::set<int> datastore_ids;
return automatic_requirements(cluster_ids, datastore_ids, error_str);
}
/**
* Checks if the resize parameters are valid
@ -2004,6 +2009,16 @@ private:
*/
int get_vmgroup(string& error);
/**
* Adds automatic placement requirements: Datastore and Cluster
* @param cluster_ids set of viable clusters for this VM
* @param ds_ids set of viable datastores for this VM
* @param error_str Returns the error reason, if any
* @return 0 on success
*/
int automatic_requirements(set<int>& cluster_ids, set<int>& ds_ids,
string& error_str);
// ------------------------------------------------------------------------
// Public cloud templates related functions
// ------------------------------------------------------------------------

View File

@ -208,6 +208,16 @@ define(function(require) {
_selectCustom(dialog);
break;
}
$("input[name='ds_type']", dialog).change(function() {
var value = $(this).val();
if ( value === "IMAGE_DS" ){
$(".only_img_ds", dialog).show();
} else {
$(".only_img_ds", dialog).hide();
}
});
$(".only_img_ds", dialog).show();
});
$('#presets', dialog).change();
@ -248,6 +258,7 @@ define(function(require) {
var iscsi_user = $('#iscsi_user', dialog).val();
var iscsi_usage = $('#iscsi_usage', dialog).val();
var vcenter_cluster = $('#vcenter_cluster', dialog).val();
var compatible_sys_ds = $('#compatible_sys_ds', dialog).val();
var ds_obj = {
"datastore" : {
@ -333,6 +344,9 @@ define(function(require) {
if (vcenter_cluster)
ds_obj.datastore.vcenter_cluster = vcenter_cluster;
if (compatible_sys_ds)
ds_obj.datastore.compatible_sys_ds = compatible_sys_ds;
Sunstone.runAction("Datastore.create", ds_obj);
return false;
}

View File

@ -250,6 +250,12 @@
</label>
<input type="text" name="staging_dir" id="staging_dir" />
</div>
<div class="medium-6 columns">
<label class="only_img_ds" for="compatible_sys_ds">
{{tr "Compatible system datastores"}}
</label>
<input class="only_img_ds" type="text" name="compatible_sys_ds" id="compatible_sys_ds" placeholder="0,100" />
</div>
<div class="medium-6 columns">
<label for="rbd_format">
{{tr "RBD format"}}

View File

@ -763,6 +763,7 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
long int ivalue;
float fvalue;
set<int> cluster_ids;
set<int> datastore_ids;
vector<Template *> quotas;
ostringstream oss;
@ -1015,7 +1016,7 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
goto error_requirements;
}
rc = automatic_requirements(cluster_ids, error_str);
rc = automatic_requirements(cluster_ids, datastore_ids, error_str);
if ( rc != 0 )
{
@ -1156,6 +1157,39 @@ error_common:
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
/**
* @return -1 for incompatible datastore IDs, -2 for missing datastore IDs
*/
static int check_and_set_datastores_id(const set<int> &csystem_ds,
set<int> &ds_ids)
{
if ( csystem_ds.empty() )
{
return -2;
}
if ( ds_ids.empty() )
{
ds_ids = csystem_ds;
return 0;
}
set<int> intersection = one_util::set_intersection(ds_ids, csystem_ds);
if (intersection.empty())
{
return -1;
}
ds_ids = intersection;
return 0;
}
/* ------------------------------------------------------------------------ */
/**
* @return -1 for incompatible cluster IDs, -2 for missing cluster IDs
*/
@ -1188,7 +1222,8 @@ static int check_and_set_cluster_id(
return 0;
}
set<int> intersection = one_util::set_intersection(cluster_ids, vatt_cluster_ids);
set<int> intersection = one_util::set_intersection(cluster_ids,
vatt_cluster_ids);
if (intersection.empty())
{
@ -1440,11 +1475,77 @@ error_common:
return -1;
}
/* ------------------------------------------------------------------------ */
/**
* Returns the list of Datastore IDs where the VM can be deployed, based
* on the images and his image datastores
*
* @param tmpl of the VirtualMachine
* @param datastore_ids set of Cluster IDs
* @param error_str Returns the error reason, if any
* @return 0 on success
*/
static int get_datastore_requirements(Template *tmpl, set<int>& ds_ids,
string& error_str)
{
ostringstream oss;
vector<VectorAttribute*> vatts;
set<int> csystem_ds;
DatastorePool * ds_pool = Nebula::instance().get_dspool();
int incomp_id;
// Get cluster id from all DISK vector attributes (IMAGE Datastore)
int num_vatts = tmpl->get("DISK",vatts);
for(int i=0; i<num_vatts; i++)
{
int val;
if (vatts[i]->vector_value("DATASTORE_ID", val) != 0)
{
continue;
}
Datastore * ds = ds_pool->get(val);
if ( ds != 0)
{
ds->get_compatible_system_ds(csystem_ds);
ds->unlock();
int rc = check_and_set_datastores_id(csystem_ds, ds_ids);
if ( rc != 0 )
{
incomp_id = i;
goto error_disk;
}
}
}
return 0;
error_disk:
oss << "Incompatible system datastore in DISK. Images Datastore for DISK "
<< incomp_id
<< " has not the same complatible system datastore"
<< "(system datastores " << one_util::join(ds_ids, ',') << ")";
error_str = oss.str();
return -1;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int VirtualMachine::automatic_requirements(set<int>& cluster_ids,
string& error_str)
set<int>& datastore_ids, string& error_str)
{
string tm_mad_system;
ostringstream oss;
@ -1460,6 +1561,8 @@ int VirtualMachine::automatic_requirements(set<int>& cluster_ids,
return -1;
}
rc = get_datastore_requirements(obj_template, datastore_ids, error_str);
if ( !cluster_ids.empty() )
{
set<int>::iterator i = cluster_ids.begin();
@ -1507,18 +1610,40 @@ int VirtualMachine::automatic_requirements(set<int>& cluster_ids,
// Set automatic System DS requirements
if ( !cluster_ids.empty() )
if ( !cluster_ids.empty() || !datastore_ids.empty() )
{
set<int>::iterator i = cluster_ids.begin();
oss << "(\"CLUSTERS/ID\" @> " << *i;
for (++i; i != cluster_ids.end(); i++)
if ( !cluster_ids.empty() )
{
oss << " | \"CLUSTERS/ID\" @> " << *i;
set<int>::iterator i = cluster_ids.begin();
oss << "(\"CLUSTERS/ID\" @> " << *i;
for (++i; i != cluster_ids.end(); i++)
{
oss << " | \"CLUSTERS/ID\" @> " << *i;
}
oss << ")";
if ( !datastore_ids.empty() )
{
oss << " & ";
}
}
oss << ")";
if ( !datastore_ids.empty() )
{
set<int>::iterator i = datastore_ids.begin();
oss << "(\"ID\" @> " << *i;
for (++i; i != datastore_ids.end(); i++)
{
oss << " | \"ID\" @> " << *i;
}
oss << ")";
}
obj_template->add("AUTOMATIC_DS_REQUIREMENTS", oss.str());
}