| 188 | } |
| 189 | |
| 190 | static gboolean |
| 191 | unpack_template(xmlNode * xml_obj, xmlNode ** expanded_xml, pe_working_set_t * data_set) |
| 192 | { |
| 193 | xmlNode *cib_resources = NULL; |
| 194 | xmlNode *template = NULL; |
| 195 | xmlNode *new_xml = NULL; |
| 196 | xmlNode *child_xml = NULL; |
| 197 | xmlNode *rsc_ops = NULL; |
| 198 | xmlNode *template_ops = NULL; |
| 199 | const char *template_ref = NULL; |
| 200 | const char *id = NULL; |
| 201 | |
| 202 | if (xml_obj == NULL) { |
| 203 | pe_err("No resource object for template unpacking"); |
| 204 | return FALSE; |
| 205 | } |
| 206 | |
| 207 | template_ref = crm_element_value(xml_obj, XML_CIB_TAG_RSC_TEMPLATE); |
| 208 | if (template_ref == NULL) { |
| 209 | return TRUE; |
| 210 | } |
| 211 | |
| 212 | id = ID(xml_obj); |
| 213 | if (id == NULL) { |
| 214 | pe_err("'%s' object must have a id", crm_element_name(xml_obj)); |
| 215 | return FALSE; |
| 216 | } |
| 217 | |
| 218 | if (crm_str_eq(template_ref, id, TRUE)) { |
| 219 | pe_err("The resource object '%s' should not reference itself", id); |
| 220 | return FALSE; |
| 221 | } |
| 222 | |
| 223 | cib_resources = get_object_root(XML_CIB_TAG_RESOURCES, data_set->input); |
| 224 | if (cib_resources == NULL) { |
| 225 | pe_err("Cannot get the root of object '%s'", XML_CIB_TAG_RESOURCES); |
| 226 | return FALSE; |
| 227 | } |
| 228 | |
| 229 | template = find_entity(cib_resources, XML_CIB_TAG_RSC_TEMPLATE, template_ref); |
| 230 | if (template == NULL) { |
| 231 | pe_err("No template named '%s'", template_ref); |
| 232 | return FALSE; |
| 233 | } |
| 234 | |
| 235 | new_xml = copy_xml(template); |
| 236 | xmlNodeSetName(new_xml, xml_obj->name); |
| 237 | crm_xml_replace(new_xml, XML_ATTR_ID, id); |
| 238 | template_ops = find_xml_node(new_xml, "operations", FALSE); |
| 239 | |
| 240 | for (child_xml = __xml_first_child(xml_obj); child_xml != NULL; |
| 241 | child_xml = __xml_next(child_xml)) { |
| 242 | xmlNode *new_child = NULL; |
| 243 | |
| 244 | new_child = add_node_copy(new_xml, child_xml); |
| 245 | |
| 246 | if (crm_str_eq((const char *)new_child->name, "operations", TRUE)) { |
| 247 | rsc_ops = new_child; |
no test coverage detected