Exemplo n.º 1
0
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
Exemplo n.º 2
0
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)))

    # 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
Exemplo n.º 3
0
 def do_modgroup(self, context, group_id, subcmd, prim_id, *args):
     """usage: modgroup <id> add <id> [after <id>|before <id>]
     modgroup <id> remove <id>"""
     if subcmd not in ("add", "remove"):
         common_err("modgroup subcommand %s unknown" % subcmd)
         return False
     after_before = None
     if args:
         if subcmd != 'add':
             context.fatal_error("Expected add (found %s)" % subcmd)
         if args[0] not in ("after", "before"):
             context.fatal_error("Expected after|before (found %s)" %
                                 args[0])
         if len(args) != 2:
             context.fatal_error(
                 "Expected 'after|before <id>' (%d arguments given)" %
                 len(args))
         after_before = args[0]
         ref_member_id = args[1]
     g = cib_factory.find_object(group_id)
     if not g:
         context.fatal_error("group %s does not exist" % group_id)
     if not xmlutil.is_group(g.node):
         context.fatal_error("element %s is not a group" % group_id)
     children = xmlutil.get_rsc_children_ids(g.node)
     if after_before and ref_member_id not in children:
         context.fatal_error("%s is not member of %s" %
                             (ref_member_id, group_id))
     if subcmd == "remove" and prim_id not in children:
         context.fatal_error("%s is not member of %s" % (prim_id, group_id))
     # done checking arguments
     # have a group and children
     if not after_before:
         after_before = "after"
         ref_member_id = children[-1]
     # just do the filter
     # (i wonder if this is a feature abuse?)
     if subcmd == "add":
         if after_before == "after":
             sed_s = r's/ %s( |$)/& %s /' % (ref_member_id, prim_id)
         else:
             sed_s = r's/ %s( |$)/ %s& /' % (ref_member_id, prim_id)
     else:
         sed_s = r's/ %s( |$)/ /' % prim_id
     l = (group_id, )
     set_obj = mkset_obj(*l)
     return set_obj.filter("sed -r '%s'" % sed_s)
Exemplo n.º 4
0
 def do_modgroup(self, context, group_id, subcmd, prim_id, *args):
     """usage: modgroup <id> add <id> [after <id>|before <id>]
     modgroup <id> remove <id>"""
     if not cib_factory.is_cib_sane():
         context.fatal_error("CIB is not valid")
     if subcmd not in ("add", "remove"):
         common_err("modgroup subcommand %s unknown" % subcmd)
         return False
     after_before = None
     if args:
         if subcmd != 'add':
             context.fatal_error("Expected add (found %s)" % subcmd)
         if args[0] not in ("after", "before"):
             context.fatal_error("Expected after|before (found %s)" % args[0])
         if len(args) != 2:
             context.fatal_error("Expected 'after|before <id>' (%d arguments given)" %
                                 len(args))
         after_before = args[0]
         ref_member_id = args[1]
     g = cib_factory.find_object(group_id)
     if not g:
         context.fatal_error("group %s does not exist" % group_id)
     if not xmlutil.is_group(g.node):
         context.fatal_error("element %s is not a group" % group_id)
     children = xmlutil.get_rsc_children_ids(g.node)
     if after_before and ref_member_id not in children:
         context.fatal_error("%s is not member of %s" % (ref_member_id, group_id))
     if subcmd == "remove" and prim_id not in children:
         context.fatal_error("%s is not member of %s" % (prim_id, group_id))
     # done checking arguments
     # have a group and children
     if not after_before:
         after_before = "after"
         ref_member_id = children[-1]
     # just do the filter
     # (i wonder if this is a feature abuse?)
     if subcmd == "add":
         if after_before == "after":
             sed_s = r's/ %s( |$)/& %s /' % (ref_member_id, prim_id)
         else:
             sed_s = r's/ %s( |$)/ %s& /' % (ref_member_id, prim_id)
     else:
         sed_s = r's/ %s( |$)/ /' % prim_id
     l = (group_id,)
     set_obj = mkset_obj(*l)
     return set_obj.filter("sed -r '%s'" % sed_s)
Exemplo n.º 5
0
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)))
    for n in xmlutil.get_set_nodes(target_node, "meta_attributes", 1):
        xmlutil.set_attr(n, attr, value)
    return xmlutil.commit_rsc(target_node)