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;
72 const char *score = NULL;
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,
103 if (score_a < score_b) {
105 }
else if (score_a > score_b) {
112 populate_hash(xmlNode *nvpair_list, GHashTable *hash,
bool overwrite)
114 const char *
name = NULL;
115 const char *value = NULL;
116 const char *old_value = NULL;
117 xmlNode *list = nvpair_list;
118 xmlNode *an_attr = NULL;
121 list = list->children;
125 an_attr != NULL; an_attr = pcmk__xe_next(an_attr)) {
131 if ((
name == NULL) && (ref_nvpair != NULL)) {
136 if ((value == NULL) && (ref_nvpair != NULL)) {
140 if (
name == NULL || value == NULL) {
144 old_value = g_hash_table_lookup(hash,
name);
149 "as %s) to the explicit value '#default' is " 150 "deprecated and will be removed in a future " 153 crm_trace(
"Letting %s default (removing explicit value \"%s\")",
155 g_hash_table_remove(hash,
name);
159 }
else if (old_value == NULL) {
163 }
else if (overwrite) {
164 crm_trace(
"Setting %s=\"%s\" (overwriting old value \"%s\")",
165 name, value, old_value);
173 unpack_attr_set(gpointer
data, gpointer user_data)
175 xmlNode *pair =
data;
183 crm_trace(
"Adding name/value pairs from %s %s overwrite",
184 pcmk__xe_id(pair), (unpack_data->
overwrite?
"with" :
"without"));
198 make_pairs(
const xmlNode *xml_obj,
const char *set_name)
200 GList *unsorted = NULL;
202 if (xml_obj == NULL) {
206 attr_set != NULL; attr_set = pcmk__xe_next(attr_set)) {
208 if ((set_name == NULL) || pcmk__xe_is(attr_set, set_name)) {
209 xmlNode *expanded_attr_set =
expand_idref(attr_set, NULL);
211 if (expanded_attr_set == NULL) {
214 unsorted = g_list_prepend(unsorted, expanded_attr_set);
235 const char *always_first, gboolean overwrite,
238 GList *pairs = make_pairs(xml_obj, set_name);
243 .first_id = always_first,
244 .overwrite = overwrite,
245 .next_change = next_change,
248 map_rule_input(&(
data.rule_input), rule_data);
250 pairs = g_list_sort_with_data(pairs, sort_pairs, &
data);
251 g_list_foreach(pairs, unpack_attr_set, &
data);
271 GHashTable *node_hash, GHashTable *hash,
272 const char *always_first, gboolean overwrite,
284 always_first, overwrite, next_change);
298 map_rule_input(&rule_input, rule_data);
325 if (match_data != NULL) {
328 if (match_data->
re != NULL) {
346 return pe_test_rule(rule, node_hash, role, now, NULL, NULL);
357 return pe_test_rule(rule, node_hash, role, now, NULL, &match_data);
364 return pe_test_rule(rule, node_hash, role, now, NULL, match_data);
374 .node_attrs = node_hash,
377 if (match_data != NULL) {
380 if (match_data->
re != NULL) {
421 map_rule_input(&rule_input, rule_data);
431 map_rule_input(&rule_input, rule_data);
438 GHashTable *node_hash, GHashTable *hash,
439 const char *always_first, gboolean overwrite,
450 pe_eval_nvpairs(NULL, xml_obj, set_name, &rule_data, hash, always_first,
463 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)
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)
int char2score(const char *score)
Get the integer value of a score string.
#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__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)