예제 #1
0
def prompt_for_index_in_list(lst, default=1):
    lst = list(lst)

    if default is None:
        input_text = prompts['common.inputtext']
    else:
        input_text = prompts['common.inputtext.default'].format(default)

    for x in range(0, len(lst)):
        io.echo(str(x + 1) + ')', lst[x])

    while True:
        try:
            default = default or 0
            choice = int(io.prompt(input_text, default=default))
            if not (0 < choice <= len(lst)):
                raise ValueError
            else:
                break
        except ValueError:
            io.echo('Sorry, that is not a valid choice. '
                    'Please choose a number between 1 and ' + str(len(lst)) +
                    '.')

    io.echo()
    return choice - 1
예제 #2
0
def setup_credentials(access_id=None, secret_key=None):
    io.log_info('Setting up ~/aws/ directory with config file')

    if access_id is None or secret_key is None:
        io.echo(strings['cred.prompt'])

    if access_id is None:
        access_id = io.prompt('aws-access-id',
                              default='ENTER_AWS_ACCESS_ID_HERE')
    if secret_key is None:
        secret_key = io.prompt('aws-secret-key', default='ENTER_SECRET_HERE')

    fileoperations.save_to_aws_config(access_id, secret_key)

    fileoperations.touch_config_folder()
    fileoperations.write_config_setting('global', 'profile', 'eb-cli')

    aws.set_session_creds(access_id, secret_key)
예제 #3
0
def prompt_for_instance_types():
    """
    Method accepts the user's choice of instance types to be used for spot fleet request

    :return: user's choice of whether the spot request should be enabled
    """
    instance_types = io.prompt(strings['spot.instance_type_defaults_notice'])
    io.echo()
    return instance_types
예제 #4
0
def prompt_for_instance_types():
    """
    Method accepts the user's choice of instance types to be used for spot fleet request

    :return: user's choice of whether the spot request should be enabled
    """
    while True:
        io.echo(strings['spot.instance_types_validation'])
        instance_types = io.prompt(strings['spot.instance_types_example'])
        io.echo('')
        if are_instance_types_valid(instance_types):
            return instance_types
예제 #5
0
파일: utils.py 프로젝트: mschmutz1/jokic
def prompt_for_index_in_list(lst, default=1):
    lst = list(lst)
    for x in range(0, len(lst)):
        io.echo(str(x + 1) + ')', lst[x])

    while True:
        try:
            choice = int(io.prompt('default is ' + str(default),
                                   default=default))
            if not (0 < choice <= len(lst)):
                raise ValueError  # Also thrown by non int numbers
            else:
                break
        except ValueError:
            io.echo('Sorry, that is not a valid choice. '
                    'Please choose a number between 1 and ' +
                    str(len(lst)) + '.')
    return choice - 1
예제 #6
0
def prompt_for_index_in_list(lst, default=1):
    lst = list(lst)
    for x in range(0, len(lst)):
        io.echo(str(x + 1) + ')', lst[x])

    while True:
        try:
            choice = int(io.prompt('default is ' + str(default),
                                   default=default))
            if not (0 < choice <= len(lst)):
                raise ValueError  # Also thrown by non int numbers
            else:
                break
        except ValueError:
            io.echo('Sorry, that is not a valid choice. '
                    'Please choose a number between 1 and ' +
                    str(len(lst)) + '.')
    return choice - 1
예제 #7
0
def _generate_and_upload_keypair(keys):
    io.echo()
    io.echo(prompts['keypair.nameprompt'])
    unique = utils.get_unique_name('aws-eb', keys)
    keyname = io.prompt('Default is ' + unique, default=unique)
    file_name = fileoperations.get_ssh_folder() + keyname

    try:
        exitcode = subprocess.call(
            ['ssh-keygen', '-f', file_name, '-C', keyname])
    except OSError:
        raise CommandError(strings['ssh.notpresent'])

    if exitcode == 0 or exitcode == 1:
        commonops.upload_keypair_if_needed(keyname)
        return keyname
    else:
        LOG.debug('ssh-keygen returned exitcode: ' + str(exitcode) +
                  ' with filename: ' + file_name)
        raise CommandError('An error occurred while running ssh-keygen.')
예제 #8
0
    def test_prompt(self, get_input_mock):
        get_input_mock.return_value = '10'

        io.prompt('some text', default='22')

        get_input_mock.assert_called_once_with('(some text)', '22')