Skip to content

Commit

Permalink
F OpenNebula#2427: Added AUTOMATIC_NIC_REQUIREMENTS
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmont committed Oct 25, 2018
1 parent 5acdf18 commit ff1ee5e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/scheduler/src/pool/VirtualMachineXML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void VirtualMachineXML::init_attributes()

string automatic_requirements;
string automatic_ds_requirements;
string automatic_nic_requirements;

xpath(oid, "/VM/ID", -1);
xpath(uid, "/VM/UID", -1);
Expand Down Expand Up @@ -101,6 +102,8 @@ void VirtualMachineXML::init_attributes()

// ------------------- NIC REQUIREMENTS -------------------------------------

xpath(automatic_nic_requirements, "/VM/TEMPLATE/AUTOMATIC_NIC_REQUIREMENTS", "");

if (get_nodes("/VM/TEMPLATE/NIC", nodes) > 0)
{
std::string net_mode;
Expand Down Expand Up @@ -131,6 +134,15 @@ void VirtualMachineXML::init_attributes()

if ( nic_template->get("SCHED_REQUIREMENTS", requirements) )
{
if ( !automatic_nic_requirements.empty() )
{
ostringstream oss;

oss << automatic_nic_requirements << " & ( " << requirements << " )";

requirements = oss.str();
}

the_nic->set_requirements(requirements);
}

Expand Down
13 changes: 12 additions & 1 deletion src/vm/VirtualMachine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ int VirtualMachine::automatic_requirements(set<int>& cluster_ids,

obj_template->erase("AUTOMATIC_REQUIREMENTS");
obj_template->erase("AUTOMATIC_DS_REQUIREMENTS");
obj_template->erase("AUTOMATIC_NIC_REQUIREMENTS");

int rc = get_cluster_requirements(obj_template, cluster_ids, error_str);

Expand Down Expand Up @@ -1625,6 +1626,8 @@ int VirtualMachine::automatic_requirements(set<int>& cluster_ids,

oss << ")";

obj_template->add("AUTOMATIC_NIC_REQUIREMENTS", oss.str());

if ( !datastore_ids.empty() )
{
oss << " & ";
Expand Down Expand Up @@ -2216,12 +2219,13 @@ string& VirtualMachine::to_xml_short(string& xml)
{
string disks_xml, monitoring_xml, user_template_xml, history_xml, nics_xml;
ostringstream oss;
string cpu_tmpl, mem_tmpl, auto_reqs, auto_ds_reqs;
string cpu_tmpl, mem_tmpl, auto_reqs, auto_ds_reqs, auto_nic_reqs;

obj_template->get("CPU", cpu_tmpl);
obj_template->get("MEMORY", mem_tmpl);
obj_template->get("AUTOMATIC_REQUIREMENTS", auto_reqs);
obj_template->get("AUTOMATIC_DS_REQUIREMENTS", auto_ds_reqs);
obj_template->get("AUTOMATIC_NIC_REQUIREMENTS", auto_nic_reqs);

oss << "<VM>"
<< "<ID>" << oid << "</ID>"
Expand Down Expand Up @@ -2265,6 +2269,13 @@ string& VirtualMachine::to_xml_short(string& xml)
oss << "</AUTOMATIC_DS_REQUIREMENTS>";
}

if (!auto_nic_reqs.empty())
{
oss << "<AUTOMATIC_NIC_REQUIREMENTS>";
oss << one_util::escape_xml(auto_nic_reqs);
oss << "</AUTOMATIC_NIC_REQUIREMENTS>";
}

oss << "</TEMPLATE>"
<< monitoring.to_xml_short(monitoring_xml)
<< user_obj_template->to_xml_short(user_template_xml);
Expand Down

0 comments on commit ff1ee5e

Please sign in to comment.