8.3. Using Rules to Determine Resource Location
If the constraint's outer-most rule evaluates to false, the cluster treats the constraint as if it was not there. When the rule evaluates to true, the node's preference for running the resource is updated with the score associated with the rule.
If this sounds familiar, its because you have been using a simplified syntax for location constraint rules already. Consider the following location constraint:
Example 8.8. Prevent myApacheRsc from running on c001n03
<rsc_location id="dont-run-apache-on-c001n03" rsc="myApacheRsc" score="-INFINITY" node="c001n03"/>
This constraint can be more verbosely written as:
Example 8.9. Prevent myApacheRsc from running on c001n03 - expanded version
<rsc_location id="dont-run-apache-on-c001n03" rsc="myApacheRsc">
<rule id="dont-run-apache-rule" score="-INFINITY">
<expression id="dont-run-apache-expr" attribute="#uname" operation="eq" value="c00n03"/>
</rule>
</rsc_location>
The advantage of using the expanded form is that one can then add extra clauses to the rule, such as limiting the rule such that it only applies during certain times of the day or days of the week (this is discussed in subsequent sections).
It also allows us to match on node properties other than its name. If we rated each machine's CPU power such that the cluster had the following nodes section:
Example 8.10. A sample nodes section for use with score-attribute
<nodes>
<node id="uuid1" uname="c001n01" type="normal">
<instance_attributes id="uuid1-custom_attrs">
<nvpair id="uuid1-cpu_mips" name="cpu_mips" value="1234"/>
</instance_attributes>
</node>
<node id="uuid2" uname="c001n02" type="normal">
<instance_attributes id="uuid2-custom_attrs">
<nvpair id="uuid2-cpu_mips" name="cpu_mips" value="5678"/>
</instance_attributes>
</node>
</nodes>
then we could prevent resources from running on underpowered machines with the rule
<rule id="need-more-power-rule" score="-INFINITY">
<expression id=" need-more-power-expr" attribute="cpu_mips" operation="lt" value="3000"/>
</rule>
8.3.1. Using score-attribute
Instead of score
When using score-attribute instead of score, each node matched by the rule has its score adjusted differently, according to its value for the named node attribute. Thus in the previous example, if a rule used score-attribute="cpu_mips"
, c001n01 would have its preference to run the resource increased by 1234 whereas c001n02 would have its preference increased by 5678.