Beispiel #1
0
    def get_solution_stack(self):
        # Get solution stack from command line arguments
        solution_string = self.app.pargs.platform

        # Get solution stack from config file, if exists
        if not solution_string:
            try:
                solution_string = commonops.get_default_solution_stack()
            except NotInitializedError:
                solution_string = None

        # Validate that the platform exists
        if solution_string:
            if is_platform_arn(solution_string):
                elasticbeanstalk.describe_platform_version(solution_string)
            else:
                commonops.get_solution_stack(solution_string)

        return solution_string
Beispiel #2
0
    def do_command(self):
        # save command line args
        env_name = self.app.pargs.environment_name
        modules = self.app.pargs.modules
        if modules and len(modules) > 0:
            self.compose_multiple_apps()
            return
        group = self.app.pargs.env_group_suffix
        cname = self.app.pargs.cname
        tier = self.app.pargs.tier
        itype = self.app.pargs.instance_type
        solution_string = self.app.pargs.platform
        single = self.app.pargs.single
        iprofile = self.app.pargs.instance_profile
        service_role = self.app.pargs.service_role
        label = self.app.pargs.version
        branch_default = self.app.pargs.branch_default
        key_name = self.app.pargs.keyname
        sample = self.app.pargs.sample
        nohang = self.app.pargs.nohang
        tags = self.app.pargs.tags
        envvars = self.app.pargs.envvars
        scale = self.app.pargs.scale
        timeout = self.app.pargs.timeout
        cfg = self.app.pargs.cfg
        elb_type = self.app.pargs.elb_type
        source = self.app.pargs.source
        process = self.app.pargs.process
        region = self.app.pargs.region
        interactive = False if env_name else True
        platform_arn = None
        solution = None

        provided_env_name = env_name is not None

        if sample and label:
            raise InvalidOptionsError(strings['create.sampleandlabel'])

        if single and scale:
            raise InvalidOptionsError(strings['create.singleandsize'])

        app_name = self.get_app_name()

        # get tags
        tags = createops.get_and_validate_tags(tags)

        #load solution stack
        if not solution_string:
            solution_string = commonops.get_default_solution_stack()

        # Test out sstack and tier before we ask any questions (Fast Fail)
        if solution_string:
            if is_platform_arn(solution_string):
                platform_arn = solution_string
            else:
                try:
                    solution = commonops.get_solution_stack(solution_string)
                except NotFoundError:
                    raise NotFoundError('Platform ' + solution_string +
                                        ' does not appear to be valid')

        if tier:
            if 'worker' in tier.lower() and cname:
                raise InvalidOptionsError(strings['worker.cname'])
            try:
                tier = Tier.parse_tier(tier)
            except NotFoundError:
                raise NotFoundError('Provided tier ' + tier + ' does not '
                                    'appear to be valid')

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

        # If we still dont have what we need, ask for it
        if not solution_string:
            solution = commonops.prompt_for_solution_stack()

        if solution is not None:
            if is_platform_arn(solution.version):
                platform_arn = solution.version
                solution = None
            elif solution.platform == 'Multi-container Docker' and iprofile is None:
                io.log_warning(prompts['ecs.permissions'])

        if not env_name:
            # default is app-name plus '-dev'
            default_name = app_name + '-dev'
            current_environments = commonops.get_all_env_names()
            unique_name = utils.get_unique_name(default_name,
                                                current_environments)

            if fileoperations.env_yaml_exists():
                env_name = fileoperations.get_env_name_from_env_yaml()
                if env_name is not None:
                    if env_name.endswith('+') and group is None:
                        io.echo(strings['create.missinggroupsuffix'])
                        return
                    else:
                        env_name = env_name[:-1] + '-' + group
                else:
                    env_name = io.prompt_for_environment_name(unique_name)
            else:
                env_name = io.prompt_for_environment_name(unique_name)

        # Get template if applicable
        template_name = get_template_name(app_name, cfg)
        if template_name:
            template_contents = elasticbeanstalk.describe_template(
                app_name, template_name)

            if template_contents['Tier']['Name'] == 'Worker':
                tier = Tier.parse_tier('worker')

        if not tier or tier.name.lower() == 'webserver':
            if not cname and not provided_env_name:
                cname = get_cname(env_name)
            elif not cname:
                cname = None

        if not key_name:
            key_name = commonops.get_default_keyname()

        if not elb_type and interactive and not single:
            elb_type = get_elb_type(region)

        database = self.form_database_object()
        vpc = self.form_vpc_object()
        envvars = get_and_validate_envars(envvars)

        env_request = CreateEnvironmentRequest(app_name=app_name,
                                               env_name=env_name,
                                               group_name=group,
                                               cname=cname,
                                               template_name=template_name,
                                               platform=solution,
                                               tier=tier,
                                               instance_type=itype,
                                               version_label=label,
                                               instance_profile=iprofile,
                                               service_role=service_role,
                                               single_instance=single,
                                               key_name=key_name,
                                               sample_application=sample,
                                               tags=tags,
                                               scale=scale,
                                               database=database,
                                               vpc=vpc,
                                               elb_type=elb_type,
                                               platform_arn=platform_arn)

        env_request.option_settings += envvars

        process_app_version = fileoperations.env_yaml_exists() or process
        createops.make_new_env(env_request,
                               branch_default=branch_default,
                               process_app_version=process_app_version,
                               nohang=nohang,
                               interactive=interactive,
                               timeout=timeout,
                               source=source)