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)
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)
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))