本文整理汇总了Python中utils.find_unique_id函数的典型用法代码示例。如果您正苦于以下问题:Python find_unique_id函数的具体用法?Python find_unique_id怎么用?Python find_unique_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_unique_id函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: add_permissions_to_role
def add_permissions_to_role(role_element, argv):
dom = role_element.ownerDocument
role_id = role_element.getAttribute("id")
while argv:
if len(argv) < 3:
return False
rwd = argv.pop(0).lower()
if not rwd in ["read", "write", "deny"]:
return False
se = dom.createElement("acl_permission")
se.setAttribute("id", utils.find_unique_id(dom, role_id + "-" + rwd))
se.setAttribute("kind", rwd)
xp_id = argv.pop(0).lower()
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:
return False
role_element.appendChild(se)
return True
开发者ID:tradej,项目名称:pcs,代码行数:23,代码来源:acl.py
示例17: 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 = 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 = utils.validate_constraint_resource(
cib, opts
)
if 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))
开发者ID:MichalCab,项目名称:pcs,代码行数:37,代码来源:constraint.py
示例18: colocation_add
def colocation_add(argv):
if len(argv) < 2:
usage.constraint()
sys.exit(1)
role1 = ""
role2 = ""
if len(argv) > 2:
if not utils.is_score_or_opt(argv[2]):
if argv[2] == "with":
role1 = argv.pop(0).lower().capitalize()
resource1 = argv.pop(0)
else:
resource1 = argv.pop(0)
argv.pop(0) # Pop 'with'
if len(argv) == 1:
resource2 = argv.pop(0)
else:
if utils.is_score_or_opt(argv[1]):
resource2 = argv.pop(0)
else:
role2 = argv.pop(0).lower().capitalize()
resource2 = argv.pop(0)
else:
resource1 = argv.pop(0)
resource2 = argv.pop(0)
else:
resource1 = argv.pop(0)
resource2 = argv.pop(0)
if not utils.is_valid_constraint_resource(resource1):
utils.err("Resource '" + resource1 + "' does not exist")
if not utils.is_valid_constraint_resource(resource2):
utils.err("Resource '" + resource2 + "' does not exist")
if utils.is_resource_masterslave(resource1):
utils.err(resource1 + " is a master/slave resource, you must use the master id: "+utils.get_resource_master_id(resource1)+ " when adding constraints")
if utils.is_resource_masterslave(resource2):
utils.err(resource2 + " is a master/slave resource, you must use the master id: "+utils.get_resource_master_id(resource2)+ " when adding constraints")
score,nv_pairs = parse_score_options(argv)
(dom,constraintsElement) = getCurrentConstraints()
cl_id = utils.find_unique_id(dom, "colocation-" + resource1 + "-" +
resource2 + "-" + score)
# If one role is specified, the other should default to "started"
if role1 != "" and role2 == "":
role2 = "Started"
if role2 != "" and role1 == "":
role1 = "Started"
element = dom.createElement("rsc_colocation")
element.setAttribute("id",cl_id)
element.setAttribute("rsc",resource1)
element.setAttribute("with-rsc",resource2)
element.setAttribute("score",score)
if role1 != "":
element.setAttribute("rsc-role", role1)
if role2 != "":
element.setAttribute("with-rsc-role", role2)
for nv_pair in nv_pairs:
element.setAttribute(nv_pair[0], nv_pair[1])
constraintsElement.appendChild(element)
utils.replace_cib_configuration(dom)
开发者ID:vincepii,项目名称:pcs,代码行数:67,代码来源:constraint.py
示例19: acl_role
def acl_role(argv):
if len(argv) < 2:
usage.acl("role")
sys.exit(1)
dom = utils.get_cib_dom()
dom, acls = get_acls(dom)
command = argv.pop(0)
if command == "create":
role_name = argv.pop(0)
if len(argv) < 3:
usage.acl("role create")
sys.exit(1)
if argv[0].startswith('description=') and len(argv[0]) > 12:
description = argv.pop(0)[12:]
else:
description = ""
if utils.does_id_exist(dom,role_name):
utils.err(role_name + " already exists")
element = dom.createElement("acl_role")
element.setAttribute("id",role_name)
if description != "":
element.setAttribute("description", description)
acls.appendChild(element)
while (len(argv) > 2):
rwd = argv.pop(0)
if not rwd in ["read","write","deny"]:
usage.acl("role create")
sys.exit(1)
se = dom.createElement("acl_permission")
se.setAttribute("id", utils.find_unique_id(dom,role_name + "-" + rwd))
se.setAttribute("kind", rwd)
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("role create")
element.appendChild(se)
utils.replace_cib_configuration(dom)
elif command == "delete":
if len(argv) < 1:
usage.acl("acl role delete")
role_id = argv.pop(0)
found = False
for elem in dom.getElementsByTagName("acl_role"):
if elem.getAttribute("id") == role_id:
found = True
elem.parentNode.removeChild(elem)
break
if not found:
utils.err("unable to find acl role: %s" % role_id)
# Remove any references to this role in acl_target or acl_group
for elem in dom.getElementsByTagName("role"):
if elem.getAttribute("id") == role_id:
elem.parentNode.removeChild(elem)
utils.replace_cib_configuration(dom)
elif command == "assign":
if len(argv) < 2:
usage.acl("role assign")
sys.exit(1)
if len(argv) == 2:
role_id = argv[0]
ug_id = argv[1]
elif len(argv) > 2 and argv[1] == "to":
role_id = argv[0]
ug_id = argv[2]
else:
usage.acl("role assign")
sys.exit(1)
found = False
for role in dom.getElementsByTagName("acl_role"):
if role.getAttribute("id") == role_id:
found = True
break
if not found:
utils.err("cannot find role: %s" % role_id)
found = False
for ug in dom.getElementsByTagName("acl_target") + dom.getElementsByTagName("acl_group"):
if ug.getAttribute("id") == ug_id:
found = True
break
if not found:
utils.err("cannot find user or group: %s" % ug_id)
#.........这里部分代码省略.........
开发者ID:MichalCab,项目名称:pcs,代码行数:101,代码来源:acl.py
示例20: order_add
def order_add(argv,returnElementOnly=False):
if len(argv) < 2:
usage.constraint()
sys.exit(1)
resource1 = argv.pop(0)
resource2 = argv.pop(0)
cib_dom = utils.get_cib_dom()
resource_valid, resource_error, correct_id \
= utils.validate_constraint_resource(cib_dom, resource1)
if "--autocorrect" in utils.pcs_options and correct_id:
resource1 = correct_id
elif not resource_valid:
utils.err(resource_error)
resource_valid, resource_error, correct_id \
= utils.validate_constraint_resource(cib_dom, resource2)
if "--autocorrect" in utils.pcs_options and correct_id:
resource2 = correct_id
elif not resource_valid:
utils.err(resource_error)
order_options = []
id_specified = False
sym = None
for arg in argv:
if arg == "symmetrical":
sym = "true"
elif arg == "nonsymmetrical":
sym = "false"
elif "=" in arg:
name, value = arg.split("=", 1)
if name == "id":
id_valid, id_error = utils.validate_xml_id(value, 'constraint id')
if not id_valid:
utils.err(id_error)
if utils.does_id_exist(cib_dom, value):
utils.err(
"id '%s' is already in use, please specify another one"
% value
)
id_specified = True
order_options.append((name, value))
elif name == "symmetrical":
if value.lower() in OPTIONS_SYMMETRICAL:
sym = value.lower()
else:
utils.err(
"invalid symmetrical value '%s', allowed values are: %s"
% (value, ", ".join(OPTIONS_SYMMETRICAL))
)
else:
order_options.append((name, value))
if sym:
order_options.append(("symmetrical", sym))
options = ""
if order_options:
options = " (Options: %s)" % " ".join([
"%s=%s" % (name, value)
for name, value in order_options
if name not in ("kind", "score")
])
scorekind = "kind: Mandatory"
id_suffix = "mandatory"
for opt in order_options:
if opt[0] == "score":
scorekind = "score: " + opt[1]
id_suffix = opt[1]
break
if opt[0] == "kind":
scorekind = "kind: " + opt[1]
id_suffix = opt[1]
break
if not id_specified:
order_id = "order-" + resource1 + "-" + resource2 + "-" + id_suffix
order_id = utils.find_unique_id(cib_dom, order_id)
order_options.append(("id", order_id))
(dom,constraintsElement) = getCurrentConstraints()
element = dom.createElement("rsc_order")
element.setAttribute("first",resource1)
element.setAttribute("then",resource2)
for order_opt in order_options:
element.setAttribute(order_opt[0], order_opt[1])
constraintsElement.appendChild(element)
if "--force" not in utils.pcs_options:
duplicates = order_find_duplicates(constraintsElement, element)
if duplicates:
utils.err(
"duplicate constraint already exists, use --force to override\n"
+ "\n".join([
" " + order_el_to_string(dup, True) for dup in duplicates
])
)
print(
"Adding " + resource1 + " " + resource2 + " ("+scorekind+")" + options
)
#.........这里部分代码省略.........
开发者ID:akanouras,项目名称:pcs,代码行数:101,代码来源:constraint.py
注:本文中的utils.find_unique_id函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论