16.2. Configuring a Pacemaker location constraint using rules
Use the following command to configure a Pacemaker constraint that uses rules.
# pcs constraint location rsc rule[resource-discovery=option] [role=promoted|unpromoted] [score=score | score-attribute=attribute] expression
-
If
scoreis omitted, it defaults to INFINITY. -
When using rules to configure location constraints, the value of
scorecan be positive or negative, with a positive value indicating "prefers" and a negative value indicating "avoids". -
If
resource-discoveryis omitted, it defaults toalways. For information about theresource-discoveryoption, see Limiting resource discovery to a subset of nodes. - As with basic location constraints, you can use regular expressions for resources with these constraints as well.
The expression option in Pacemaker rules
The expression option can be one of the following where duration_options and date_spec_options are: hours, months, weeks, and years as described in the "Properties of a Date Specification" table in Pacemaker rules.
-
defined|not_defined attribute -
attribute lt|gt|lte|gte|eq|ne [string|integer|number|version] value -
date gt|lt date -
date in_range date to date -
date in_range date to duration duration_options … -
date-spec date_spec_options -
expression and|or expression -
(expression)
Durations in Pacemaker rules
Note that durations are an alternative way to specify an end for in_range operations by means of calculations. For example, you can specify a duration of 19 months. The supported values for duration options are seconds, minutes, hours, days, weeks, months, and years.
The following location constraint configures an expression that is true if now is any time in the year 2018.
# pcs constraint location Webserver rule score=INFINITY date-spec years=2018
The following command configures an expression that is true from 9 am to 5 pm, Monday through Friday. Note that the hours value of 16 matches up to 16:59:59, as the numeric value (hour) still matches.
# pcs constraint location Webserver rule score=INFINITY date-spec hours="9-16" weekdays="1-5"
The following command configures an expression that is true on Friday the thirteenth.
# pcs constraint location Webserver rule date-spec weekdays=5 monthdays=13