25 #include <sys/types.h> 66 sort_pairs(gconstpointer a, gconstpointer b, gpointer user_data)
68 const xmlNode *pair_a = a;
69 const xmlNode *pair_b = b;
76 if (a == NULL && b == NULL) {
78 }
else if (a == NULL) {
80 }
else if (b == NULL) {
84 if (pcmk__str_eq(pcmk__xe_id(pair_a), unpack_data->
first_id,
88 }
else if (pcmk__str_eq(pcmk__xe_id(pair_b), unpack_data->
first_id,
96 "is not a valid score: %s",
105 "is not a valid score: %s",
115 if (score_a < score_b) {
117 }
else if (score_a > score_b) {
124 populate_hash(xmlNode *nvpair_list, GHashTable *hash,
bool overwrite)
126 const char *
name = NULL;
127 const char *value = NULL;
128 const char *old_value = NULL;
129 xmlNode *list = nvpair_list;
130 xmlNode *an_attr = NULL;
133 list = list->children;
137 an_attr != NULL; an_attr = pcmk__xe_next(an_attr)) {
143 if ((
name == NULL) && (ref_nvpair != NULL)) {
148 if ((value == NULL) && (ref_nvpair != NULL)) {
152 if (
name == NULL || value == NULL) {
156 old_value = g_hash_table_lookup(hash,
name);
161 "as %s) to the explicit value '#default' is " 162 "deprecated and will be removed in a future " 165 crm_trace(
"Letting %s default (removing explicit value \"%s\")",
167 g_hash_table_remove(hash,
name);
171 }
else if (old_value == NULL) {
175 }
else if (overwrite) {
176 crm_trace(
"Setting %s=\"%s\" (overwriting old value \"%s\")",
177 name, value, old_value);
185 unpack_attr_set(gpointer
data, gpointer user_data)
187 xmlNode *pair =
data;
195 crm_trace(
"Adding name/value pairs from %s %s overwrite",
196 pcmk__xe_id(pair), (unpack_data->
overwrite?
"with" :
"without"));
210 make_pairs(
const xmlNode *xml_obj,
const char *set_name)
212 GList *unsorted = NULL;
214 if (xml_obj == NULL) {
218 attr_set != NULL; attr_set = pcmk__xe_next(attr_set)) {
220 if ((set_name == NULL) || pcmk__xe_is(attr_set, set_name)) {
221 xmlNode *expanded_attr_set =
expand_idref(attr_set, NULL);
223 if (expanded_attr_set == NULL) {
226 unsorted = g_list_prepend(unsorted, expanded_attr_set);
247 const char *always_first, gboolean overwrite,
250 GList *pairs = make_pairs(xml_obj, set_name);
255 .first_id = always_first,
256 .overwrite = overwrite,
257 .next_change = next_change,
260 map_rule_input(&(
data.rule_input), rule_data);
262 pairs = g_list_sort_with_data(pairs, sort_pairs, &
data);
263 g_list_foreach(pairs, unpack_attr_set, &
data);
283 GHashTable *node_hash, GHashTable *hash,
284 const char *always_first, gboolean overwrite,
296 always_first, overwrite, next_change);
310 map_rule_input(&rule_input, rule_data);
337 if (match_data != NULL) {
340 if (match_data->
re != NULL) {
358 return pe_test_rule(rule, node_hash, role, now, NULL, NULL);
369 return pe_test_rule(rule, node_hash, role, now, NULL, &match_data);
376 return pe_test_rule(rule, node_hash, role, now, NULL, match_data);
386 .node_attrs = node_hash,
389 if (match_data != NULL) {
392 if (match_data->
re != NULL) {
433 map_rule_input(&rule_input, rule_data);
443 map_rule_input(&rule_input, rule_data);
450 GHashTable *node_hash, GHashTable *hash,
451 const char *always_first, gboolean overwrite,
462 pe_eval_nvpairs(NULL, xml_obj, set_name, &rule_data, hash, always_first,
475 if (match_data == NULL) {
void pe_unpack_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now, crm_time_t *next_change)
Extract nvpair blocks contained by an XML element into a hash table.
int pcmk_evaluate_rule(xmlNode *rule, const pcmk_rule_input_t *rule_input, crm_time_t *next_change)
Evaluate a single rule, including all its conditions.
gboolean pe_test_rule(xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, crm_time_t *next_change, pe_match_data_t *match_data)
Deprecated Pacemaker rule API.
enum expression_type pcmk__condition_type(const xmlNode *condition)
gboolean pe_test_rule_re(xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, pe_re_match_data_t *re_match_data)
struct crm_time_s crm_time_t
#define pcmk__config_warn(fmt...)
#define PCMK__XE_ATTRIBUTES
CRM_TRACE_INIT_DATA(pe_rules)
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
gboolean pe_test_expression_re(xmlNode *expr, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, pe_re_match_data_t *re_match_data)
pe_match_data_t * match_data
pe_op_eval_data_t * op_data
gboolean pe_eval_rules(xmlNode *ruleset, const pe_rule_eval_data_t *rule_data, crm_time_t *next_change)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
#define crm_trace(fmt, args...)
gboolean pe_test_expression(xmlNode *expr, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, crm_time_t *next_change, pe_match_data_t *match_data)
xmlNode * expand_idref(xmlNode *input, xmlNode *top)
gboolean pe_eval_expr(xmlNode *rule, const pe_rule_eval_data_t *rule_data, crm_time_t *next_change)
gboolean test_rule(xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now)
Wrappers for and extensions to libxml2.
gboolean pe_test_rule_full(xmlNode *rule, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, pe_match_data_t *match_data)
gboolean pe_evaluate_rules(xmlNode *ruleset, GHashTable *node_hash, crm_time_t *now, crm_time_t *next_change)
int pcmk__evaluate_condition(xmlNode *condition, const pcmk_rule_input_t *rule_input, crm_time_t *next_change)
pe_rsc_eval_data_t * rsc_data
void populate_hash(xmlNode *nvpair_list, GHashTable *hash, const char **attrs, int attrs_length)
gboolean pe_eval_subexpr(xmlNode *expr, const pe_rule_eval_data_t *rule_data, crm_time_t *next_change)
gboolean pe_test_expression_full(xmlNode *expr, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now, pe_match_data_t *match_data)
char * pcmk__replace_submatches(const char *string, const char *match, const regmatch_t submatches[], int nmatches)
char * pe_expand_re_matches(const char *string, const pe_re_match_data_t *match_data)
int pcmk__xe_get_score(const xmlNode *xml, const char *name, int *score, int default_score)
int pcmk__evaluate_rules(xmlNode *xml, const pcmk_rule_input_t *rule_input, crm_time_t *next_change)
enum expression_type find_expression_type(xmlNode *expr)
pcmk_rule_input_t rule_input
gboolean test_expression(xmlNode *expr, GHashTable *node_hash, enum rsc_role_e role, crm_time_t *now)
void unpack_instance_attributes(xmlNode *top, xmlNode *xml_obj, const char *set_name, GHashTable *node_hash, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *now)
gboolean test_ruleset(xmlNode *ruleset, GHashTable *node_hash, crm_time_t *now)
void pe_eval_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, const pe_rule_eval_data_t *rule_data, GHashTable *hash, const char *always_first, gboolean overwrite, crm_time_t *next_change)
Extract nvpair blocks contained by an XML element into a hash table.
void pcmk__insert_dup(GHashTable *table, const char *name, const char *value)