instance_attributes
objects for the resource and adding a rule to each, we can easily handle these special cases.
mySpecialRsc
will use eth1 and port 9999 when run on node1
, eth2 and port 8888 on node2
and default to eth0 and port 9999 for all other nodes.
Example 7.11. Defining different resource options based on the node name
<primitive id="mySpecialRsc" class="ocf" type="Special" provider="me"> <instance_attributes id="special-node1" score="3"> <rule id="node1-special-case" score="INFINITY" > <expression id="node1-special-case-expr" attribute="#uname" operation="eq" value="node1"/> </rule> <nvpair id="node1-interface" name="interface" value="eth1"/> </instance_attributes> <instance_attributes id="special-node2" score="2" > <rule id="node2-special-case" score="INFINITY"> <expression id="node2-special-case-expr" attribute="#uname" operation="eq" value="node2"/> </rule> <nvpair id="node2-interface" name="interface" value="eth2"/> <nvpair id="node2-port" name="port" value="8888"/> </instance_attributes> <instance_attributes id="defaults" score="1" > <nvpair id="default-interface" name="interface" value="eth0"/> <nvpair id="default-port" name="port" value="9999"/> </instance_attributes> </primitive>
instance_attributes
objects are evaluated is determined by their score (highest to lowest). If not supplied, score defaults to zero, and objects with an equal score are processed in listed order. If the instance_attributes
object has no rule or a rule
that evaluates to true
, then for any parameter the resource does not yet have a value for, the resource will use the parameter values defined by the instance_attributes
.
special-node1
has the highest score (3) and so is evaluated first; its rule evaluates to true
, so interface
is set to eth1
.
special-node2
is evaluated next with score 2, but its rule evaluates to false
, so it is ignored.
defaults
is evaluated last with score 1, and has no rule, so its values are examined; interface
is already defined, so the value here is not used, but port
is not yet defined, so port
is set to 9999
.