当前位置: 首页>>代码示例>>Python>>正文


Python utils.find_unique_id函数代码示例

本文整理汇总了Python中utils.find_unique_id函数的典型用法代码示例。如果您正苦于以下问题:Python find_unique_id函数的具体用法?Python find_unique_id怎么用?Python find_unique_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了find_unique_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: colocation_set

def colocation_set(argv):
    setoptions = []
    for i in range(len(argv)):
        if argv[i] == "setoptions":
            setoptions = argv[i+1:]
            argv[i:] = []
            break

    current_set = set_args_into_array(argv)
    colocation_id = "pcs_rsc_colocation"
    for a in argv:
        if a.find('=') == -1:
            colocation_id = colocation_id + "_" + a

    cib = utils.get_cib_etree()
    constraints = cib.find(".//constraints")
    if constraints == None:
        constraints = ET.SubElement(cib, "constraints")
    rsc_colocation = ET.SubElement(constraints,"rsc_colocation")
    rsc_colocation.set("id", utils.find_unique_id(cib,colocation_id))
    rsc_colocation.set("score","INFINITY")
    for opt in setoptions:
        if opt.find("=") != -1:
            name,value = opt.split("=")
            rsc_colocation.set(name,value)
    set_add_resource_sets(rsc_colocation, current_set, cib)
    utils.replace_cib_configuration(cib)
开发者ID:BillTheBest,项目名称:pcs,代码行数:27,代码来源:constraint.py

示例2: set_add_resource_sets

def set_add_resource_sets(elem, sets, cib):
    allowed_options = {
        "sequential": ("true", "false"),
        "require-all": ("true", "false"),
        "action" : ("start", "promote", "demote", "stop"),
        "role" : ("Stopped", "Started", "Master", "Slave"),
    }

    for o_set in sets:
        set_id = "pcs_rsc_set"
        res_set = ET.SubElement(elem,"resource_set")
        for opts in o_set:
            if opts.find("=") != -1:
                key,val = opts.split("=")
                if key not in allowed_options:
                    utils.err(
                        "invalid option '%s', allowed options are: %s"
                        % (key, ", ".join(allowed_options.keys()))
                    )
                if val not in allowed_options[key]:
                    utils.err(
                        "invalid value '%s' of option '%s', allowed values are: %s"
                        % (val, key, ", ".join(allowed_options[key]))
                    )
                res_set.set(key,val)
            else:
                se = ET.SubElement(res_set,"resource_ref")
                se.set("id",opts)
                set_id = set_id + "_" + opts
        res_set.set("id", utils.find_unique_id(cib,set_id))
开发者ID:vincepii,项目名称:pcs,代码行数:30,代码来源:constraint.py

示例3: stonith_level_add

def stonith_level_add(level, node, devices):
    dom = utils.get_cib_dom()

    if not "--force" in utils.pcs_options:
        for dev in devices.split(","):
            if not utils.is_stonith_resource(dev):
                utils.err("%s is not a stonith id (use --force to override)" % dev)
        if not utils.is_pacemaker_node(node) and not utils.is_corosync_node(node):
            utils.err("%s is not currently a node (use --force to override)" % node)

    ft = dom.getElementsByTagName("fencing-topology")
    if len(ft) == 0:
        conf = dom.getElementsByTagName("configuration")[0]
        ft = dom.createElement("fencing-topology")
        conf.appendChild(ft)
    else:
        ft = ft[0]

    fls = ft.getElementsByTagName("fencing-level")
    for fl in fls:
        if fl.getAttribute("target") == node and fl.getAttribute("index") == level and fl.getAttribute("devices") == devices:
            utils.err("unable to add fencing level, fencing level for node: %s, at level: %s, with device: %s already exists" % (node,level,devices))

    new_fl = dom.createElement("fencing-level")
    ft.appendChild(new_fl)
    new_fl.setAttribute("target", node)
    new_fl.setAttribute("index", level)
    new_fl.setAttribute("devices", devices)
    new_fl.setAttribute("id", utils.find_unique_id(dom, "fl-" + node +"-" + level))

    utils.replace_cib_configuration(dom)
开发者ID:ClaudiuPID,项目名称:pcs,代码行数:31,代码来源:stonith.py

示例4: acl_permission

def acl_permission(argv):
    if len(argv) < 1:
        usage.acl("permission")
        sys.exit(1)

    dom = utils.get_cib_dom()
    dom, acls = get_acls(dom)

    command = argv.pop(0)
    if command == "add":
        if len(argv) < 4:
            usage.acl("permission add")
            sys.exit(1)
        role_id = argv.pop(0)
        found = False
        for role in dom.getElementsByTagName("acl_role"):
            if role.getAttribute("id") == role_id:
                found = True
                break
        if found == False:
            acl_role(["create", role_id] + argv) 
            return

        while len(argv) >= 3:
            kind = argv.pop(0)
            se = dom.createElement("acl_permission")
            se.setAttribute("id", utils.find_unique_id(dom, role_id + "-" + kind))
            se.setAttribute("kind", kind)
            xp_id = argv.pop(0)
            if xp_id == "xpath":
                xpath_query = argv.pop(0)
                se.setAttribute("xpath",xpath_query)
            elif xp_id == "id":
                acl_ref = argv.pop(0)
                se.setAttribute("reference",acl_ref)
            else:
                usage.acl("permission add")
            role.appendChild(se)

        utils.replace_cib_configuration(dom)

    elif command == "delete":
        if len(argv) < 1:
            usage.acl("permission delete")
            sys.exit(1)

        perm_id = argv.pop(0)
        found = False
        for elem in dom.getElementsByTagName("acl_permission"):
            if elem.getAttribute("id") == perm_id:
                elem.parentNode.removeChild(elem)
                found = True
        if not found:
            utils.err("Unable to find permission with id: %s" % perm_id)

        utils.replace_cib_configuration(dom)

    else:
        usage.acl("permission")
        sys.exit(1)
开发者ID:MichalCab,项目名称:pcs,代码行数:60,代码来源:acl.py

示例5: location_rule

def location_rule(argv):
    if len(argv) < 3:
        usage.constraint("location rule")
        sys.exit(1)
    
    res_name = argv.pop(0)
    resource_valid, resource_error = utils.validate_constraint_resource(
        utils.get_cib_dom(), res_name
    )
    if not resource_valid:
        utils.err(resource_error)

    argv.pop(0)

    cib = utils.get_cib_dom()
    constraints = cib.getElementsByTagName("constraints")[0]
    lc = cib.createElement("rsc_location")
    constraints.appendChild(lc)
    lc_id = utils.find_unique_id(cib, "location-" + res_name)
    lc.setAttribute("id", lc_id)
    lc.setAttribute("rsc", res_name)

    rule_utils.dom_rule_add(lc, argv)

    utils.replace_cib_configuration(cib)
开发者ID:MichalCab,项目名称:pcs,代码行数:25,代码来源:constraint.py

示例6: colocation_add

def colocation_add(argv):
    if len(argv) < 2:
        usage.constraint()
        sys.exit(1)

    resource1 = argv.pop(0)
    resource2 = argv.pop(0)

    if not utils.does_resource_exist(resource1):
        print "Error: Resource '" + resource1 + "' does not exist"
        sys.exit(1)

    if not utils.does_resource_exist(resource2):
        print "Error: Resource '" + resource2 + "' does not exist"
        sys.exit(1)

    score,nv_pairs = parse_score_options(argv)

    (dom,constraintsElement) = getCurrentConstraints()
    cl_id = utils.find_unique_id(dom, "colocation-" + resource1 + "-" +
            resource2 + "-" + score)

    element = dom.createElement("rsc_colocation")
    element.setAttribute("id",cl_id)
    element.setAttribute("rsc",resource1)
    element.setAttribute("with-rsc",resource2)
    element.setAttribute("score",score)
    for nv_pair in nv_pairs:
        element.setAttribute(nv_pair[0], nv_pair[1])
    constraintsElement.appendChild(element)
    xml_constraint_string = constraintsElement.toxml()
    args = ["cibadmin", "-c", "-R", "--xml-text", xml_constraint_string]
    output,retval = utils.run(args)
    if output != "":
        print output
开发者ID:ckesselh,项目名称:pcs,代码行数:35,代码来源:constraint.py

示例7: order_set

def order_set(argv):
    current_set = set_args_into_array(argv)
    cib = utils.get_cib_etree()
    constraints = cib.find(".//constraints")
    if constraints == None:
        constraints = ET.SubElement(cib, "constraints")
    rsc_order = ET.SubElement(constraints,"rsc_order")
    rsc_order.set("id", utils.find_unique_id(cib,"pcs_rsc_order"))
    set_add_resource_sets(rsc_order, current_set, cib)
    utils.replace_cib_configuration(cib)
开发者ID:FumihiroSaito,项目名称:pcs,代码行数:10,代码来源:constraint.py

示例8: set_add_resource_sets

def set_add_resource_sets(elem, sets, cib):
    for o_set in sets:
        res_set = ET.SubElement(elem,"resource_set")
        res_set.set("id", utils.find_unique_id(cib,"pcs_rsc_set"))
        for opts in o_set:
            if opts.find("=") != -1:
                key,val = opts.split("=")
                res_set.set(key,val)
            else:
                se = ET.SubElement(res_set,"resource_ref")
                se.set("id",opts)
开发者ID:FumihiroSaito,项目名称:pcs,代码行数:11,代码来源:constraint.py

示例9: location_rule

def location_rule(argv):
    if len(argv) < 3:
        usage.constraint(["location", "rule"])
        sys.exit(1)
    
    res_name = argv.pop(0)
    resource_valid, resource_error, correct_id \
        = utils.validate_constraint_resource(utils.get_cib_dom(), res_name)
    if "--autocorrect" in utils.pcs_options and correct_id:
        res_name = correct_id
    elif not resource_valid:
        utils.err(resource_error)

    argv.pop(0) # pop "rule"

    options, rule_argv = rule_utils.parse_argv(argv, {"constraint-id": None, "resource-discovery": None,})

    # If resource-discovery is specified, we use it with the rsc_location
    # element not the rule
    if "resource-discovery" in options and options["resource-discovery"]:
        utils.checkAndUpgradeCIB(2,2,0)
        cib, constraints = getCurrentConstraints(utils.get_cib_dom())
        lc = cib.createElement("rsc_location")
        lc.setAttribute("resource-discovery", options.pop("resource-discovery"))
    else:
        cib, constraints = getCurrentConstraints(utils.get_cib_dom())
        lc = cib.createElement("rsc_location")


    constraints.appendChild(lc)
    if options.get("constraint-id"):
        id_valid, id_error = utils.validate_xml_id(
            options["constraint-id"], 'constraint id'
        )
        if not id_valid:
            utils.err(id_error)
        if utils.does_id_exist(cib, options["constraint-id"]):
            utils.err(
                "id '%s' is already in use, please specify another one"
                % options["constraint-id"]
            )
        lc.setAttribute("id", options["constraint-id"])
        del options["constraint-id"]
    else:
        lc.setAttribute("id", utils.find_unique_id(cib, "location-" + res_name))
    lc.setAttribute("rsc", res_name)

    rule_utils.dom_rule_add(lc, options, rule_argv)
    location_rule_check_duplicates(constraints, lc)
    utils.replace_cib_configuration(cib)
开发者ID:akanouras,项目名称:pcs,代码行数:50,代码来源:constraint.py

示例10: order_set

def order_set(argv):
    current_set = set_args_into_array(argv)

    order_id = "pcs_rsc_order"
    for a in argv:
        if a.find('=') == -1:
            order_id = order_id + "_" + a

    cib, constraints = getCurrentConstraints(utils.get_cib_dom())
    rsc_order = cib.createElement("rsc_order")
    constraints.appendChild(rsc_order)
    rsc_order.setAttribute("id", utils.find_unique_id(cib, order_id))
    set_add_resource_sets(rsc_order, current_set, cib)
    utils.replace_cib_configuration(cib)
开发者ID:MichalCab,项目名称:pcs,代码行数:14,代码来源:constraint.py

示例11: set_add_resource_sets

def set_add_resource_sets(elem, sets, cib):
    allowed_options = {
        "sequential": ("true", "false"),
        "require-all": ("true", "false"),
        "action" : OPTIONS_ACTION,
        "role" : OPTIONS_ROLE,
    }

    for o_set in sets:
        set_id = "pcs_rsc_set"
        res_set = cib.createElement("resource_set")
        elem.appendChild(res_set)
        for opts in o_set:
            if opts.find("=") != -1:
                key,val = opts.split("=")
                if key not in allowed_options:
                    utils.err(
                        "invalid option '%s', allowed options are: %s"
                        % (key, ", ".join(allowed_options.keys()))
                    )
                if val not in allowed_options[key]:
                    utils.err(
                        "invalid value '%s' of option '%s', allowed values are: %s"
                        % (val, key, ", ".join(allowed_options[key]))
                    )
                res_set.setAttribute(key, val)
            else:
                res_valid, res_error, correct_id \
                    = utils.validate_constraint_resource(cib, opts)
                if "--autocorrect" in utils.pcs_options and correct_id:
                    opts = correct_id
                elif not res_valid:
                    utils.err(res_error)
                se = cib.createElement("resource_ref")
                res_set.appendChild(se)
                se.setAttribute("id", opts)
                set_id = set_id + "_" + opts
        res_set.setAttribute("id", utils.find_unique_id(cib, set_id))
    if "--force" not in utils.pcs_options:
        duplicates = set_constraint_find_duplicates(cib, elem)
        if duplicates:
            utils.err(
                "duplicate constraint already exists, use --force to override\n"
                + "\n".join([
                    "  " + set_constraint_el_to_string(dup, True)
                    for dup in duplicates
                ])
            )
开发者ID:akanouras,项目名称:pcs,代码行数:48,代码来源:constraint.py

示例12: resource_operation_add

def resource_operation_add(res_id, argv):
    if len(argv) < 1:
        usage.resource()
        sys.exit(1)

    op_name = argv.pop(0)
    dom = utils.get_cib_dom()
    resource_found = False

    for resource in dom.getElementsByTagName("primitive"):
        if resource.getAttribute("id") == res_id:
            resource_found = True
            break

    if not resource_found:
        print "Unable to find resource: %s" % res_id
        sys.exit(1)

    op_properties = convert_args_to_tuples(argv)
    op_properties.sort(key=lambda a:a[0])
    op_properties.insert(0,('name', op_name))
    found_match = False

    op = dom.createElement("op")
    op_id = res_id + "-"
    for prop in op_properties:
        op.setAttribute(prop[0], prop[1])
        op_id += prop[0] + "-" + prop[1] + "-"
    op_id = op_id[:-1]
    op_id = utils.find_unique_id(dom, op_id)
    op.setAttribute("id", op_id)

    operations = resource.getElementsByTagName("operations")
    if len(operations) == 0:
        operations = dom.createElement("operations")
        resource.appendChild(operations)
    else:
        operations = operations[0]

    if utils.operation_exists(operations,op):
        print "Error: identical operation already exists for %s" % res_id
        sys.exit(1)

    operations.appendChild(op)
    utils.replace_cib_configuration(dom)
开发者ID:lyon667,项目名称:pcs,代码行数:45,代码来源:resource.py

示例13: location_rule

def location_rule(argv):
    if len(argv) < 3:
        usage.constraint("location rule")
        sys.exit(1)
    
    res_name = argv.pop(0)
    argv.pop(0)

    cib = utils.get_cib_etree()
    constraints = cib.find(".//constraints")
    lc = ET.SubElement(constraints,"rsc_location")
    lc_id = utils.find_unique_id(cib, "location-" + res_name)
    lc.set("id", lc_id)
    lc.set("rsc", res_name)

    utils.rule_add(lc, argv)

    utils.replace_cib_configuration(cib)
开发者ID:FumihiroSaito,项目名称:pcs,代码行数:18,代码来源:constraint.py

示例14: location_rule

def location_rule(argv):
    if len(argv) < 3:
        usage.constraint("location rule")
        sys.exit(1)
    
    res_name = argv.pop(0)

    (dom, constraintsElement) = getCurrentConstraints()

    lc = dom.createElement("rsc_location")
    lc_id = utils.find_unique_id(dom, "location-" + res_name)
    lc.setAttribute("id", lc_id)
    lc.setAttribute("rsc", res_name)

    rule = utils.getRule(dom, lc, argv)
    lc.appendChild(rule)
    constraintsElement.appendChild(lc)

    utils.replace_cib_configuration(dom)
开发者ID:adrianlzt,项目名称:pcs,代码行数:19,代码来源:constraint.py

示例15: colocation_set

def colocation_set(argv):
    setoptions = []
    for i in range(len(argv)):
        if argv[i] == "setoptions":
            setoptions = argv[i+1:]
            argv[i:] = []
            break

    current_set = set_args_into_array(argv)
    colocation_id = "pcs_rsc_colocation"
    for a in argv:
        if a.find('=') == -1:
            colocation_id = colocation_id + "_" + a

    cib = utils.get_cib_etree()
    constraints = cib.find(".//constraints")
    if constraints == None:
        constraints = ET.SubElement(cib, "constraints")
    rsc_colocation = ET.SubElement(constraints,"rsc_colocation")
    rsc_colocation.set("id", utils.find_unique_id(cib,colocation_id))
    rsc_colocation.set("score","INFINITY")
    score_options = ("score", "score-attribute", "score-attribute-mangle")
    score_specified = False
    for opt in setoptions:
        if opt.find("=") != -1:
            name,value = opt.split("=")
            if name not in score_options:
                utils.err(
                    "invalid option '%s', allowed options are: %s"
                    % (name, ", ".join(score_options))
                )
            if score_specified:
                utils.err("you cannot specify multiple score options")
            score_specified = True
            if name == "score" and not utils.is_score(value):
                utils.err(
                    "invalid score '%s', use integer or INFINITY or -INFINITY"
                    % value
                )
            rsc_colocation.set(name,value)
    set_add_resource_sets(rsc_colocation, current_set, cib)
    utils.replace_cib_configuration(cib)
开发者ID:vincepii,项目名称:pcs,代码行数:42,代码来源:constraint.py


注:本文中的utils.find_unique_id函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。