This source file includes following definitions.
- test_rule
- map_rule_input
- pe_eval_nvpairs
- pe_unpack_nvpairs
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <stdio.h>
13 #include <glib.h>
14 #include <libxml/tree.h>
15
16 #include <crm/crm.h>
17 #include <crm/common/iso8601.h>
18 #include <crm/common/roles.h>
19
20 #include <crm/common/xml.h>
21 #include <crm/common/rules.h>
22 #include <crm/common/nvpair_internal.h>
23
24 CRM_TRACE_INIT_DATA(pe_rules);
25
26
27
28
29 #include <crm/pengine/common_compat.h>
30 #include <crm/pengine/rules_compat.h>
31
32 gboolean
33 test_rule(xmlNode * rule, GHashTable * node_hash, enum rsc_role_e role, crm_time_t * now)
34 {
35 pcmk_rule_input_t rule_input = {
36 .node_attrs = node_hash,
37 .now = now,
38 };
39
40 return pcmk_evaluate_rule(rule, &rule_input, NULL) == pcmk_rc_ok;
41 }
42
43
44
45
46
47
48
49
50 static void
51 map_rule_input(pcmk_rule_input_t *new, const pe_rule_eval_data_t *old)
52 {
53 if (old == NULL) {
54 return;
55 }
56 new->now = old->now;
57 new->node_attrs = old->node_hash;
58 if (old->rsc_data != NULL) {
59 new->rsc_standard = old->rsc_data->standard;
60 new->rsc_provider = old->rsc_data->provider;
61 new->rsc_agent = old->rsc_data->agent;
62 }
63 if (old->match_data != NULL) {
64 new->rsc_params = old->match_data->params;
65 new->rsc_meta = old->match_data->meta;
66 if (old->match_data->re != NULL) {
67 new->rsc_id = old->match_data->re->string;
68 new->rsc_id_submatches = old->match_data->re->pmatch;
69 new->rsc_id_nmatches = old->match_data->re->nregs;
70 }
71 }
72 if (old->op_data != NULL) {
73 new->op_name = old->op_data->op_name;
74 new->op_interval_ms = old->op_data->interval;
75 }
76 }
77
78 void
79 pe_eval_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name,
80 const pe_rule_eval_data_t *rule_data, GHashTable *hash,
81 const char *always_first, gboolean overwrite,
82 crm_time_t *next_change)
83 {
84 GList *pairs = pcmk__xe_dereference_children(xml_obj, set_name);
85
86 if (pairs) {
87 pcmk__nvpair_unpack_t data = {
88 .values = hash,
89 .first_id = always_first,
90 .overwrite = overwrite,
91 .next_change = next_change,
92 };
93
94 map_rule_input(&(data.rule_input), rule_data);
95
96 pairs = g_list_sort_with_data(pairs, pcmk__cmp_nvpair_blocks, &data);
97 g_list_foreach(pairs, pcmk__unpack_nvpair_block, &data);
98 g_list_free(pairs);
99 }
100 }
101
102 void
103 pe_unpack_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name,
104 GHashTable *node_hash, GHashTable *hash,
105 const char *always_first, gboolean overwrite,
106 crm_time_t *now, crm_time_t *next_change)
107 {
108 pe_rule_eval_data_t rule_data = {
109 .node_hash = node_hash,
110 .now = now,
111 .match_data = NULL,
112 .rsc_data = NULL,
113 .op_data = NULL
114 };
115
116 pe_eval_nvpairs(NULL, xml_obj, set_name, &rule_data, hash,
117 always_first, overwrite, next_change);
118 }
119
120
121