Example #1
0
def quorum_config_to_str(config):
    lines = []

    lines.append("Options:")
    if "options" in config and config["options"]:
        lines.extend(
            indent([
                "{n}: {v}".format(n=name, v=value)
                for name, value in sorted(config["options"].items())
            ]))

    if "device" in config and config["device"]:
        lines.append("Device:")
        lines.extend(
            indent([
                "{n}: {v}".format(n=name, v=value)
                for name, value in sorted(config["device"].get(
                    "generic_options", {}).items())
            ]))
        model_settings = [
            "Model: {m}".format(m=config["device"].get("model", ""))
        ]
        model_settings.extend(
            indent([
                "{n}: {v}".format(n=name, v=value)
                for name, value in sorted(config["device"].get(
                    "model_options", {}).items())
            ]))
        lines.extend(indent(model_settings))

    return lines
Example #2
0
    def test_all_posibilities(self):
        self.fixture_full_configuration()
        self.assert_pcs_success("stonith level config", self.config)
        self.assert_pcs_success("stonith level", self.config)
        self.assert_pcs_success(
            "stonith",
            outdent(
                """\
                 F1\t(stonith:fence_apc):\tStopped
                 F2\t(stonith:fence_apc):\tStopped
                 F3\t(stonith:fence_apc):\tStopped
                """
            ) + "\n".join(indent(self.config_lines, 1)) + "\n"
        )
        self.assert_pcs_success(
            "config",
            self.full_config.format(
                devices="""
 Resource: F1 (class=stonith type=fence_apc)
  Attributes: pcmk_host_list="rh7-1 rh7-2," ipaddr=ip login=lgn
  Operations: monitor interval=60s (F1-monitor-interval-60s)
 Resource: F2 (class=stonith type=fence_apc)
  Attributes: pcmk_host_list="rh7-1 rh7-2," ipaddr=ip login=lgn
  Operations: monitor interval=60s (F2-monitor-interval-60s)
 Resource: F3 (class=stonith type=fence_apc)
  Attributes: pcmk_host_list="rh7-1 rh7-2," ipaddr=ip login=lgn
  Operations: monitor interval=60s (F3-monitor-interval-60s)\
""",
                levels=("\n" + "\n".join(indent(self.config_lines, 2)))
            )
        )
Example #3
0
    def test_all_posibilities(self):
        self.fixture_full_configuration()
        self.assert_pcs_success("stonith level config", self.config)
        self.assert_pcs_success("stonith level", self.config)
        self.assert_pcs_success(
            "stonith",
            outdent("""\
                 F1\t(stonith:fence_apc):\tStopped
                 F2\t(stonith:fence_apc):\tStopped
                 F3\t(stonith:fence_apc):\tStopped
                """) + "\n".join(indent(self.config_lines, 1)) + "\n")
        self.assert_pcs_success(
            "config",
            self.full_config.format(
                devices="""
 Resource: F1 (class=stonith type=fence_apc)
  Attributes: ipaddr=ip login=lgn pcmk_host_list="rh7-1 rh7-2,"
  Operations: monitor interval=60s (F1-monitor-interval-60s)
 Resource: F2 (class=stonith type=fence_apc)
  Attributes: ipaddr=ip login=lgn pcmk_host_list="rh7-1 rh7-2,"
  Operations: monitor interval=60s (F2-monitor-interval-60s)
 Resource: F3 (class=stonith type=fence_apc)
  Attributes: ipaddr=ip login=lgn pcmk_host_list="rh7-1 rh7-2,"
  Operations: monitor interval=60s (F3-monitor-interval-60s)\
""",
                levels=("\n" + "\n".join(indent(self.config_lines, 2)))))
Example #4
0
File: quorum.py Project: idevat/pcs
def quorum_config_to_str(config):
    lines = []

    lines.append("Options:")
    if "options" in config and config["options"]:
        lines.extend(indent([
            "{n}: {v}".format(n=name, v=value)
            for name, value in sorted(config["options"].items())
        ]))

    if "device" in config and config["device"]:
        lines.append("Device:")
        lines.extend(indent([
            "{n}: {v}".format(n=name, v=value)
            for name, value in sorted(
                config["device"].get("generic_options", {}).items()
            )
        ]))
        model_settings = [
            "Model: {m}".format(m=config["device"].get("model", ""))
        ]
        model_settings.extend(indent([
            "{n}: {v}".format(n=name, v=value)
            for name, value in sorted(
                config["device"].get("model_options", {}).items()
            )
        ]))
        lines.extend(indent(model_settings))

    return lines
Example #5
0
def _alert_to_str(alert):
    content = []
    content.extend(__description_attributes_to_str(alert))

    recipients = []
    for recipient in alert.get("recipient_list", []):
        recipients.extend( _recipient_to_str(recipient))

    if recipients:
        content.append("Recipients:")
        content.extend(indent(recipients, 1))

    return ["Alert: {alert_id} (path={path})".format(
        alert_id=alert["id"], path=alert["path"]
    )] + indent(content, 1)
Example #6
0
def _alert_to_str(alert):
    content = []
    content.extend(__description_attributes_to_str(alert))

    recipients = []
    for recipient in alert.get("recipient_list", []):
        recipients.extend(_recipient_to_str(recipient))

    if recipients:
        content.append("Recipients:")
        content.extend(indent(recipients, 1))

    return ["Alert: {alert_id} (path={path})".format(
        alert_id=alert["id"], path=alert["path"]
    )] + indent(content, 1)
Example #7
0
def stonith_level_config_to_str(config):
    """
    Commandline option: no options
    """
    config_data = dict()
    for level in config:
        if level["target_type"] not in config_data:
            config_data[level["target_type"]] = dict()
        if level["target_value"] not in config_data[level["target_type"]]:
            config_data[level["target_type"]][level["target_value"]] = []
        config_data[level["target_type"]][level["target_value"]].append(level)

    lines = []
    for target_type in [
            TARGET_TYPE_NODE, TARGET_TYPE_REGEXP, TARGET_TYPE_ATTRIBUTE
    ]:
        if not target_type in config_data:
            continue
        for target_value in sorted(config_data[target_type].keys()):
            lines.append(
                "Target: {0}".format("=".join(target_value) if target_type ==
                                     TARGET_TYPE_ATTRIBUTE else target_value))
            level_lines = []
            for target_level in sorted(config_data[target_type][target_value],
                                       key=lambda level: level["level"]):
                level_lines.append("Level {level} - {devices}".format(
                    level=target_level["level"],
                    devices=",".join(target_level["devices"])))
            lines.extend(indent(level_lines))
    return lines
Example #8
0
def show(caption, load_constraints, format_options, modifiers):
    """
    load constraints and return console lines list with info about constraints
    string caption for example "Ticket Constraints:"
    callable load_constraints which returns desired constraints as dictionary
        like {"plain": [], "with_resource_sets": []}
    callable format_options takes dict of options and show_detail flag (bool)
        and returns string with constraint formated for commandline
    modifiers dict like object with command modifiers
    """
    show_detail = modifiers["full"]
    constraints = load_constraints()

    line_list = [caption]
    line_list.extend([
        "  " + format_options(constraint_options_dict, show_detail)
        for constraint_options_dict in constraints["plain"]
    ])

    if constraints["with_resource_sets"]:
        line_list.extend(
            indent(
                show_constraints_with_set(constraints["with_resource_sets"],
                                          show_detail)))

    return line_list
Example #9
0
def config_show(argv):
    print("Cluster Name: %s" % utils.getClusterName())
    status.nodes_status(["config"])
    print()
    config_show_cib()
    if (
        utils.hasCorosyncConf()
        and
        (
            utils.is_rhel6()
            or
            (not utils.usefile and "--corosync_conf" not in utils.pcs_options)
        )
    ):
        # with corosync 1 and cman, uid gid is part of cluster.conf file
        # with corosync 2, uid gid is in a separate directory
        cluster.cluster_uidgid([], True)
    if (
        "--corosync_conf" in utils.pcs_options
        or
        (not utils.is_rhel6() and utils.hasCorosyncConf())
    ):
        print()
        print("Quorum:")
        try:
            config = lib_quorum.get_config(utils.get_lib_env())
            print("\n".join(indent(quorum.quorum_config_to_str(config))))
        except LibraryError as e:
            utils.process_library_reports(e.args)
Example #10
0
def config_show(lib, argv, modifiers):
    """
    Options:
      * -f - CIB file, when getting cluster name on remote node (corosync.conf
        doesn't exist)
      * --corosync_conf - corosync.conf file
    """
    modifiers.ensure_only_supported("-f", "--corosync_conf")
    if argv:
        raise CmdLineInputError()
    print("Cluster Name: %s" % utils.getClusterName())
    status.nodes_status(lib, ["config"], modifiers.get_subset("-f"))
    print()
    print("\n".join(_config_show_cib_lines(lib)))
    if (utils.hasCorosyncConf() and not modifiers.is_specified("-f")
            and not modifiers.is_specified("--corosync_conf")):
        cluster.cluster_uidgid(lib, [],
                               modifiers.get_subset(),
                               silent_list=True)
    if (modifiers.is_specified("--corosync_conf") or utils.hasCorosyncConf()):
        print()
        print("Quorum:")
        try:
            config = lib_quorum.get_config(utils.get_lib_env())
            print("\n".join(indent(quorum.quorum_config_to_str(config))))
        except LibraryError as e:
            process_library_reports(e.args)
Example #11
0
def config_show(argv):
    print("Cluster Name: %s" % utils.getClusterName())
    status.nodes_status(["config"])
    print()
    config_show_cib()
    if (
        utils.hasCorosyncConf()
        and
        (
            utils.is_rhel6()
            or
            (not utils.usefile and "--corosync_conf" not in utils.pcs_options)
        )
    ):
        # with corosync 1 and cman, uid gid is part of cluster.conf file
        # with corosync 2, uid gid is in a separate directory
        cluster.cluster_uidgid([], True)
    if (
        "--corosync_conf" in utils.pcs_options
        or
        (not utils.is_rhel6() and utils.hasCorosyncConf())
    ):
        print()
        print("Quorum:")
        try:
            config = lib_quorum.get_config(utils.get_lib_env())
            print("\n".join(indent(quorum.quorum_config_to_str(config))))
        except LibraryError as e:
            utils.process_library_reports(e.args)
Example #12
0
def stonith_level_config_to_str(config):
    config_data = dict()
    for level in config:
        if level["target_type"] not in config_data:
            config_data[level["target_type"]] = dict()
        if level["target_value"] not in config_data[level["target_type"]]:
            config_data[level["target_type"]][level["target_value"]] = []
        config_data[level["target_type"]][level["target_value"]].append(level)

    lines = []
    for target_type in [
        TARGET_TYPE_NODE, TARGET_TYPE_REGEXP, TARGET_TYPE_ATTRIBUTE
    ]:
        if not target_type in config_data:
            continue
        for target_value in sorted(config_data[target_type].keys()):
            lines.append("Target: {0}".format(
                "=".join(target_value) if target_type == TARGET_TYPE_ATTRIBUTE
                else target_value
            ))
            level_lines = []
            for target_level in sorted(
                config_data[target_type][target_value],
                key=lambda level: level["level"]
            ):
                level_lines.append("Level {level} - {devices}".format(
                    level=target_level["level"],
                    devices=",".join(target_level["devices"])
                ))
            lines.extend(indent(level_lines))
    return lines
Example #13
0
def config_show_cib():
    lib = utils.get_library_wrapper()
    modifiers = utils.get_modifiers()

    print("Resources:")
    utils.pcs_options["--all"] = 1
    utils.pcs_options["--full"] = 1
    resource.resource_show([])

    print()
    print("Stonith Devices:")
    resource.resource_show([], True)
    print("Fencing Levels:")
    levels = stonith.stonith_level_config_to_str(
        lib.fencing_topology.get_config())
    if levels:
        print("\n".join(indent(levels, 2)))

    print()
    constraint.location_show([])
    order_command.show(lib, [], modifiers)
    colocation_command.show(lib, [], modifiers)
    ticket_command.show(lib, [], modifiers)

    print()
    alert.print_alert_config(lib, [], modifiers)

    print()
    del utils.pcs_options["--all"]
    print("Resources Defaults:")
    resource.show_defaults("rsc_defaults", indent=" ")
    print("Operations Defaults:")
    resource.show_defaults("op_defaults", indent=" ")
    print()
    prop.list_property([])
Example #14
0
def show(caption, load_constraints, format_options, modifiers):
    """
    load constraints and return console lines list with info about constraints
    string caption for example "Ticket Constraints:"
    callable load_constraints which returns desired constraints as dictionary
        like {"plain": [], "with_resource_sets": []}
    callable format_options takes dict of options and show_detail flag (bool)
        and returns string with constraint formated for commandline
    modifiers dict like object with command modifiers

    Commandline options:
      * -f - CIB file
      * --full - print more details
    """
    show_detail = modifiers.get("--full")
    constraints = load_constraints()

    line_list = [caption]
    line_list.extend([
        "  " + format_options(constraint_options_dict, show_detail)
        for constraint_options_dict in constraints["plain"]
    ])

    if constraints["with_resource_sets"]:
        line_list.extend(
            indent(show_constraints_with_set(
                constraints["with_resource_sets"],
                show_detail
            ))
        )

    return line_list
Example #15
0
def stonith_cmd(argv):
    if len(argv) < 1:
        sub_cmd, argv_next = "show", []
    else:
        sub_cmd, argv_next = argv[0], argv[1:]

    lib = utils.get_library_wrapper()
    modifiers = utils.get_modifiers()

    try:
        if sub_cmd == "help":
            usage.stonith([" ".join(argv_next)] if argv_next else [])
        elif sub_cmd == "list":
            stonith_list_available(lib, argv_next, modifiers)
        elif sub_cmd == "describe":
            stonith_list_options(lib, argv_next, modifiers)
        elif sub_cmd == "create":
            stonith_create(lib, argv_next, modifiers)
        elif sub_cmd == "update":
            if len(argv_next) > 1:
                stn_id = argv_next.pop(0)
                resource.resource_update(stn_id, argv_next)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "delete":
            if len(argv_next) == 1:
                stn_id = argv_next.pop(0)
                resource.resource_remove(stn_id)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "show":
            resource.resource_show(argv_next, True)
            levels = stonith_level_config_to_str(
                lib.fencing_topology.get_config())
            if levels:
                print("\n".join(indent(levels, 1)))
        elif sub_cmd == "level":
            stonith_level_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "fence":
            stonith_fence(argv_next)
        elif sub_cmd == "cleanup":
            resource.resource_cleanup(argv_next)
        elif sub_cmd == "refresh":
            resource.resource_refresh(argv_next)
        elif sub_cmd == "confirm":
            stonith_confirm(argv_next)
        elif sub_cmd == "get_fence_agent_info":
            get_fence_agent_info(argv_next)
        elif sub_cmd == "sbd":
            sbd_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "enable":
            resource.resource_enable_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "disable":
            resource.resource_disable_cmd(lib, argv_next, modifiers)
        else:
            raise CmdLineInputError()
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "stonith", sub_cmd)
Example #16
0
def stonith_cmd(argv):
    if len(argv) < 1:
        sub_cmd, argv_next = "show", []
    else:
        sub_cmd, argv_next = argv[0], argv[1:]

    lib = utils.get_library_wrapper()
    modifiers = utils.get_modificators()

    try:
        if sub_cmd == "help":
            usage.stonith(argv)
        elif sub_cmd == "list":
            stonith_list_available(lib, argv_next, modifiers)
        elif sub_cmd == "describe":
            stonith_list_options(lib, argv_next, modifiers)
        elif sub_cmd == "create":
            stonith_create(lib, argv_next, modifiers)
        elif sub_cmd == "update":
            if len(argv_next) > 1:
                stn_id = argv_next.pop(0)
                resource.resource_update(stn_id, argv_next)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "delete":
            if len(argv_next) == 1:
                stn_id = argv_next.pop(0)
                resource.resource_remove(stn_id)
            else:
                raise CmdLineInputError()
        elif sub_cmd == "show":
            resource.resource_show(argv_next, True)
            levels = stonith_level_config_to_str(
                lib.fencing_topology.get_config()
            )
            if levels:
                print("\n".join(indent(levels, 1)))
        elif sub_cmd == "level":
            stonith_level_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "fence":
            stonith_fence(argv_next)
        elif sub_cmd == "cleanup":
            resource.resource_cleanup(argv_next)
        elif sub_cmd == "confirm":
            stonith_confirm(argv_next)
        elif sub_cmd == "get_fence_agent_info":
            get_fence_agent_info(argv_next)
        elif sub_cmd == "sbd":
            sbd_cmd(lib, argv_next, modifiers)
        elif sub_cmd == "enable":
            resource.resource_enable(argv_next)
        elif sub_cmd == "disable":
            resource.resource_disable(argv_next)
        else:
            raise CmdLineInputError()
    except LibraryError as e:
        utils.process_library_reports(e.args)
    except CmdLineInputError as e:
        utils.exit_on_cmdline_input_errror(e, "stonith", sub_cmd)
Example #17
0
def alert_config_lines(lib):
    lines = ["Alerts:"]
    alert_list = lib.alert.get_all_alerts()
    if alert_list:
        for alert in alert_list:
            lines.extend(indent(_alert_to_str(alert), 1))
    else:
        lines.append(" No alerts defined")
    return lines
Example #18
0
def alert_config_lines(lib):
    lines = ["Alerts:"]
    alert_list = lib.alert.get_all_alerts()
    if alert_list:
        for alert in alert_list:
            lines.extend(indent(_alert_to_str(alert), 1))
    else:
        lines.append(" No alerts defined")
    return lines
Example #19
0
def print_alert_config(lib, argv, modifiers):
    if argv:
        raise CmdLineInputError()

    print("Alerts:")
    alert_list = lib.alert.get_all_alerts()
    if alert_list:
        for alert in alert_list:
            print("\n".join(indent(_alert_to_str(alert), 1)))
    else:
        print(" No alerts defined")
Example #20
0
 def test_indent_list_of_lines(self):
     self.assertEqual(
         indent([
             "first",
             "second"
         ]),
         [
             "  first",
             "  second"
         ]
     )
Example #21
0
 def test_indent_list_of_lines(self):
     self.assertEqual(
         indent([
             "first",
             "second"
         ]),
         [
             "  first",
             "  second"
         ]
     )
Example #22
0
def print_alert_config(lib, argv, modifiers):
    if argv:
        raise CmdLineInputError()

    print("Alerts:")
    alert_list = lib.alert.get_all_alerts()
    if alert_list:
        for alert in alert_list:
            print("\n".join(indent(_alert_to_str(alert), 1)))
    else:
        print(" No alerts defined")
Example #23
0
def show_constraints_with_set(constraint_list, show_detail, indent_step=2):
    """
    return list of console lines with info about constraints
    list of dict constraint_list see constraint in pcs/lib/exchange_formats.md
    bool with_id have to show id with options
    int indent_step is count of spaces for indenting
    """
    return ["Resource Sets:"] + indent([
        console_report.constraint_with_sets(constraint, with_id=show_detail)
        for constraint in constraint_list
    ],
                                       indent_step=indent_step)
Example #24
0
def show_constraints_with_set(constraint_list, show_detail, indent_step=2):
    """
    return list of console lines with info about constraints
    list of dict constraint_list see constraint in pcs/lib/exchange_formats.md
    bool with_id have to show id with options
    int indent_step is count of spaces for indenting
    """
    return ["Resource Sets:"] + indent(
        [
            console_report.constraint_with_sets(constraint, with_id=show_detail)
            for constraint in constraint_list
        ],
        indent_step=indent_step
    )
Example #25
0
def config_show(argv):
    print("Cluster Name: %s" % utils.getClusterName())
    status.nodes_status(["config"])
    print()
    config_show_cib()
    cluster.cluster_uidgid([], True)
    if "--corosync_conf" in utils.pcs_options or not utils.is_rhel6():
        print()
        print("Quorum:")
        try:
            config = lib_quorum.get_config(utils.get_lib_env())
            print("\n".join(indent(quorum.quorum_config_to_str(config))))
        except LibraryError as e:
            utils.process_library_reports(e.args)
Example #26
0
def print_alert_config(lib, argv, modifiers):
    """
    Options:
      * -f - CIB file (in lib wrapper)
    """
    modifiers.ensure_only_supported("-f")
    if argv:
        raise CmdLineInputError()

    print("Alerts:")
    alert_list = lib.alert.get_all_alerts()
    if alert_list:
        for alert in alert_list:
            print("\n".join(indent(_alert_to_str(alert), 1)))
    else:
        print(" No alerts defined")
Example #27
0
def full_status():
    if "--hide-inactive" in utils.pcs_options and "--full" in utils.pcs_options:
        utils.err("you cannot specify both --hide-inactive and --full")

    monitor_command = ["crm_mon", "--one-shot"]
    if "--hide-inactive" not in utils.pcs_options:
        monitor_command.append('--inactive')
    if "--full" in utils.pcs_options:
        monitor_command.extend(
            ["--show-detail", "--show-node-attributes", "--failcounts"])

    output, retval = utils.run(monitor_command)

    if (retval != 0):
        utils.err("cluster is not currently running on this node")

    if not utils.usefile or "--corosync_conf" in utils.pcs_options:
        cluster_name = utils.getClusterName()
        print("Cluster name: %s" % cluster_name)

    status_stonith_check()

    if (not utils.usefile and not utils.is_rhel6()
            and utils.corosyncPacemakerNodeCheck()):
        print(
            "WARNING: corosync and pacemaker node names do not match (IPs used in setup?)"
        )

    print(output)

    if "--full" in utils.pcs_options:
        tickets, retval = utils.run(["crm_ticket", "-L"])
        if retval != 0:
            print("WARNING: Unable to get information about tickets")
            print()
        elif tickets:
            print("Tickets:")
            print("\n".join(indent(tickets.split("\n"))))

    if not utils.usefile:
        if "--full" in utils.pcs_options and utils.hasCorosyncConf():
            print_pcsd_daemon_status()
            print()
        utils.serviceStatus("  ")
Example #28
0
def config_show_cib(lib):
    """
    Commandline options:
      * -f - CIB file
    """
    print("Resources:")
    # update of pcs_options will change output of constraint show
    utils.pcs_options["--full"] = 1
    # get latest modifiers object after updating pcs_options
    modifiers = utils.get_input_modifiers()
    resource.resource_config(lib, [], modifiers.get_subset("-f"))

    print()
    print("Stonith Devices:")
    resource.resource_config(
        lib,
        [],
        modifiers.get_subset("-f"),
        stonith=True,
    )
    print("Fencing Levels:")
    levels = stonith.stonith_level_config_to_str(
        lib.fencing_topology.get_config())
    if levels:
        print("\n".join(indent(levels, 2)))

    print()
    constraint.location_show(lib, [], modifiers.get_subset("-f", "--full"))
    order_command.show(lib, [], modifiers.get_subset("-f", "--full"))
    colocation_command.show(lib, [], modifiers.get_subset("-f", "--full"))
    ticket_command.show(lib, [], modifiers.get_subset("-f", "--full"))

    print()
    alert.print_alert_config(lib, [], modifiers.get_subset("-f"))

    print()
    print("Resources Defaults:")
    resource.show_defaults("rsc_defaults", indent=" ")
    print("Operations Defaults:")
    resource.show_defaults("op_defaults", indent=" ")
    print()
    prop.list_property(lib, [],
                       modifiers.get_subset("--defaults", "--all", "-f"))
Example #29
0
def config_show(lib, argv, modifiers):
    """
    Options:
      * -f - CIB file, when getting cluster name on remote node (corosync.conf
        doesn't exist)
      * --corosync_conf - corosync.conf file
    """
    modifiers.ensure_only_supported("-f", "--corosync_conf")
    if argv:
        raise CmdLineInputError()
    print("Cluster Name: %s" % utils.getClusterName())
    status.nodes_status(lib, ["config"], modifiers.get_subset("-f"))
    print()
    print("\n".join(_config_show_cib_lines(lib)))
    if (
        utils.hasCorosyncConf()
        and
        not modifiers.is_specified("-f")
        and
        not modifiers.is_specified("--corosync_conf")
    ):
        cluster.cluster_uidgid(
            lib, [], modifiers.get_subset(), silent_list=True
        )
    if (
        modifiers.is_specified("--corosync_conf")
        or
        utils.hasCorosyncConf()
    ):
        print()
        print("Quorum:")
        try:
            config = lib_quorum.get_config(utils.get_lib_env())
            print("\n".join(indent(quorum.quorum_config_to_str(config))))
        except LibraryError as e:
            utils.process_library_reports(e.args)
Example #30
0
def config_show_cib():
    lib = utils.get_library_wrapper()
    modificators = utils.get_modificators()

    print("Resources:")
    utils.pcs_options["--all"] = 1
    utils.pcs_options["--full"] = 1
    resource.resource_show([])

    print()
    print("Stonith Devices:")
    resource.resource_show([], True)
    print("Fencing Levels:")
    levels = stonith.stonith_level_config_to_str(
        lib.fencing_topology.get_config()
    )
    if levels:
        print("\n".join(indent(levels, 2)))

    print()
    constraint.location_show([])
    order_command.show(lib, [], modificators)
    colocation_command.show(lib, [], modificators)
    ticket_command.show(lib, [], modificators)

    print()
    alert.print_alert_config(lib, [], modificators)

    print()
    del utils.pcs_options["--all"]
    print("Resources Defaults:")
    resource.show_defaults("rsc_defaults", indent=" ")
    print("Operations Defaults:")
    resource.show_defaults("op_defaults", indent=" ")
    print()
    prop.list_property([])
Example #31
0
def _target_group_to_str(type_name, obj):
    return ["{0}: {1}".format(type_name.title(), obj.get("id"))] + indent(
        [" ".join(["Roles:"] + obj.get("role_list", []))]
    )
Example #32
0
def print_stonith_levels(lib):
    levels = stonith_level_config_to_str(lib.fencing_topology.get_config())
    if levels:
        print("\n".join(indent(levels, 1)))
Example #33
0
def role_to_str(role):
    out = []
    if role.get("description"):
        out.append("Description: {0}".format(role.get("description")))
    out += map(_permission_to_str, role.get("permission_list", []))
    return ["Role: {0}".format(role.get("id"))] + indent(out)
Example #34
0
def _target_group_to_str(type_name, obj):
    return ["{0}: {1}".format(type_name.title(), obj.get("id"))] + indent(
        [" ".join(["Roles:"] + obj.get("role_list", []))])
Example #35
0
def _recipient_to_str(recipient):
    return ["Recipient: {id} (value={value})".format(
        value=recipient["value"], id=recipient["id"]
    )] + indent(__description_attributes_to_str(recipient), 1)
Example #36
0
def _recipient_to_str(recipient):
    return [
        "Recipient: {id} (value={value})".format(value=recipient["value"],
                                                 id=recipient["id"])
    ] + indent(__description_attributes_to_str(recipient), 1)
Example #37
0
def role_to_str(role):
    out = []
    if role.get("description"):
        out.append("Description: {0}".format(role.get("description")))
    out += map(_permission_to_str, role.get("permission_list", []))
    return ["Role: {0}".format(role.get("id"))] + indent(out)
Example #38
0
def full_status(lib, argv, modifiers):
    """
    Options:
      * --hide-inactive - hide inactive resources
      * --full - show full details, node attributes and failcount
      * -f - CIB file, crm_mon accepts CIB_file environment variable
      * --corosync_conf - file corocync.conf
      * --request-timeout - HTTP timeout for node authorization check
    """
    modifiers.ensure_only_supported(
        "--hide-inactive",
        "--full",
        "-f",
        "--corosync_conf",
        "--request-timeout",
    )
    if argv:
        raise CmdLineInputError()
    if (modifiers.is_specified("--hide-inactive")
            and modifiers.is_specified("--full")):
        utils.err("you cannot specify both --hide-inactive and --full")

    monitor_command = [
        os.path.join(settings.pacemaker_binaries, "crm_mon"), "--one-shot"
    ]
    if not modifiers.get("--hide-inactive"):
        monitor_command.append('--inactive')
    if modifiers.get("--full"):
        monitor_command.extend(
            ["--show-detail", "--show-node-attributes", "--failcounts"])
        # by default, pending and failed actions are displayed
        # with --full, we display the whole history
        if is_fence_history_supported():
            monitor_command.append("--fence-history=3")

    stdout, stderr, retval = utils.cmd_runner().run(monitor_command)

    if retval != 0:
        utils.err("cluster is not currently running on this node")

    warnings = []
    if stderr.strip():
        for line in stderr.strip().splitlines():
            if line.startswith("DEBUG: "):
                if modifiers.get("--full"):
                    warnings.append(line)
            else:
                warnings.append(line)
    warnings.extend(status_stonith_check(modifiers))

    print("Cluster name: %s" % utils.getClusterName())
    if warnings:
        print()
        print("WARNINGS:")
        print("\n".join(warnings))
        print()
    print(stdout)

    if modifiers.get("--full"):
        tickets, retval = utils.run(["crm_ticket", "-L"])
        if retval != 0:
            print("WARNING: Unable to get information about tickets")
            print()
        elif tickets:
            print("Tickets:")
            print("\n".join(indent(tickets.split("\n"))))

    if not (modifiers.is_specified("-f")
            or modifiers.is_specified("--corosync_conf")):
        # do this only if in live environment
        if modifiers.get("--full"):
            print_pcsd_daemon_status(lib, modifiers)
            print()
        utils.serviceStatus("  ")
Example #39
0
def _config_show_cib_lines(lib):
    """
    Commandline options:
      * -f - CIB file
    """
    # update of pcs_options will change output of constraint show
    utils.pcs_options["--full"] = 1
    # get latest modifiers object after updating pcs_options
    modifiers = utils.get_input_modifiers()
    cib_xml = utils.get_cib()
    cib_etree = utils.get_cib_etree(cib_xml=cib_xml)
    cib_dom = utils.get_cib_dom(cib_xml=cib_xml)

    resource_lines = []
    stonith_lines = []
    for resource_el in cib_etree.find(".//resources"):
        is_stonith = ("class" in resource_el.attrib
                      and resource_el.attrib["class"] == "stonith")
        resource_el_lines = resource.resource_node_lines(resource_el)
        if is_stonith:
            stonith_lines += resource_el_lines
        else:
            resource_lines += resource_el_lines

    all_lines = []

    all_lines.append("Resources:")
    all_lines.extend(indent(resource_lines, indent_step=1))
    all_lines.append("")
    all_lines.append("Stonith Devices:")
    all_lines.extend(indent(stonith_lines, indent_step=1))
    all_lines.append("Fencing Levels:")
    levels_lines = stonith.stonith_level_config_to_str(
        lib.fencing_topology.get_config())
    if levels_lines:
        all_lines.extend(indent(levels_lines, indent_step=2))

    all_lines.append("")
    constraints_element = cib_dom.getElementsByTagName('constraints')[0]
    all_lines.extend(
        constraint.location_lines(constraints_element,
                                  showDetail=True,
                                  show_expired=True,
                                  verify_expiration=False))
    all_lines.extend(
        constraint_command.show(
            "Ordering Constraints:",
            lib.constraint_order.show,
            order_console_report.constraint_plain,
            modifiers.get_subset("-f", "--full"),
        ))
    all_lines.extend(
        constraint_command.show(
            "Colocation Constraints:",
            lib.constraint_colocation.show,
            colocation_console_report.constraint_plain,
            modifiers.get_subset("-f", "--full"),
        ))
    all_lines.extend(
        constraint_command.show(
            "Ticket Constraints:",
            lib.constraint_ticket.show,
            ticket_console_report.constraint_plain,
            modifiers.get_subset("-f", "--full"),
        ))

    all_lines.append("")
    all_lines.extend(alert.alert_config_lines(lib))

    all_lines.append("")
    all_lines.append("Resources Defaults:")
    all_lines.extend(
        indent(resource.show_defaults(cib_dom, "rsc_defaults"), indent_step=1))
    all_lines.append("Operations Defaults:")
    all_lines.extend(
        indent(resource.show_defaults(cib_dom, "op_defaults"), indent_step=1))

    all_lines.append("")
    all_lines.append("Cluster Properties:")
    properties = utils.get_set_properties()
    all_lines.extend(
        indent([
            "{0}: {1}".format(prop, val)
            for prop, val in sorted(properties.items())
        ],
               indent_step=1))
    return all_lines
Example #40
0
def print_stonith_levels(lib):
    levels = stonith_level_config_to_str(
        lib.fencing_topology.get_config()
    )
    if levels:
        print("\n".join(indent(levels, 1)))
Example #41
0
def _config_show_cib_lines(lib):
    """
    Commandline options:
      * -f - CIB file
    """
    # update of pcs_options will change output of constraint show
    utils.pcs_options["--full"] = 1
    # get latest modifiers object after updating pcs_options
    modifiers = utils.get_input_modifiers()
    cib_xml = utils.get_cib()
    cib_etree = utils.get_cib_etree(cib_xml=cib_xml)
    cib_dom = utils.get_cib_dom(cib_xml=cib_xml)

    resource_lines = []
    stonith_lines = []
    for resource_el in cib_etree.find(".//resources"):
        is_stonith = (
            "class" in resource_el.attrib
            and
            resource_el.attrib["class"] == "stonith"
        )
        resource_el_lines = resource.resource_node_lines(resource_el)
        if is_stonith:
            stonith_lines += resource_el_lines
        else:
            resource_lines += resource_el_lines

    all_lines = []

    all_lines.append("Resources:")
    all_lines.extend(indent(resource_lines, indent_step=1))
    all_lines.append("")
    all_lines.append("Stonith Devices:")
    all_lines.extend(indent(stonith_lines, indent_step=1))
    all_lines.append("Fencing Levels:")
    levels_lines = stonith.stonith_level_config_to_str(
        lib.fencing_topology.get_config()
    )
    if levels_lines:
        all_lines.extend(indent(levels_lines, indent_step=2))

    all_lines.append("")
    constraints_element = cib_dom.getElementsByTagName('constraints')[0]
    all_lines.extend(
        constraint.location_lines(constraints_element, showDetail=True)
    )
    all_lines.extend(constraint_command.show(
        "Ordering Constraints:",
        lib.constraint_order.show,
        order_console_report.constraint_plain,
        modifiers.get_subset("-f", "--full"),
    ))
    all_lines.extend(constraint_command.show(
         "Colocation Constraints:",
        lib.constraint_colocation.show,
        colocation_console_report.constraint_plain,
        modifiers.get_subset("-f", "--full"),
    ))
    all_lines.extend(constraint_command.show(
        "Ticket Constraints:",
        lib.constraint_ticket.show,
        ticket_console_report.constraint_plain,
        modifiers.get_subset("-f", "--full"),
    ))

    all_lines.append("")
    all_lines.extend(alert.alert_config_lines(lib))

    all_lines.append("")
    all_lines.append("Resources Defaults:")
    all_lines.extend(indent(
        resource.show_defaults(cib_dom, "rsc_defaults"),
        indent_step=1
    ))
    all_lines.append("Operations Defaults:")
    all_lines.extend(indent(
        resource.show_defaults(cib_dom, "op_defaults"),
        indent_step=1
    ))

    all_lines.append("")
    all_lines.append("Cluster Properties:")
    properties = utils.get_set_properties()
    all_lines.extend(indent(
        [
            "{0}: {1}".format(prop, val)
            for prop, val in sorted(properties.items())
        ],
        indent_step=1
    ))
    return all_lines