本文整理汇总了Python中usage.constraint函数的典型用法代码示例。如果您正苦于以下问题:Python constraint函数的具体用法?Python constraint怎么用?Python constraint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了constraint函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
示例2: 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
示例3: order_add
def order_add(argv,returnElementOnly=False):
if len(argv) != 3 and len(argv) != 4:
usage.constraint()
sys.exit(1)
resource1 = argv.pop(0)
resource2 = argv.pop(0)
score = argv.pop(0)
sym = "true" if (len(argv) == 0 or argv.pop(0) != "nonsymmetrical") else "false"
order_id = "order-" + resource1 + "-" + resource2 + "-" + score
print "Adding " + resource1 + " " + resource2 + " score: " + score + " Symmetrical: "+sym
(dom,constraintsElement) = getCurrentConstraints()
element = dom.createElement("rsc_order")
element.setAttribute("id",order_id)
element.setAttribute("first",resource1)
element.setAttribute("then",resource2)
element.setAttribute("score",score)
if (sym == "false"):
element.setAttribute("symmetrical", "false")
constraintsElement.appendChild(element)
if returnElementOnly == False:
xml_constraint_string = constraintsElement.toxml()
args = ["cibadmin", "-c", "-R", "--xml-text", xml_constraint_string]
output,retval = utils.run(args)
if output != "":
print output
else:
return element.toxml()
开发者ID:bwheatley,项目名称:pcs,代码行数:31,代码来源:constraint.py
示例4: colocation_rm
def colocation_rm(argv):
elementFound = False
if len(argv) < 2:
usage.constraint()
sys.exit(1)
(dom,constraintsElement) = getCurrentConstraints()
resource1 = argv[0]
resource2 = argv[1]
for co_loc in constraintsElement.getElementsByTagName('rsc_colocation')[:]:
if co_loc.getAttribute("rsc") == resource1 and co_loc.getAttribute("with-rsc") == resource2:
constraintsElement.removeChild(co_loc)
elementFound = True
if co_loc.getAttribute("rsc") == resource2 and co_loc.getAttribute("with-rsc") == resource1:
constraintsElement.removeChild(co_loc)
elementFound = True
if elementFound == True:
xml_constraint_string = constraintsElement.toxml()
args = ["cibadmin", "-c", "-R", "--xml-text", xml_constraint_string]
output,retval = utils.run(args)
if output != "":
print output
else:
print "No matching resources found in ordering list"
开发者ID:BillTheBest,项目名称:pcs,代码行数:27,代码来源:constraint.py
示例5: order_rm
def order_rm(argv):
if len(argv) == 0:
usage.constraint()
sys.exit(1)
elementFound = False
(dom,constraintsElement) = getCurrentConstraints()
for resource in argv:
for ord_loc in constraintsElement.getElementsByTagName('rsc_order')[:]:
if ord_loc.getAttribute("first") == resource or ord_loc.getAttribute("then") == resource:
constraintsElement.removeChild(ord_loc)
elementFound = True
resource_refs_to_remove = []
for ord_set in constraintsElement.getElementsByTagName('resource_ref'):
if ord_set.getAttribute("id") == resource:
resource_refs_to_remove.append(ord_set)
elementFound = True
for res_ref in resource_refs_to_remove:
res_set = res_ref.parentNode
res_order = res_set.parentNode
res_ref.parentNode.removeChild(res_ref)
if len(res_set.getElementsByTagName('resource_ref')) <= 0:
res_set.parentNode.removeChild(res_set)
if len(res_order.getElementsByTagName('resource_set')) <= 0:
res_order.parentNode.removeChild(res_order)
if elementFound == True:
utils.replace_cib_configuration(dom)
else:
utils.err("No matching resources found in ordering list")
开发者ID:vincepii,项目名称:pcs,代码行数:34,代码来源:constraint.py
示例6: location_prefer
def location_prefer(argv):
rsc = argv.pop(0)
prefer_option = argv.pop(0)
if prefer_option == "prefers":
prefer = True
elif prefer_option == "avoids":
prefer = False
else:
usage.constraint()
sys.exit(1)
for nodeconf in argv:
nodeconf_a = nodeconf.split("=",1)
if len(nodeconf_a) == 1:
node = nodeconf_a[0]
if prefer:
score = "INFINITY"
else:
score = "-INFINITY"
else:
score = nodeconf_a[1]
if not utils.is_score(score):
utils.err("invalid score '%s', use integer or INFINITY or -INFINITY" % score)
if not prefer:
if score[0] == "-":
score = score[1:]
else:
score = "-" + score
node = nodeconf_a[0]
location_add(["location-" +rsc+"-"+node+"-"+score,rsc,node,score])
开发者ID:vincepii,项目名称:pcs,代码行数:32,代码来源:constraint.py
示例7: constraint_rm
def constraint_rm(argv):
if len(argv) < 1:
usage.constraint()
sys.exit(1)
if len(argv) != 1:
for arg in argv:
constraint_rm([arg])
return
else:
c_id = argv.pop(0)
elementFound = False
(dom,constraintsElement) = getCurrentConstraints()
for co in constraintsElement.childNodes[:]:
if co.nodeType != xml.dom.Node.ELEMENT_NODE:
continue
if co.getAttribute("id") == c_id:
constraintsElement.removeChild(co)
elementFound = True
if elementFound == True:
xml_constraint_string = constraintsElement.toxml()
args = ["cibadmin", "-c", "-R", "--xml-text", xml_constraint_string]
output,retval = utils.run(args)
if output != "":
print output
else:
print "No matching resources found in ordering list"
开发者ID:ckesselh,项目名称:pcs,代码行数:30,代码来源:constraint.py
示例8: constraint_rule
def constraint_rule(argv):
if len(argv) < 2:
usage.constraint("rule")
sys.exit(1)
found = False
command = argv.pop(0)
constraint_id = None
rule_id = None
if command == "add":
constraint_id = argv.pop(0)
cib = utils.get_cib_dom()
constraint = utils.dom_get_element_with_id(
cib.getElementsByTagName("constraints")[0],
"rsc_location",
constraint_id
)
if not constraint:
utils.err("Unable to find constraint: " + constraint_id)
options, rule_argv = rule_utils.parse_argv(argv)
rule_utils.dom_rule_add(constraint, options, rule_argv)
location_rule_check_duplicates(cib, constraint)
utils.replace_cib_configuration(cib)
elif command in ["remove","delete"]:
cib = utils.get_cib_etree()
temp_id = argv.pop(0)
constraints = cib.find('.//constraints')
loc_cons = cib.findall(str('.//rsc_location'))
rules = cib.findall(str('.//rule'))
for loc_con in loc_cons:
for rule in loc_con:
if rule.get("id") == temp_id:
if len(loc_con) > 1:
print("Removing Rule: {0}".format(rule.get("id")))
loc_con.remove(rule)
found = True
break
else:
print(
"Removing Constraint: {0}".format(loc_con.get("id"))
)
constraints.remove(loc_con)
found = True
break
if found == True:
break
if found:
utils.replace_cib_configuration(cib)
else:
utils.err("unable to find rule with id: %s" % temp_id)
else:
usage.constraint("rule")
sys.exit(1)
开发者ID:akanouras,项目名称:pcs,代码行数:60,代码来源:constraint.py
示例9: constraint_rule
def constraint_rule(argv):
if len(argv) < 2:
usage.constraint("rule")
sys.exit(1)
found = False
command = argv.pop(0)
constraint_id = None
rule_id = None
cib = utils.get_cib_etree()
if command == "add":
constraint_id = argv.pop(0)
constraint = None
for a in cib.findall(".//configuration//*"):
if a.get("id") == constraint_id and a.tag == "rsc_location":
found = True
constraint = a
if not found:
utils.err("Unable to find constraint: " + constraint_id)
utils.rule_add(constraint, argv)
utils.replace_cib_configuration(cib)
elif command in ["remove","delete"]:
temp_id = argv.pop(0)
constraints = cib.find('.//constraints')
loc_cons = cib.findall('.//rsc_location')
rules = cib.findall('.//rule')
for loc_con in loc_cons:
for rule in loc_con:
if rule.get("id") == temp_id:
if len(loc_con) > 1:
print "Removing Rule:",rule.get("id")
loc_con.remove(rule)
found = True
break
else:
print "Removing Constraint:",loc_con.get("id")
constraints.remove(loc_con)
found = True
break
if found == True:
break
if found:
utils.replace_cib_configuration(cib)
else:
utils.err("unable to find rule with id: %s" % temp_id)
else:
usage.constraint("rule")
sys.exit(1)
开发者ID:vincepii,项目名称:pcs,代码行数:58,代码来源:constraint.py
示例10: location_add
def location_add(argv,rm=False):
if len(argv) != 4 and (rm == False or len(argv) < 1):
usage.constraint()
sys.exit(1)
constraint_id = argv.pop(0)
# If we're removing, we only care about the id
if (rm == True):
resource_name = ""
node = ""
score = ""
else:
id_valid, id_error = utils.validate_xml_id(constraint_id, 'constraint id')
if not id_valid:
utils.err(id_error)
resource_name = argv.pop(0)
node = argv.pop(0)
score = argv.pop(0)
resource_valid, resource_error = utils.validate_constraint_resource(
utils.get_cib_dom(), resource_name
)
if not resource_valid:
utils.err(resource_error)
if not utils.is_score(score):
utils.err("invalid score '%s', use integer or INFINITY or -INFINITY" % score)
# Verify current constraint doesn't already exist
# If it does we replace it with the new constraint
(dom,constraintsElement) = getCurrentConstraints()
elementsToRemove = []
# If the id matches, or the rsc & node match, then we replace/remove
for rsc_loc in constraintsElement.getElementsByTagName('rsc_location'):
if (constraint_id == rsc_loc.getAttribute("id")) or \
(rsc_loc.getAttribute("rsc") == resource_name and \
rsc_loc.getAttribute("node") == node and not rm):
elementsToRemove.append(rsc_loc)
for etr in elementsToRemove:
constraintsElement.removeChild(etr)
if (rm == True and len(elementsToRemove) == 0):
utils.err("resource location id: " + constraint_id + " not found.")
if (not rm):
element = dom.createElement("rsc_location")
element.setAttribute("id",constraint_id)
element.setAttribute("rsc",resource_name)
element.setAttribute("node",node)
element.setAttribute("score",score)
constraintsElement.appendChild(element)
utils.replace_cib_configuration(dom)
开发者ID:MichalCab,项目名称:pcs,代码行数:54,代码来源:constraint.py
示例11: location_add
def location_add(argv,rm=False):
if len(argv) != 4 and (rm == False or len(argv) < 1):
usage.constraint()
sys.exit(1)
constraint_id = argv.pop(0)
# If we're removing, we only care about the id
if (rm == True):
resource_name = ""
node = ""
score = ""
else:
resource_name = argv.pop(0)
node = argv.pop(0)
score = argv.pop(0)
# If resource doesn't exist, we error out
if not utils.does_resource_exist(resource_name):
print "Error: Resource " + resource_name + "' does not exist"
sys.exit(1)
# Verify current constraint doesn't already exist
# If it does we replace it with the new constraint
(dom,constraintsElement) = getCurrentConstraints()
elementsToRemove = []
# If the id matches, or the rsc & node match, then we replace/remove
for rsc_loc in constraintsElement.getElementsByTagName('rsc_location'):
if (constraint_id == rsc_loc.getAttribute("id")) or \
(rsc_loc.getAttribute("rsc") == resource_name and \
rsc_loc.getAttribute("node") == node and not rm):
elementsToRemove.append(rsc_loc)
for etr in elementsToRemove:
constraintsElement.removeChild(etr)
if (rm == True and len(elementsToRemove) == 0):
print "Resource location id: " + constraint_id + " not found."
sys.exit(1)
if (not rm):
element = dom.createElement("rsc_location")
element.setAttribute("id",constraint_id)
element.setAttribute("rsc",resource_name)
element.setAttribute("node",node)
element.setAttribute("score",score)
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,代码行数:53,代码来源:constraint.py
示例12: constraint_rm
def constraint_rm(argv,returnStatus=False, constraintsElement=None, passed_dom=None):
if len(argv) < 1:
usage.constraint()
sys.exit(1)
bad_constraint = False
if len(argv) != 1:
for arg in argv:
if not constraint_rm([arg],True, passed_dom=passed_dom):
bad_constraint = True
if bad_constraint:
sys.exit(1)
return
else:
c_id = argv.pop(0)
elementFound = False
if not constraintsElement:
(dom, constraintsElement) = getCurrentConstraints(passed_dom)
use_cibadmin = True
else:
use_cibadmin = False
for co in constraintsElement.childNodes[:]:
if co.nodeType != xml.dom.Node.ELEMENT_NODE:
continue
if co.getAttribute("id") == c_id:
constraintsElement.removeChild(co)
elementFound = True
if not elementFound:
for rule in constraintsElement.getElementsByTagName("rule")[:]:
if rule.getAttribute("id") == c_id:
elementFound = True
parent = rule.parentNode
parent.removeChild(rule)
if len(parent.getElementsByTagName("rule")) == 0:
parent.parentNode.removeChild(parent)
if elementFound == True:
if passed_dom:
return dom
if use_cibadmin:
utils.replace_cib_configuration(dom)
if returnStatus:
return True
else:
print >> sys.stderr, "Error: Unable to find constraint - '%s'" % c_id
if returnStatus:
return False
sys.exit(1)
开发者ID:vincepii,项目名称:pcs,代码行数:52,代码来源:constraint.py
示例13: constraint_ref
def constraint_ref(argv):
if len(argv) == 0:
usage.constraint()
sys.exit(1)
for arg in argv:
print "Resource: %s" % arg
constraints = find_constraints_containing(arg)
if len(constraints) == 0:
print " No Matches."
else:
for constraint in constraints:
print " " + constraint
开发者ID:ckesselh,项目名称:pcs,代码行数:13,代码来源:constraint.py
示例14: constraint_rm
def constraint_rm(argv,returnStatus=False, constraintsElement=None):
if len(argv) < 1:
usage.constraint()
sys.exit(1)
bad_constraint = False
if len(argv) != 1:
for arg in argv:
if not constraint_rm([arg],True):
bad_constraint = True
if bad_constraint:
sys.exit(1)
return
else:
c_id = argv.pop(0)
elementFound = False
if not constraintsElement:
(dom, constraintsElement) = getCurrentConstraints()
use_cibadmin = True
else:
use_cibadmin = False
for co in constraintsElement.childNodes[:]:
if co.nodeType != xml.dom.Node.ELEMENT_NODE:
continue
if co.getAttribute("id") == c_id:
constraintsElement.removeChild(co)
elementFound = True
if not elementFound:
for rule in constraintsElement.getElementsByTagName("rule")[:]:
if rule.getAttribute("id") == c_id:
elementFound = True
parent = rule.parentNode
parent.removeChild(rule)
if len(parent.getElementsByTagName("rule")) == 0:
parent.parentNode.removeChild(parent)
if elementFound == True:
if use_cibadmin:
xml_constraint_string = constraintsElement.toxml()
args = ["cibadmin", "-c", "-R", "--xml-text", xml_constraint_string]
output,retval = utils.run(args)
if output != "":
print output
else:
print >> sys.stderr, "Error: Unable to find constraint - '%s'" % c_id
if not returnStatus:
sys.exit(1)
开发者ID:BillTheBest,项目名称:pcs,代码行数:51,代码来源:constraint.py
示例15: 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
示例16: constraint_ref
def constraint_ref(argv):
if len(argv) == 0:
usage.constraint()
sys.exit(1)
for arg in argv:
print("Resource: %s" % arg)
constraints,set_constraints = find_constraints_containing(arg)
if len(constraints) == 0 and len(set_constraints) == 0:
print(" No Matches.")
else:
for constraint in constraints:
print(" " + constraint)
for constraint in set_constraints:
print(" " + constraint)
开发者ID:akanouras,项目名称:pcs,代码行数:15,代码来源:constraint.py
示例17: 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
示例18: 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
示例19: colocation_add
def colocation_add(argv):
if len(argv) < 2:
usage.constraint()
sys.exit(1)
resource1 = argv.pop(0)
resource2 = argv.pop(0)
score = "INFINITY" if (len(argv) == 0) else argv.pop(0)
cl_id = "colocation-" + resource1 + "-" + resource2 + "-" + score
(dom,constraintsElement) = getCurrentConstraints()
element = dom.createElement("rsc_colocation")
element.setAttribute("id",cl_id)
element.setAttribute("rsc",resource1)
element.setAttribute("with-rsc",resource2)
element.setAttribute("score",score)
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:bwheatley,项目名称:pcs,代码行数:22,代码来源:constraint.py
示例20: order_rm
def order_rm(argv):
if len(argv) == 0:
usage.constraint()
sys.exit(1)
elementFound = False
(dom,constraintsElement) = getCurrentConstraints()
for resource in argv:
for ord_loc in constraintsElement.getElementsByTagName('rsc_order')[:]:
if ord_loc.getAttribute("first") == resource or ord_loc.getAttribute("then") == resource:
constraintsElement.removeChild(ord_loc)
elementFound = True
if elementFound == True:
xml_constraint_string = constraintsElement.toxml()
args = ["cibadmin", "-c", "-R", "--xml-text", xml_constraint_string]
output,retval = utils.run(args)
if output != "":
print output
else:
print "No matching resources found in ordering list"
开发者ID:BillTheBest,项目名称:pcs,代码行数:22,代码来源:constraint.py
注:本文中的usage.constraint函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论