diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 633e186516..55a12f7024 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1177,7 +1177,7 @@ private: int parse_context(string& error_str); /** - * Parse the "REQUIREMENTS" attribute of the template by substituting + * Parse the "SCHED_REQUIREMENTS" attribute of the template by substituting * $VARIABLE, $VARIABLE[ATTR] and $VARIABLE[ATTR, ATTR = VALUE] * @param error_str Returns the error reason, if any * @return 0 on success diff --git a/share/etc/oned.conf b/share/etc/oned.conf index f32a3254f0..548408c43d 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -491,6 +491,10 @@ DEFAULT_UMASK = 177 VM_RESTRICTED_ATTR = "CONTEXT/FILES" VM_RESTRICTED_ATTR = "NIC/MAC" VM_RESTRICTED_ATTR = "NIC/VLAN_ID" + VM_RESTRICTED_ATTR = "RANK" +VM_RESTRICTED_ATTR = "SCHED_RANK" +VM_RESTRICTED_ATTR = "REQUIREMENTS" +VM_RESTRICTED_ATTR = "SCHED_REQUIREMENTS" IMAGE_RESTRICTED_ATTR = "SOURCE" diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index fd4d3561a0..91195a2ad0 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -51,7 +51,7 @@ void VirtualMachineXML::init_attributes() cpu = 0; } - result = ((*this)["/VM/TEMPLATE/RANK"]); + result = ((*this)["/VM/USER_TEMPLATE/SCHED_RANK"]); if (result.size() > 0) { @@ -59,10 +59,20 @@ void VirtualMachineXML::init_attributes() } else { - rank = ""; + // Compatibility with previous versions + result = ((*this)["/VM/USER_TEMPLATE/RANK"]); + + if (result.size() > 0) + { + rank = result[0]; + } + else + { + rank = ""; + } } - result = ((*this)["/VM/TEMPLATE/REQUIREMENTS"]); + result = ((*this)["/VM/USER_TEMPLATE/SCHED_REQUIREMENTS"]); if (result.size() > 0) { diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index d1d30f6a13..e1b7dd3a8a 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -431,7 +431,7 @@ void Scheduler::match() matched = false; n_error++; - error_msg << "Error evaluating REQUIREMENTS expression: '" + error_msg << "Error evaluating SCHED_REQUIREMENTS expression: '" << reqs << "', error: " << error; oss << "VM " << oid << ": " << error_msg.str(); @@ -454,7 +454,7 @@ void Scheduler::match() ostringstream oss; oss << "VM " << oid << ": Host " << host->get_hid() << - " filtered out. It does not fulfill REQUIREMENTS."; + " filtered out. It does not fulfill SCHED_REQUIREMENTS."; NebulaLog::log("SCHED",Log::DEBUG,oss); continue; @@ -503,7 +503,7 @@ void Scheduler::match() } else if (n_matched == 0) { - vm->log("No host meets the REQUIREMENTS expression"); + vm->log("No host meets the SCHED_REQUIREMENTS expression"); } else { diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 8fd9bcfeaf..890c7088d5 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -785,7 +785,30 @@ int VirtualMachine::parse_requirements(string& error_str) string parsed; - num = user_obj_template->remove("REQUIREMENTS", array_reqs); + num = user_obj_template->remove("SCHED_REQUIREMENTS", array_reqs); + + if ( num == 0 ) // Compatibility with old REQUIREMENTS attribute + { + vector array_reqs_aux; + vector::iterator it; + + num = user_obj_template->remove("REQUIREMENTS", array_reqs_aux); + + // Rename att to SCHED_REQUIREMENTS + for (it = array_reqs_aux.begin(); it != array_reqs_aux.end(); it++) + { + reqs = dynamic_cast(*it); + + if (reqs != 0) + { + array_reqs.push_back( new SingleAttribute( + "SCHED_REQUIREMENTS", + reqs->value()) ); + } + + delete *it; + } + } if ( num == 0 ) { @@ -793,7 +816,7 @@ int VirtualMachine::parse_requirements(string& error_str) } else if ( num > 1 ) { - error_str = "Only one REQUIREMENTS attribute can be defined."; + error_str = "Only one SCHED_REQUIREMENTS attribute can be defined."; goto error_cleanup; } @@ -801,7 +824,7 @@ int VirtualMachine::parse_requirements(string& error_str) if ( reqs == 0 ) { - error_str = "Wrong format for REQUIREMENTS attribute."; + error_str = "Wrong format for SCHED_REQUIREMENTS attribute."; goto error_cleanup; } @@ -811,8 +834,8 @@ int VirtualMachine::parse_requirements(string& error_str) { SingleAttribute * reqs_parsed; - reqs_parsed = new SingleAttribute("REQUIREMENTS",parsed); - obj_template->set(reqs_parsed); + reqs_parsed = new SingleAttribute("SCHED_REQUIREMENTS",parsed); + user_obj_template->set(reqs_parsed); } /* --- Delete old requirements attributes --- */ @@ -974,15 +997,15 @@ int VirtualMachine::automatic_requirements(string& error_str) oss.str(""); oss << "CLUSTER_ID = " << cluster_id; - user_obj_template->get("REQUIREMENTS", requirements); - user_obj_template->erase("REQUIREMENTS"); + user_obj_template->get("SCHED_REQUIREMENTS", requirements); + user_obj_template->erase("SCHED_REQUIREMENTS"); if ( !requirements.empty() ) { oss << " & ( " << requirements << " )"; } - obj_template->add("REQUIREMENTS", oss.str()); + user_obj_template->add("SCHED_REQUIREMENTS", oss.str()); } return 0;