def set_deep_meta_attr_node(target_node, attr, value): nvpair_l = [] if xmlutil.is_clone(target_node): for c in target_node.iterchildren(): if xmlutil.is_child_rsc(c): rm_meta_attribute(c, attr, nvpair_l) if config.core.manage_children != "never" and \ (xmlutil.is_group(target_node) or (xmlutil.is_clone(target_node) and xmlutil.cloned_el(target_node) == "group")): odd_children = get_children_with_different_attr(target_node, attr, value) for c in odd_children: if config.core.manage_children == "always" or \ (config.core.manage_children == "ask" and utils.ask("Do you want to override %s for child resource %s?" % (attr, c.get("id")))): common_debug("force remove meta attr %s from %s" % (attr, c.get("id"))) rm_meta_attribute(c, attr, nvpair_l, force_children=True) xmlutil.rmnodes(list(set(nvpair_l))) xmlutil.xml_processnodes(target_node, xmlutil.is_emptynvpairs, xmlutil.rmnodes) # work around issue with pcs interoperability # by finding exising nvpairs -- if there are any, just # set the value in those. Otherwise fall back to adding # to all meta_attributes tags nvpairs = target_node.xpath("./meta_attributes/nvpair[@name='%s']" % (attr)) if len(nvpairs) > 0: for nvpair in nvpairs: nvpair.set("value", value) else: for n in xmlutil.get_set_nodes(target_node, "meta_attributes", 1): xmlutil.set_attr(n, attr, value) return True
def set_deep_meta_attr_node(target_node, attr, value): nvpair_l = [] if xmlutil.is_clone(target_node): for c in target_node.iterchildren(): if xmlutil.is_child_rsc(c): rm_meta_attribute(c, attr, nvpair_l) if config.core.manage_children != "never" and \ (xmlutil.is_group(target_node) or (xmlutil.is_clone(target_node) and xmlutil.cloned_el(target_node) == "group")): odd_children = get_children_with_different_attr(target_node, attr, value) for c in odd_children: if config.core.manage_children == "always" or \ (config.core.manage_children == "ask" and utils.ask("Do you want to override %s for child resource %s?" % (attr, c.get("id")))): common_debug("force remove meta attr %s from %s" % (attr, c.get("id"))) rm_meta_attribute(c, attr, nvpair_l, force_children=True) xmlutil.rmnodes(list(set(nvpair_l))) xmlutil.xml_processnodes(target_node, xmlutil.is_emptynvpairs, xmlutil.rmnodes) # work around issue with pcs interoperability # by finding exising nvpairs -- if there are any, just # set the value in those. Otherwise fall back to adding # to all meta_attributes tags nvpairs = target_node.xpath("./meta_attributes/nvpair[@name='%s']" % (attr)) if len(nvpairs) > 0: for nvpair in nvpairs: nvpair.set("value", value) else: for n in xmlutil.get_set_nodes(target_node, "meta_attributes", create=True): xmlutil.set_attr(n, attr, value) return True
def mock_commit_rsc(node): xmlutil.xml_processnodes(node, xmlutil.is_emptynvpairs, xmlutil.rmnodes) xmlutil.xml_processnodes(node, xmlutil.is_emptyops, xmlutil.rmnodes) print etree.tostring(node) assert 'name="target-role" value="Started"' in etree.tostring(node) return True