Example #1
0
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)
Example #2
0
 def complete_command(self, commands):
     if not self.complete_region(commands):
         # Environment names are the second positional argument in this
         ## controller, so we only complete if its the second
         if len(commands) == 2 and commands[-1].startswith('-'):
             app_name = fileoperations.get_application_name()
             io.echo(*elasticbeanstalk.get_environment_names(app_name))
def ask_for_customer_confirmation_to_delete_all_application_resources(
        app_name):
    application = elasticbeanstalk.describe_application(app_name)

    application['Versions'] = application.get('Versions', [])

    environments = elasticbeanstalk.get_environment_names(app_name)
    confirm_message = prompts['delete.confirm'].format(
        app_name=app_name,
        env_num=len(environments),
        config_num=len(application['ConfigurationTemplates']),
        version_num=len(application['Versions']))
    io.echo(confirm_message)
    io.validate_action(prompts['delete.validate'], app_name)
def clone_env(clone_request):
    while True:
        try:
            return elasticbeanstalk.clone_environment(clone_request)
        except InvalidParameterValueError as e:
            LOG.debug('cloning env returned error: ' + e.message)
            if re.match(responses['env.cnamenotavailable'], e.message):
                io.echo(prompts['cname.unavailable'])
                clone_request.cname = io.prompt_for_cname()
            elif re.match(responses['env.nameexists'], e.message):
                io.echo(strings['env.exists'])
                current_environments = elasticbeanstalk.get_environment_names(
                    clone_request.app_name)
                unique_name = utils.get_unique_name(clone_request.env_name,
                                                    current_environments)
                clone_request.env_name = io.prompt_for_environment_name(
                    default_name=unique_name)
            else:
                raise
Example #5
0
    def do_command(self):
        app_name = self.get_app_name()
        source_env = self.get_env_name()
        destination_env = self.app.pargs.destination_name

        if not destination_env:
            envs = elasticbeanstalk.get_environment_names(app_name)
            if len(envs) < 2:
                raise NotSupportedError(strings['swap.unsupported'])

            envs = [e for e in envs if e != source_env]
            if len(envs) == 1:
                destination_env = envs[0]
            else:
                io.echo()
                io.echo(prompts['swap.envprompt'])
                destination_env = utils.prompt_for_item_in_list(envs)

        swapops.cname_swap(source_env, destination_env)
Example #6
0
    def do_command(self):
        app_name = self.get_app_name()
        source_env = self.get_env_name()
        destination_env = self.app.pargs.destination_name

        if not destination_env:
            # Ask interactively for an env to swap with
            envs = elasticbeanstalk.get_environment_names(app_name)
            if len(envs) < 2:
                raise NotSupportedError(strings['swap.unsupported'])

            # Filter out current env
            envs = [e for e in envs if e != source_env]
            if len(envs) == 1:
                # Don't ask for env, just swap with only other environment
                destination_env = envs[0]
            else:
                # Ask for env to swap with
                io.echo()
                io.echo(prompts['swap.envprompt'])
                destination_env = utils.prompt_for_item_in_list(envs)

        swapops.cname_swap(source_env, destination_env)
Example #7
0
    def do_command(self):
        app_name = self.get_app_name()
        env_name = self.get_env_name()
        clone_name = self.app.pargs.clone_name
        cname = self.app.pargs.cname
        scale = self.app.pargs.scale
        nohang = self.app.pargs.nohang
        tags = self.app.pargs.tags
        envvars = self.app.pargs.envvars
        exact = self.app.pargs.exact
        timeout = self.app.pargs.timeout
        provided_clone_name = clone_name is not None
        platform = None

        env = elasticbeanstalk.get_environment(app_name=app_name,
                                               env_name=env_name)
        tier = env.tier
        if 'worker' in tier.name.lower() and cname:
            raise InvalidOptionsError(strings['worker.cname'])

        if cname:
            if not elasticbeanstalk.is_cname_available(cname):
                raise AlreadyExistsError(strings['cname.unavailable'].replace(
                    '{cname}', cname))

        tags = tagops.get_and_validate_tags(tags)
        envvars = get_and_validate_envars(envvars)

        if not clone_name:
            if len(env_name) < 16:
                unique_name = env_name + '-clone'
            else:
                unique_name = 'my-cloned-env'

            env_list = elasticbeanstalk.get_environment_names(app_name)

            unique_name = utils.get_unique_name(unique_name, env_list)

            clone_name = io.prompt_for_environment_name(
                default_name=unique_name,
                prompt_text='Enter name for Environment Clone')

        if tier.name.lower() == 'webserver':
            if not cname and not provided_clone_name:
                cname = get_cname_from_customer(clone_name)
            elif not cname:
                cname = None

        if not exact:
            if not provided_clone_name:
                latest = solution_stack_ops.find_solution_stack_from_string(
                    env.platform.name, find_newer=True)

                if latest != env.platform:
                    io.echo()
                    io.echo(prompts['clone.latest'])
                    lst = [
                        'Latest  (' + str(latest) + ')',
                        'Same    (' + str(env.platform) + ')'
                    ]
                    result = utils.prompt_for_item_in_list(lst)
                    if result == lst[0]:
                        platform = latest
                else:
                    platform = latest
            else:
                platform = solution_stack_ops.find_solution_stack_from_string(
                    env.platform.name, find_newer=True)
                if platform != env.platform:
                    io.log_warning(prompts['clone.latestwarn'])

        clone_request = CloneEnvironmentRequest(
            app_name=app_name,
            env_name=clone_name,
            original_name=env_name,
            cname=cname,
            platform=platform,
            scale=scale,
            tags=tags,
        )

        clone_request.option_settings += envvars

        cloneops.make_cloned_env(clone_request, nohang=nohang, timeout=timeout)
Example #8
0
 def complete_command(self, commands):
     if not self.complete_region(commands):
         if len(commands) == 1:  # They only have the main command so far
             # lets complete for positional args
             app_name = fileoperations.get_application_name()
             io.echo(*elasticbeanstalk.get_environment_names(app_name))
Example #9
0
 def complete_command(self, commands):
     self.complete_region(commands)
     if commands[-1] in ['-e', '--environment']:
         app_name = fileoperations.get_application_name()
         io.echo(*elasticbeanstalk.get_environment_names(app_name))
 def complete_command(self, commands):
     if not self.complete_region(commands):
         if len(commands) == 1:  # They only have the main command so far
             # lets complete for positional args
             app_name = fileoperations.get_application_name()
             io.echo(*elasticbeanstalk.get_environment_names(app_name))