Esempio n. 1
0
def _check_nodes(node_list, prefix=""):
    """
    Print pcsd status on node_list, return if there is any pcsd not online

    Commandline options:
      * --request-timeout - HTTP timeout for node authorization check
    """
    online_code = 0
    status_desc_map = {online_code: "Online", 3: "Unable to authenticate"}
    status_list = []

    def report(node, returncode, output):
        del output
        print(
            "{0}{1}: {2}".format(
                prefix, node, status_desc_map.get(returncode, "Offline")
            )
        )
        status_list.append(returncode)

    utils.read_known_hosts_file()  # cache known hosts
    utils.run_parallel(
        utils.create_task_list(report, utils.checkAuthorization, node_list)
    )

    return any(status != online_code for status in status_list)
Esempio n. 2
0
def deauth_cmd(lib, argv, modifiers):
    if len(argv) < 1:
        # Object of type 'dict_keys' is not JSON serializable, make it a list
        remove_hosts = list(utils.read_known_hosts_file().keys())
    else:
        remove_hosts = argv
    output, retval = utils.run_pcsdcli('remove_known_hosts',
                                       {'host_names': remove_hosts})
    if retval == 0 and output['status'] == 'access_denied':
        utils.err('Access denied')
    if retval == 0 and output['status'] == 'ok' and output['data']:
        try:
            if output["data"]["hosts_not_found"]:
                utils.err("Following hosts were not found: '{hosts}'".format(
                    hosts="', '".join(output["data"]["hosts_not_found"])))
            if not output['data']['sync_successful']:
                utils.err(
                    "Some nodes had a newer known-hosts than the local node. "
                    + "Local node's known-hosts were updated. " +
                    "Please repeat the action if needed.")
            if output['data']['sync_nodes_err']:
                utils.err(
                    ("Unable to synchronize and save known-hosts on nodes: " +
                     "{0}. Run 'pcs host auth {1}' to make sure the nodes " +
                     "are authorized.").format(
                         ", ".join(output['data']['sync_nodes_err']),
                         " ".join(output['data']['sync_nodes_err'])))
        except (ValueError, KeyError):
            utils.err('Unable to communicate with pcsd')
        return
    utils.err('Unable to communicate with pcsd')
Esempio n. 3
0
def deauth_cmd(lib, argv, modifiers):
    # pylint: disable=unused-argument
    """
    Options:
      * --request-timeout - timeout for HTTP requests
    """
    modifiers.ensure_only_supported("--request-timeout")
    if not argv:
        # Object of type 'dict_keys' is not JSON serializable, make it a list
        remove_hosts = list(utils.read_known_hosts_file().keys())
    else:
        remove_hosts = argv
    output, retval = utils.run_pcsdcli(
        'remove_known_hosts',
        {'host_names': remove_hosts}
    )
    if retval == 0 and output['status'] == 'access_denied':
        utils.err('Access denied')
    if retval == 0 and output['status'] == 'ok' and output['data']:
        try:
            if output["data"]["hosts_not_found"]:
                utils.err("Following hosts were not found: '{hosts}'".format(
                    hosts="', '".join(output["data"]["hosts_not_found"])
                ))
            if not output['data']['sync_successful']:
                utils.err(
                    "Some nodes had a newer known-hosts than the local node. "
                        + "Local node's known-hosts were updated. "
                        + "Please repeat the action if needed."
                )
            if output['data']['sync_nodes_err']:
                utils.err(
                    (
                        "Unable to synchronize and save known-hosts on nodes: "
                        + "{0}. Run 'pcs host auth {1}' to make sure the nodes "
                        + "are authorized."
                    ).format(
                        ", ".join(output['data']['sync_nodes_err']),
                        " ".join(output['data']['sync_nodes_err'])
                    )
                )
        except (ValueError, KeyError):
            utils.err('Unable to communicate with pcsd')
        return
    utils.err('Unable to communicate with pcsd')
Esempio n. 4
0
def deauth_cmd(lib, argv, modifiers):
    # pylint: disable=unused-argument
    """
    Options:
      * --request-timeout - timeout for HTTP requests
    """
    modifiers.ensure_only_supported("--request-timeout")
    if not argv:
        # Object of type 'dict_keys' is not JSON serializable, make it a list
        remove_hosts = list(utils.read_known_hosts_file().keys())
    else:
        remove_hosts = argv
    output, retval = utils.run_pcsdcli("remove_known_hosts",
                                       {"host_names": remove_hosts})
    if retval == 0 and output["status"] == "access_denied":
        utils.err("Access denied")
    if retval == 0 and output["status"] == "ok" and output["data"]:
        try:
            if output["data"]["hosts_not_found"]:
                utils.err("Following hosts were not found: '{hosts}'".format(
                    hosts="', '".join(output["data"]["hosts_not_found"])))
            if not output["data"]["sync_successful"]:
                utils.err(
                    "Some nodes had a newer known-hosts than the local node. "
                    + "Local node's known-hosts were updated. " +
                    "Please repeat the action if needed.")
            if output["data"]["sync_nodes_err"]:
                utils.err(
                    ("Unable to synchronize and save known-hosts on nodes: " +
                     "{0}. Run 'pcs host auth {1}' to make sure the nodes " +
                     "are authorized.").format(
                         ", ".join(output["data"]["sync_nodes_err"]),
                         " ".join(output["data"]["sync_nodes_err"]),
                     ))
        except (ValueError, KeyError):
            utils.err("Unable to communicate with pcsd")
        return
    utils.err("Unable to communicate with pcsd")