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)
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)
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)