MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / inject_resource

Function inject_resource

tools/crm_simulate.c:214–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

212}
213
214static xmlNode *
215inject_resource(xmlNode * cib_node, const char *resource, const char *rclass, const char *rtype,
216 const char *rprovider)
217{
218 xmlNode *lrm = NULL;
219 xmlNode *container = NULL;
220 xmlNode *cib_resource = NULL;
221 char *xpath = NULL;
222
223 cib_resource = find_resource(cib_node, resource);
224 if (cib_resource != NULL) {
225 return cib_resource;
226 }
227
228 /* One day, add query for class, provider, type */
229
230 if (rclass == NULL || rtype == NULL) {
231 fprintf(stderr, "Resource %s not found in the status section of %s."
232 " Please supply the class and type to continue\n", resource, ID(cib_node));
233 return NULL;
234
235 } else if (safe_str_neq(rclass, "ocf")
236 && safe_str_neq(rclass, "stonith")
237 && safe_str_neq(rclass, "heartbeat")
238 && safe_str_neq(rclass, "lsb")) {
239 fprintf(stderr, "Invalid class for %s: %s\n", resource, rclass);
240 return NULL;
241
242 } else if (safe_str_eq(rclass, "ocf") && rprovider == NULL) {
243 fprintf(stderr, "Please specify the provider for resource %s\n", resource);
244 return NULL;
245 }
246
247 xpath = (char *)xmlGetNodePath(cib_node);
248 crm_info("Injecting new resource %s into %s '%s'", resource, xpath, ID(cib_node));
249 free(xpath);
250
251 lrm = first_named_child(cib_node, XML_CIB_TAG_LRM);
252 if (lrm == NULL) {
253 const char *node_uuid = ID(cib_node);
254
255 lrm = create_xml_node(cib_node, XML_CIB_TAG_LRM);
256 crm_xml_add(lrm, XML_ATTR_ID, node_uuid);
257 }
258
259 container = first_named_child(lrm, XML_LRM_TAG_RESOURCES);
260 if (container == NULL) {
261 container = create_xml_node(lrm, XML_LRM_TAG_RESOURCES);
262 }
263
264 cib_resource = create_xml_node(container, XML_LRM_TAG_RESOURCE);
265 crm_xml_add(cib_resource, XML_ATTR_ID, resource);
266
267 crm_xml_add(cib_resource, XML_AGENT_ATTR_CLASS, rclass);
268 crm_xml_add(cib_resource, XML_AGENT_ATTR_PROVIDER, rprovider);
269 crm_xml_add(cib_resource, XML_ATTR_TYPE, rtype);
270
271 return cib_resource;

Callers 2

exec_rsc_actionFunction · 0.85
modify_configurationFunction · 0.85

Calls 5

find_resourceFunction · 0.85
safe_str_neqFunction · 0.85
first_named_childFunction · 0.85
create_xml_nodeFunction · 0.85
crm_xml_addFunction · 0.85

Tested by

no test coverage detected