This source file includes following definitions.
- pcmk_cib_xpath_for
- pcmk__cib_abs_xpath_for
- pcmk_cib_parent_name_for
- pcmk_find_cib_element
- pcmk__check_feature_set
1
2
3
4
5
6
7
8
9
10
11 #include <crm_internal.h>
12
13 #include <stdio.h>
14 #include <libxml/tree.h>
15
16 #include <crm/common/xml.h>
17 #include <crm/common/cib.h>
18 #include <crm/common/cib_internal.h>
19
20
21
22
23
24
25 static struct {
26 const char *name;
27 const char *parent;
28 const char *path;
29 } cib_sections[] = {
30 {
31
32 PCMK_XE_CIB,
33 NULL,
34 "//" PCMK_XE_CIB
35 },
36 {
37 PCMK_XE_STATUS,
38 "/" PCMK_XE_CIB,
39 "//" PCMK_XE_CIB "/" PCMK_XE_STATUS
40 },
41 {
42 PCMK_XE_CONFIGURATION,
43 "/" PCMK_XE_CIB,
44 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION
45 },
46 {
47 PCMK_XE_CRM_CONFIG,
48 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
49 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_CRM_CONFIG
50 },
51 {
52 PCMK_XE_NODES,
53 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
54 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_NODES
55 },
56 {
57 PCMK_XE_RESOURCES,
58 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
59 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_RESOURCES
60 },
61 {
62 PCMK_XE_CONSTRAINTS,
63 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
64 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_CONSTRAINTS
65 },
66 {
67 PCMK_XE_OP_DEFAULTS,
68 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
69 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_OP_DEFAULTS
70 },
71 {
72 PCMK_XE_RSC_DEFAULTS,
73 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
74 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_RSC_DEFAULTS
75 },
76 {
77 PCMK_XE_ACLS,
78 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
79 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_ACLS
80 },
81 {
82 PCMK_XE_FENCING_TOPOLOGY,
83 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
84 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_FENCING_TOPOLOGY
85 },
86 {
87 PCMK_XE_TAGS,
88 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
89 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_TAGS
90 },
91 {
92 PCMK_XE_ALERTS,
93 "/" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION,
94 "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_ALERTS
95 },
96 {
97 PCMK__XE_ALL,
98 NULL,
99 "//" PCMK_XE_CIB
100 },
101 };
102
103
104
105
106
107
108
109
110
111 const char *
112 pcmk_cib_xpath_for(const char *element_name)
113 {
114 for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
115
116 if (pcmk__str_eq(element_name, cib_sections[lpc].name,
117 pcmk__str_null_matches)) {
118 return cib_sections[lpc].path;
119 }
120 }
121 return NULL;
122 }
123
124
125
126
127
128
129
130
131
132 const char *
133 pcmk__cib_abs_xpath_for(const char *element)
134 {
135 const char *xpath = pcmk_cib_xpath_for(element);
136
137
138 return ((xpath != NULL)? (xpath + 1) : NULL);
139 }
140
141
142
143
144
145
146
147
148
149 const char *
150 pcmk_cib_parent_name_for(const char *element_name)
151 {
152 for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
153
154 if (pcmk__str_eq(element_name, cib_sections[lpc].name,
155 pcmk__str_null_matches)) {
156 return cib_sections[lpc].parent;
157 }
158 }
159 return NULL;
160 }
161
162
163
164
165
166
167
168
169
170
171 xmlNode *
172 pcmk_find_cib_element(xmlNode *cib, const char *element_name)
173 {
174 return get_xpath_object(pcmk_cib_xpath_for(element_name), cib, LOG_TRACE);
175 }
176
177
178
179
180
181
182
183 int
184 pcmk__check_feature_set(const char *cib_version)
185 {
186 if (cib_version && compare_version(cib_version, CRM_FEATURE_SET) > 0) {
187 return EPROTONOSUPPORT;
188 }
189
190 return pcmk_rc_ok;
191 }