コード例 #1
0
ファイル: constraint.py プロジェクト: miz-take/pcs
def show_location_rules(ruleshash, showDetail, noheader=False):
    constraint_options = {}
    for rsc in sorted(ruleshash.keys(),
                      key=lambda item: ({
                          RESOURCE_TYPE_RESOURCE: 1,
                          RESOURCE_TYPE_REGEXP: 0,
                      }[item[0]], item[1])):
        constrainthash = defaultdict(list)
        if not noheader:
            print("  {0}".format(rsc[2]))
        for rule in ruleshash[rsc]:
            constraint_id = rule.parentNode.getAttribute("id")
            constrainthash[constraint_id].append(rule)
            constraint_options[constraint_id] = []
            if rule.parentNode.getAttribute("resource-discovery"):
                constraint_options[constraint_id].append(
                    "resource-discovery=%s" %
                    rule.parentNode.getAttribute("resource-discovery"))

        for constraint_id in sorted(constrainthash.keys()):
            if constraint_id in constraint_options and len(
                    constraint_options[constraint_id]) > 0:
                constraint_option_info = " (" + " ".join(
                    constraint_options[constraint_id]) + ")"
            else:
                constraint_option_info = ""

            print("    Constraint: " + constraint_id + constraint_option_info)
            for rule in constrainthash[constraint_id]:
                print(rule_utils.ExportDetailed().get_string(
                    rule, showDetail, "      "))
コード例 #2
0
ファイル: constraint.py プロジェクト: miz-take/pcs
def location_rule_check_duplicates(dom, constraint_el):
    if "--force" not in utils.pcs_options:
        duplicates = location_rule_find_duplicates(dom, constraint_el)
        if duplicates:
            lines = []
            for dup in duplicates:
                lines.append("  Constraint: %s" % dup.getAttribute("id"))
                for dup_rule in utils.dom_get_children_by_tag_name(
                        dup, "rule"):
                    lines.append(rule_utils.ExportDetailed().get_string(
                        dup_rule, True, "    "))
            utils.err(
                "duplicate constraint already exists, use --force to override\n"
                + "\n".join(lines))
コード例 #3
0
ファイル: constraint.py プロジェクト: rriifftt/pcs
def show_location_rules(ruleshash,showDetail,noheader=False):
    constraint_options = {}
    for rsc in ruleshash:
        constrainthash= defaultdict(list)
        if not noheader:
            print("  " + rsc)
        for rule in ruleshash[rsc]:
            constraint_id = rule.parentNode.getAttribute("id")
            constrainthash[constraint_id].append(rule)
            constraint_options[constraint_id] = []
            if rule.parentNode.getAttribute("resource-discovery"):
                constraint_options[constraint_id].append("resource-discovery=%s" % rule.parentNode.getAttribute("resource-discovery"))

        for constraint_id in sorted(constrainthash.keys()):
            if constraint_id in constraint_options and len(constraint_options[constraint_id]) > 0:
                constraint_option_info = " (" + " ".join(constraint_options[constraint_id]) + ")"
            else:
                constraint_option_info = ""

            print("    Constraint: " + constraint_id + constraint_option_info)
            for rule in constrainthash[constraint_id]:
                print(rule_utils.ExportDetailed().get_string(
                    rule, showDetail, "      "
                ))
コード例 #4
0
ファイル: constraint.py プロジェクト: miladalipour99/pcs
def _show_location_rules(ruleshash,
                         cib,
                         show_detail,
                         show_expired=False,
                         verify_expiration=True,
                         noheader=False):
    """
    Commandline options: no options
    """
    all_lines = []
    constraint_options = {}
    for rsc in sorted(ruleshash.keys(),
                      key=lambda item: ({
                          RESOURCE_TYPE_RESOURCE: 1,
                          RESOURCE_TYPE_REGEXP: 0,
                      }[item[0]], item[1])):
        constrainthash = defaultdict(list)
        if not noheader:
            all_lines.append("  {0}".format(rsc[2]))
        for rule in ruleshash[rsc]:
            constraint_id = rule.parentNode.getAttribute("id")
            constrainthash[constraint_id].append(rule)
            constraint_options[constraint_id] = []
            if rule.parentNode.getAttribute("resource-discovery"):
                constraint_options[constraint_id].append(
                    "resource-discovery=%s" %
                    rule.parentNode.getAttribute("resource-discovery"))

        for constraint_id in sorted(constrainthash.keys()):
            if (constraint_id in constraint_options
                    and constraint_options[constraint_id]):
                constraint_option_info = (
                    " (" + " ".join(constraint_options[constraint_id]) + ")")
            else:
                constraint_option_info = ""

            rule_lines = []
            # When expiration check is needed, starting value should be True and
            # when it's not, check is skipped so the initial value must be False
            # to print the constraint
            is_constraint_expired = verify_expiration
            for rule in constrainthash[constraint_id]:
                rule_status = RULE_UNKNOWN_STATUS
                if verify_expiration:
                    rule_status = _get_rule_status(rule.getAttribute("id"),
                                                   cib)
                    if rule_status != RULE_EXPIRED:
                        is_constraint_expired = False

                rule_lines.append(rule_utils.ExportDetailed().get_string(
                    rule,
                    rule_status == RULE_EXPIRED and show_expired,
                    show_detail,
                    indent="      "))

            if not show_expired and is_constraint_expired:
                continue

            all_lines.append("    Constraint{0}: {1}{2}".format(
                " (expired)" if is_constraint_expired else "", constraint_id,
                constraint_option_info))
            all_lines += rule_lines
    return all_lines