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

Function template_to_set

pengine/constraints.c:1304–1374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1302}
1303
1304static gboolean
1305template_to_set(xmlNode *xml_obj, xmlNode **rsc_set, const char *attr,
1306 gboolean convert_rsc, pe_working_set_t *data_set)
1307{
1308 const char *cons_id = NULL;
1309 const char *id = NULL;
1310
1311 resource_t *rsc = NULL;
1312
1313 *rsc_set = NULL;
1314
1315 if(xml_obj == NULL) {
1316 crm_config_err("No constraint object to process.");
1317 return FALSE;
1318 }
1319
1320 if(attr == NULL) {
1321 crm_config_err("No attribute name to process.");
1322 return FALSE;
1323 }
1324
1325 cons_id = crm_element_value(xml_obj, XML_ATTR_ID);
1326 if(cons_id == NULL) {
1327 crm_config_err("%s constraint must have an id", crm_element_name(xml_obj));
1328 return FALSE;
1329 }
1330
1331 id = crm_element_value(xml_obj, attr);
1332 if(id == NULL) {
1333 return TRUE;
1334 }
1335
1336 rsc = pe_find_resource(data_set->resources, id);
1337 if(rsc == NULL) {
1338 xmlNode *template_rsc_set = g_hash_table_lookup(data_set->template_rsc_sets, id);
1339
1340 if(template_rsc_set == NULL) {
1341 crm_config_err("Invalid constraint '%s': No template named '%s'", cons_id, id);
1342 return FALSE;
1343 }
1344
1345 /* A template is referenced by the "attr" attribute (first, then, rsc or with-rsc).
1346 Add the template's corresponding "resource_set" which contains the primitives derived
1347 from it under the constraint. */
1348 *rsc_set = add_node_copy(xml_obj, template_rsc_set);
1349
1350 /* Set sequential="false" for the resource_set */
1351 crm_xml_add(*rsc_set, "sequential", XML_BOOLEAN_FALSE);
1352
1353 } else if(convert_rsc) {
1354 /* Even a regular resource is referenced by "attr", convert it into a resource_set.
1355 Because the other side of the constraint could be a template reference. */
1356 xmlNode *rsc_ref = NULL;
1357
1358 *rsc_set = create_xml_node(xml_obj, XML_CONS_TAG_RSC_SET);
1359 crm_xml_add(*rsc_set, XML_ATTR_ID, id);
1360
1361 rsc_ref = create_xml_node(*rsc_set, XML_TAG_RESOURCE_REF);

Callers 3

unpack_order_templateFunction · 0.85

Calls 6

crm_element_valueFunction · 0.85
pe_find_resourceFunction · 0.85
add_node_copyFunction · 0.85
crm_xml_addFunction · 0.85
create_xml_nodeFunction · 0.85
xml_remove_propFunction · 0.85

Tested by

no test coverage detected