This source file includes following definitions.
- is_rsc_baremetal_remote_node
- is_baremetal_remote_node
- is_container_remote_node
- is_remote_node
- rsc_contains_remote_node
- xml_contains_remote_node
- pe_foreach_guest_node
- pe_create_remote_xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <crm_internal.h>
19 #include <crm/msg_xml.h>
20 #include <crm/common/xml.h>
21 #include <crm/pengine/internal.h>
22 #include <glib.h>
23
24 gboolean
25 is_rsc_baremetal_remote_node(resource_t *rsc, pe_working_set_t * data_set)
26 {
27 node_t *node;
28
29 if (rsc == NULL) {
30 return FALSE;
31 } else if (rsc->is_remote_node == FALSE) {
32 return FALSE;
33 }
34
35 node = pe_find_node(data_set->nodes, rsc->id);
36 if (node == NULL) {
37 return FALSE;
38 }
39
40 return is_baremetal_remote_node(node);
41 }
42
43 gboolean
44 is_baremetal_remote_node(node_t *node)
45 {
46 if (is_remote_node(node) && (node->details->remote_rsc == NULL || node->details->remote_rsc->container == FALSE)) {
47 return TRUE;
48 }
49 return FALSE;
50 }
51
52 gboolean
53 is_container_remote_node(node_t *node)
54 {
55 if (is_remote_node(node) && (node->details->remote_rsc && node->details->remote_rsc->container)) {
56 return TRUE;
57 }
58 return FALSE;
59 }
60
61 gboolean
62 is_remote_node(node_t *node)
63 {
64 if (node && node->details->type == node_remote) {
65 return TRUE;
66 }
67 return FALSE;
68 }
69
70 resource_t *
71 rsc_contains_remote_node(pe_working_set_t * data_set, resource_t *rsc)
72 {
73 if (is_set(data_set->flags, pe_flag_have_remote_nodes) == FALSE) {
74 return NULL;
75 }
76
77 if (rsc->fillers) {
78 GListPtr gIter = NULL;
79 for (gIter = rsc->fillers; gIter != NULL; gIter = gIter->next) {
80 resource_t *filler = (resource_t *) gIter->data;
81
82 if (filler->is_remote_node) {
83 return filler;
84 }
85 }
86 }
87 return NULL;
88 }
89
90 gboolean
91 xml_contains_remote_node(xmlNode *xml)
92 {
93 const char *class = crm_element_value(xml, XML_AGENT_ATTR_CLASS);
94 const char *provider = crm_element_value(xml, XML_AGENT_ATTR_PROVIDER);
95 const char *agent = crm_element_value(xml, XML_ATTR_TYPE);
96
97 if (safe_str_eq(agent, "remote") && safe_str_eq(provider, "pacemaker")
98 && safe_str_eq(class, PCMK_RESOURCE_CLASS_OCF)) {
99 return TRUE;
100 }
101 return FALSE;
102 }
103
104
105
106
107
108
109
110
111
112
113 void
114 pe_foreach_guest_node(const pe_working_set_t *data_set, const node_t *host,
115 void (*helper)(const node_t*, void*), void *user_data)
116 {
117 GListPtr iter;
118
119 CRM_CHECK(data_set && host && host->details && helper, return);
120 if (!is_set(data_set->flags, pe_flag_have_remote_nodes)) {
121 return;
122 }
123 for (iter = host->details->running_rsc; iter != NULL; iter = iter->next) {
124 resource_t *rsc = (resource_t *) iter->data;
125
126 if (rsc->is_remote_node && (rsc->container != NULL)) {
127 node_t *guest_node = pe_find_node(data_set->nodes, rsc->id);
128
129 if (guest_node) {
130 (*helper)(guest_node, user_data);
131 }
132 }
133 }
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157 xmlNode *
158 pe_create_remote_xml(xmlNode *parent, const char *uname,
159 const char *container_id, const char *migrateable,
160 const char *is_managed, const char *interval,
161 const char *monitor_timeout, const char *start_timeout,
162 const char *server, const char *port)
163 {
164 xmlNode *remote;
165 xmlNode *xml_sub;
166
167 remote = create_xml_node(parent, XML_CIB_TAG_RESOURCE);
168
169
170 crm_xml_add(remote, XML_ATTR_ID, uname);
171 crm_xml_add(remote, XML_AGENT_ATTR_CLASS, PCMK_RESOURCE_CLASS_OCF);
172 crm_xml_add(remote, XML_AGENT_ATTR_PROVIDER, "pacemaker");
173 crm_xml_add(remote, XML_ATTR_TYPE, "remote");
174
175
176 xml_sub = create_xml_node(remote, XML_TAG_META_SETS);
177 crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_META_SETS);
178 crm_create_nvpair_xml(xml_sub, NULL,
179 XML_RSC_ATTR_INTERNAL_RSC, XML_BOOLEAN_TRUE);
180 if (container_id) {
181 crm_create_nvpair_xml(xml_sub, NULL,
182 XML_RSC_ATTR_CONTAINER, container_id);
183 }
184 if (migrateable) {
185 crm_create_nvpair_xml(xml_sub, NULL,
186 XML_OP_ATTR_ALLOW_MIGRATE, migrateable);
187 }
188 if (is_managed) {
189 crm_create_nvpair_xml(xml_sub, NULL, XML_RSC_ATTR_MANAGED, is_managed);
190 }
191
192
193 if (port || server) {
194 xml_sub = create_xml_node(remote, XML_TAG_ATTR_SETS);
195 crm_xml_set_id(xml_sub, "%s-%s", uname, XML_TAG_ATTR_SETS);
196 if (server) {
197 crm_create_nvpair_xml(xml_sub, NULL, "addr", server);
198 }
199 if (port) {
200 crm_create_nvpair_xml(xml_sub, NULL, "port", port);
201 }
202 }
203
204
205 if (interval || start_timeout) {
206 xml_sub = create_xml_node(remote, "operations");
207 if (interval) {
208 crm_create_op_xml(xml_sub, uname, "monitor", interval,
209 monitor_timeout);
210 }
211 if (start_timeout) {
212 crm_create_op_xml(xml_sub, uname, "start", "0", start_timeout);
213 }
214 }
215 return remote;
216 }