Exemplo n.º 1
0
def auth_cmd(lib, argv, modifiers):
    # pylint: disable=unused-argument
    """
    Options:
      * -u - username
      * -p - password
      * --token - auth token
      * --request-timeout - timeout for HTTP requests
    """
    modifiers.ensure_only_supported("-u", "-p", "--request-timeout", "--token")
    if not argv:
        raise CmdLineInputError("No host specified")
    host_dict = {
        host: _parse_host_options(host, opts)
        for host, opts in parse_args.split_list_by_any_keywords(
            argv, "host name").items()
    }
    token = modifiers.get("--token")
    if token:
        token_value = utils.get_token_from_file(token)
        for host_info in host_dict.values():
            host_info.update(dict(token=token_value))
        utils.auth_hosts_token(host_dict)
        return
    username, password = utils.get_user_and_pass()
    for host_info in host_dict.values():
        host_info.update(dict(username=username, password=password))
    utils.auth_hosts(host_dict)
Exemplo n.º 2
0
def auth_cmd(lib, argv, modifiers):
    if not argv:
        raise CmdLineInputError("No host specified")
    host_dict = {
        host: _parse_host_options(host, opts)
        for host, opts in parse_args.split_list_by_any_keywords(
            argv, "host name").items()
    }
    username, password = utils.get_user_and_pass()
    for host_info in host_dict.values():
        host_info.update(dict(username=username, password=password))
    utils.auth_hosts(host_dict)
Exemplo n.º 3
0
Arquivo: host.py Projeto: gmelikov/pcs
def auth_cmd(lib, argv, modifiers):
    """
    Options:
      * -u - username
      * -p - password
      * --request-timeout - timeout for HTTP requests
    """
    modifiers.ensure_only_supported("-u", "-p", "--request-timeout")
    if not argv:
        raise CmdLineInputError("No host specified")
    host_dict = {
        host: _parse_host_options(host, opts)
        for host, opts in parse_args.split_list_by_any_keywords(
            argv, "host name").items()
    }
    username, password = utils.get_user_and_pass()
    for host_info in host_dict.values():
        host_info.update(dict(username=username, password=password))
    utils.auth_hosts(host_dict)
Exemplo n.º 4
0
def local_auth_cmd(lib, argv, modifiers):
    """
    Options:
      * -u - username
      * -p - password
      * --request-timeout - timeout for HTTP requests
    """
    modifiers.ensure_only_supported("-u", "-p", "--request-timeout")
    if len(argv) > 1:
        raise CmdLineInputError()
    port = argv[0] if argv else settings.pcsd_default_port
    username, password = utils.get_user_and_pass()
    utils.auth_hosts(
        {
            "localhost": {
                "username": username,
                "password": password,
                "dest_list": [{"addr": "localhost", "port": port}]
            }
        }
    )
Exemplo n.º 5
0
def local_auth_cmd(lib, argv, modifiers):
    """
    Options:
      * -u - username
      * -p - password
      * --request-timeout - timeout for HTTP requests
    """
    del lib
    modifiers.ensure_only_supported("-u", "-p", "--request-timeout")
    if len(argv) > 1:
        raise CmdLineInputError()
    port = argv[0] if argv else settings.pcsd_default_port
    username, password = utils.get_user_and_pass()
    utils.auth_hosts(
        {
            "localhost": {
                "username": username,
                "password": password,
                "dest_list": [{"addr": "localhost", "port": port}]
            }
        }
    )
Exemplo n.º 6
0
def auth_cmd(lib, argv, modifiers):
    # pylint: disable=unused-argument
    """
    Options:
      * -u - username
      * -p - password
      * --request-timeout - timeout for HTTP requests
    """
    modifiers.ensure_only_supported("-u", "-p", "--request-timeout")
    if not argv:
        raise CmdLineInputError("No host specified")
    host_dict = {
        host: _parse_host_options(host, opts)
        for host, opts in parse_args.split_list_by_any_keywords(
            argv,
            "host name"
        ).items()
    }
    username, password = utils.get_user_and_pass()
    for host_info in host_dict.values():
        host_info.update(dict(username=username, password=password))
    utils.auth_hosts(host_dict)
Exemplo n.º 7
0
def cluster_auth_cmd(lib, argv, modifiers):
    if argv:
        raise CmdLineInputError()
    lib_env = utils.get_lib_env()
    target_factory = lib_env.get_node_target_factory()
    cluster_node_list = lib_env.get_corosync_conf().get_nodes()
    cluster_node_names = []
    missing_name = False
    for node in cluster_node_list:
        if node.name:
            cluster_node_names.append(node.name)
        else:
            missing_name = True
    if missing_name:
        print(
            "Warning: Skipping nodes which do not have their name defined in "
            "corosync.conf, use the 'pcs host auth' command to authenticate "
            "them")
    target_list = []
    not_authorized_node_name_list = []
    for node_name in cluster_node_names:
        try:
            target_list.append(target_factory.get_target(node_name))
        except HostNotFound:
            print("{}: Not authorized".format(node_name))
            not_authorized_node_name_list.append(node_name)
    com_cmd = CheckAuth(lib_env.report_processor)
    com_cmd.set_targets(target_list)
    not_authorized_node_name_list.extend(
        run_and_raise(lib_env.get_node_communicator(), com_cmd))
    if not_authorized_node_name_list:
        print("Nodes to authorize: {}".format(
            ", ".join(not_authorized_node_name_list)))
        username, password = utils.get_user_and_pass()
        not_auth_node_list = []
        for node_name in not_authorized_node_name_list:
            for node in cluster_node_list:
                if node.name == node_name:
                    if node.addrs_plain:
                        not_auth_node_list.append(node)
                    else:
                        print(
                            f"{node.name}: No addresses defined in "
                            "corosync.conf, use the 'pcs host auth' command to "
                            "authenticate the node")
        nodes_to_auth_data = {
            node.name: dict(
                username=username,
                password=password,
                dest_list=[
                    dict(
                        addr=node.addrs_plain[0],
                        port=settings.pcsd_default_port,
                    )
                ],
            )
            for node in not_auth_node_list
        }
        utils.auth_hosts(nodes_to_auth_data)
    else:
        print("Sending cluster config files to the nodes...")
        msgs = send_local_configs(cluster_node_names, force=True)
        for msg in msgs:
            print("Warning: {0}".format(msg))