예제 #1
0
def run_loop(action, options):
    assert callable(action)
    loop = asyncio.get_event_loop()

    print_header('START {}'.format(action.__name__))
    try:
        config = dcos_installer.config.Config(
            dcos_installer.constants.CONFIG_PATH)
        cli_delegate = CliDelegate()
        result = loop.run_until_complete(
            action(config,
                   block=True,
                   async_delegate=cli_delegate,
                   options=options))
        pp = PrettyPrint(result)
        pp.stage_name = action.__name__
        pp.beautify('print_data')

    finally:
        loop.close()
    exitcode = 0
    for host_result in result:
        for command_result in host_result:
            for host, process_result in command_result.items():
                if process_result['returncode'] != 0:
                    exitcode += 1
    print_header('ACTION {} COMPLETE'.format(action.__name__))
    pp.print_summary()
    return exitcode
예제 #2
0
파일: cli.py 프로젝트: some-things/dcos
def dispatch(args):
    """ Dispatches the selected mode based on command line args. """
    if args.action == 'hash-password':
        # TODO(cmaloney): Import a function from the auth stuff to do the hashing and guarantee it
        # always matches
        byte_str = do_hash_password(args.password).encode('ascii')
        sys.stdout.buffer.write(byte_str + b'\n')
        sys.exit(0)

    if args.action == 'generate-node-upgrade-script':
        status = backend.generate_node_upgrade_script(
            args.installed_cluster_version)
        sys.exit(status)

    if args.action == 'generate-node-upgrade-win-script':
        status = backend.generate_node_upgrade_win_script(
            args.installed_cluster_version)
        sys.exit(status)

    if args.action in dispatch_dict_simple:
        action = dispatch_dict_simple[args.action]
        if action[1] is not None:
            print_header(action[1])
        sys.exit(action[0](args))

    print("Internal Error: No known way to dispatch {}".format(args.action))
    sys.exit(1)
예제 #3
0
파일: cli.py 프로젝트: zouyee/dcos
def do_hash_password(password):
    if password is None:
        password = ''
        while True:
            password = input('Password: '******'Must provide a non-empty password')

    print_header("HASHING PASSWORD TO SHA512")
    hashed_password = sha512_crypt.encrypt(password)
    return hashed_password
예제 #4
0
파일: cli.py 프로젝트: kernt/dcos-1
def dispatch(args):
    """ Dispatches the selected mode based on command line args. """
    if args.action == 'set-superuser-password':
        password_hash = do_hash_password(args.password)
        messages = backend.create_config_from_post(
            {'superuser_password_hash': password_hash},
            dcos_installer.constants.CONFIG_PATH)
        if messages:
            log.error("Unable to save password: {}".format(messages))
            sys.exit(1)
        sys.exit(0)

    if args.action == 'hash-password':
        # TODO(cmaloney): Import a function from the auth stuff to do the hashing and guarantee it
        # always matches
        byte_str = do_hash_password(args.password).encode('ascii')
        sys.stdout.buffer.write(byte_str + b'\n')
        sys.exit(0)

    if args.action == 'generate-node-upgrade-script':
        status = backend.generate_node_upgrade_script(
            args.installed_cluster_version)
        sys.exit(status)

    if args.action in dispatch_dict_simple:
        action = dispatch_dict_simple[args.action]
        if action[1] is not None:
            print_header(action[1])
        sys.exit(action[0](args))

    # Dispatches CLI options which are installer actions ran through AIO event loop
    if args.action in dispatch_dict_aio:
        action = dispatch_dict_aio[args.action]
        if do_validate_config(args) != 0:
            sys.exit(1)
        if action[1] is not None:
            print_header(action[1])
        errors = run_loop(action[0], args)
        if not args.cli_telemetry_disabled:
            installer_analytics.send(
                action=args.action,
                install_method="cli",
                num_errors=errors,
            )
        sys.exit(1 if errors > 0 else 0)

    print("Internal Error: No known way to dispatch {}".format(args.action))
    sys.exit(1)
예제 #5
0
파일: cli.py 프로젝트: malnick/dcos
def dispatch(args):
    """ Dispatches the selected mode based on command line args. """
    if args.action == 'set-superuser-password':
        password_hash = do_hash_password(args.password)
        messages = backend.create_config_from_post(
            {'superuser_password_hash': password_hash},
            dcos_installer.constants.CONFIG_PATH)
        if messages:
            log.error("Unable to save password: {}".format(messages))
            sys.exit(1)
        sys.exit(0)

    if args.action == 'hash-password':
        # TODO(cmaloney): Import a function from the auth stuff to do the hashing and guarantee it
        # always matches
        byte_str = do_hash_password(args.password).encode('ascii')
        sys.stdout.buffer.write(byte_str + b'\n')
        sys.exit(0)

    if args.action == 'generate-node-upgrade-script':
        status = backend.generate_node_upgrade_script(args.installed_cluster_version)
        sys.exit(status)

    if args.action in dispatch_dict_simple:
        action = dispatch_dict_simple[args.action]
        if action[1] is not None:
            print_header(action[1])
        sys.exit(action[0](args))

    # Dispatches CLI options which are installer actions ran through AIO event loop
    if args.action in dispatch_dict_aio:
        action = dispatch_dict_aio[args.action]
        if do_validate_config(args) != 0:
            sys.exit(1)
        if action[1] is not None:
            print_header(action[1])
        errors = run_loop(action[0], args)
        if not args.cli_telemetry_disabled:
            installer_analytics.send(
                action=args.action,
                install_method="cli",
                num_errors=errors,
            )
        sys.exit(1 if errors > 0 else 0)

    print("Internal Error: No known way to dispatch {}".format(args.action))
    sys.exit(1)
예제 #6
0
파일: cli.py 프로젝트: enst/dcos
def dispatch(args):
    """ Dispatches the selected mode based on command line args. """
    if getattr(args, 'set_superuser_password'):
        assert len(args.set_superuser_password) == 1
        password_hash = do_hash_password(args.set_superuser_password[0])
        err, messages = backend.create_config_from_post(
            {'superuser_password_hash': password_hash})
        if err:
            log.error("Unable to save password: {}".format(messages))
            sys.exit(1)
        sys.exit(0)

    if getattr(args, 'hash_password'):
        assert len(args.hash_password) == 1
        # TODO(cmaloney): Import a function from the auth stuff to do the hashing and guarantee it
        # always matches
        byte_str = do_hash_password(args.hash_password[0]).encode('ascii')
        sys.stdout.buffer.write(byte_str + b'\n')
        sys.exit(0)

    if args.action in dispatch_dict_simple:
        action = dispatch_dict_simple[args.action]
        if action[1] is not None:
            print_header(action[1])
        sys.exit(action[0](args))

    # Dispatches CLI options which are installer actions ran through AIO event loop
    if args.action in dispatch_dict_aio:
        action = dispatch_dict_aio[args.action]
        if do_validate_config(args) != 0:
            sys.exit(1)
        if action[1] is not None:
            print_header(action[1])
        errors = run_loop(action[0], args)
        if not args.cli_telemetry_disabled:
            installer_analytics.send(
                action=args.action,
                install_method="cli",
                num_errors=errors,
            )
        sys.exit(1 if errors > 0 else 0)

    print("Internal Error: No known way to dispatch {}".format(args.action))
    sys.exit(1)
예제 #7
0
파일: cli.py 프로젝트: joerg84/dcos
def dispatch(args):
    """ Dispatches the selected mode based on command line args. """
    if getattr(args, 'set_superuser_password'):
        assert len(args.set_superuser_password) == 1
        password_hash = do_hash_password(args.set_superuser_password[0])
        err, messages = backend.create_config_from_post({'superuser_password_hash': password_hash})
        if err:
            log.error("Unable to save password: {}".format(messages))
            sys.exit(1)
        sys.exit(0)

    if getattr(args, 'hash_password'):
        assert len(args.hash_password) == 1
        # TODO(cmaloney): Import a function from the auth stuff to do the hashing and guarantee it
        # always matches
        byte_str = do_hash_password(args.hash_password[0]).encode('ascii')
        sys.stdout.buffer.write(byte_str + b'\n')
        sys.exit(0)

    if args.action in dispatch_dict_simple:
        action = dispatch_dict_simple[args.action]
        if action[1] is not None:
            print_header(action[1])
        sys.exit(action[0](args))

    # Dispatches CLI options which are installer actions ran through AIO event loop
    if args.action in dispatch_dict_aio:
        action = dispatch_dict_aio[args.action]
        if do_validate_config(args) != 0:
            sys.exit(1)
        if action[1] is not None:
            print_header(action[1])
        errors = run_loop(action[0], args)
        if not args.cli_telemetry_disabled:
            installer_analytics.send(
                action=args.action,
                install_method="cli",
                num_errors=errors,
            )
        sys.exit(1 if errors > 0 else 0)

    print("Internal Error: No known way to dispatch {}".format(args.action))
    sys.exit(1)
예제 #8
0
파일: cli.py 프로젝트: alberts/dcos
def run_loop(action, options):
    assert callable(action)
    loop = asyncio.get_event_loop()

    print_header('START {}'.format(action.__name__))
    try:
        config = dcos_installer.config.Config(dcos_installer.constants.CONFIG_PATH)
        cli_delegate = CliDelegate()
        result = loop.run_until_complete(action(config, block=True, async_delegate=cli_delegate, options=options))
        pp = PrettyPrint(result)
        pp.stage_name = action.__name__
        pp.beautify('print_data')

    finally:
        loop.close()
    exitcode = 0
    for host_result in result:
        for command_result in host_result:
            for host, process_result in command_result.items():
                if process_result['returncode'] != 0:
                    exitcode += 1
    print_header('ACTION {} COMPLETE'.format(action.__name__))
    pp.print_summary()
    return exitcode
예제 #9
0
파일: cli.py 프로젝트: zouyee/dcos
 def on_done(self, name, result, host_status=None):
     print_header('STAGE {}'.format(name))