예제 #1
0
파일: listops.py 프로젝트: mschmutz1/jokic
def list_env_names_for_app(app_name, verbose):
    current_env = commonops.get_current_branch_environment()
    env_names = elasticbeanstalk.get_environment_names(app_name)
    env_names.sort()

    if verbose:
        io.echo('Application:', app_name)
        io.echo('    Environments:', len(env_names))
        for e in env_names:
            instances = commonops.get_instance_ids(e)
            if e == current_env:
                e = '* ' + e

            io.echo('       ', e, ':', instances)

    else:
        for i in range(0, len(env_names)):
            if env_names[i] == current_env:
                env_names[i] = '* ' + env_names[i]

        if len(env_names) <= 10:
            for e in env_names:
                io.echo(e)
        else:
            utils.print_list_in_columns(env_names)
예제 #2
0
def prepare_for_ssh(env_name,
                    instance,
                    keep_open,
                    force,
                    setup,
                    number,
                    keyname=None,
                    no_keypair_error_message=None,
                    custom_ssh=None,
                    command=None,
                    timeout=None):
    if setup:
        setup_ssh(env_name, keyname, timeout=timeout)
        return

    if instance and number:
        raise InvalidOptionsError(strings['ssh.instanceandnumber'])

    if not instance:
        instances = commonops.get_instance_ids(env_name)
        if number is not None:
            if number > len(instances) or number < 1:
                raise InvalidOptionsError('Invalid index number (' +
                                          str(number) +
                                          ') for environment with ' +
                                          str(len(instances)) + ' instances')
            else:
                instance = instances[number - 1]

        elif len(instances) == 1:
            instance = instances[0]
        else:
            io.echo()
            io.echo('Select an instance to ssh into')
            instance = utils.prompt_for_item_in_list(instances)

    try:
        ssh_into_instance(instance,
                          keep_open=keep_open,
                          force_open=force,
                          custom_ssh=custom_ssh,
                          command=command)
    except NoKeypairError:
        if not no_keypair_error_message:
            no_keypair_error_message = prompts['ssh.nokey']
        io.log_error(no_keypair_error_message)
예제 #3
0
파일: eb_ssm.py 프로젝트: zagaran/eb-ssm
    def ssh(self):
        aws.set_region(self.region)
        aws.set_profile(self.profile)

        if self.environment_name is None:
            environment_names = get_all_environment_names()
            if environment_names:
                error = "Please chose one of the following environment names:\n\n"
                error += "\n".join(sorted(environment_names)) + "\n"
                io.log_error(error)
            else:
                io.log_error(
                    "The current Elastic Beanstalk application has no environments"
                )
            sys.exit()

        instances = get_instance_ids(self.environment_name)
        if len(instances) == 1:
            instance = instances[0]
        else:
            io.echo()
            io.echo('Select an instance to ssh into')
            instance = utils.prompt_for_item_in_list(instances)

        params = [
            "aws",
            "ssm",
            "start-session",
            "--document-name",
            "AWS-StartInteractiveCommand",
            "--parameters",
            "command='bash -l'",
            "--profile",
            self.profile,
            "--region",
            self.region,
            "--target",
            instance,
        ]

        os.system(" ".join(params))