コード例 #1
0
    def json_to_environment_object(
            cls,
            environment_json,
            want_solution_stack=False
    ):
        platform_name = cls.__get_platform_name(environment_json, want_solution_stack)

        tier = environment_json['Tier']
        tier = Tier(tier['Name'], tier['Type'], tier['Version'])

        environment = Environment(
            version_label=environment_json.get('VersionLabel'),
            status=environment_json.get('Status'),
            app_name=environment_json.get('ApplicationName'),
            health=environment_json.get('Health'),
            id=environment_json.get('EnvironmentId'),
            date_updated=environment_json.get('DateUpdated'),
            platform=platform_name,
            description=environment_json.get('Description'),
            name=environment_json.get('EnvironmentName'),
            date_created=environment_json.get('DateCreated'),
            tier=tier,
            cname=environment_json.get('CNAME', 'UNKNOWN'),
            option_settings=environment_json.get('OptionSettings'),
            is_abortable=environment_json.get('AbortableOperationInProgress', False),
            environment_links=environment_json.get('EnvironmentLinks'),
            environment_arn=environment_json.get('EnvironmentArn')
        )

        return environment
コード例 #2
0
def _api_to_environment(api_dict, want_solution_stack = False):
    # Convert solution_stack and tier to objects
    try:
        if want_solution_stack:
            solution_stack_name = api_dict['SolutionStackName']
            platform = SolutionStack(solution_stack_name)
        else:
            platform_arn = api_dict['PlatformArn']
            platform = PlatformVersion(platform_arn)
    except KeyError:
        platform = SolutionStack(api_dict['SolutionStackName'])

    tier = api_dict['Tier']
    tier = Tier(tier['Name'], tier['Type'], tier['Version'])

    env = Environment(
        version_label=api_dict.get('VersionLabel'),
        status=api_dict.get('Status'),
        app_name=api_dict.get('ApplicationName'),
        health=api_dict.get('Health'),
        id=api_dict.get('EnvironmentId'),
        date_updated=api_dict.get('DateUpdated'),
        platform=platform,
        description=api_dict.get('Description'),
        name=api_dict.get('EnvironmentName'),
        date_created=api_dict.get('DateCreated'),
        tier=tier,
        cname=api_dict.get('CNAME', 'UNKNOWN'),
        option_settings=api_dict.get('OptionSettings'),
        is_abortable=api_dict.get('AbortableOperationInProgress', False),
        environment_links=api_dict.get('EnvironmentLinks'),
        environment_arn=api_dict.get('EnvironmentArn')
    )
    return env
コード例 #3
0
    def test_status__verbose_mode__elbv2(
            self, get_target_group_healths_mock,
            get_target_groups_for_load_balancer_mock,
            get_environment_resources_mock, get_default_repository_mock,
            get_default_branch_mock, echo_mock, log_alert_mock,
            find_solution_stack_from_string_mock, get_environment_mock):
        environment_object = Environment.json_to_environment_object(
            mock_responses.DESCRIBE_ENVIRONMENTS_RESPONSE['Environments'][0])
        environment_object.platform = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_environment_mock.return_value = environment_object
        find_solution_stack_from_string_mock.return_value = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_default_branch_mock.return_value = 'branch'
        get_default_repository_mock.return_value = 'repository'
        get_environment_resources_mock.return_value = mock_responses.DESCRIBE_ENVIRONMENT_RESOURCES_RESPONSE__ELBV2_ENVIRONMENT
        get_target_groups_for_load_balancer_mock.return_value = mock_responses.DESCRIBE_TARGET_GROUPS_RESPONSE[
            'TargetGroups']
        get_target_group_healths_mock.return_value = {
            "arn:aws:elasticloadbalancing:us-west-2:123123123123:targetgroup/awseb-AWSEB-179V6JWWL9HI5/e57decc4139bfdd2":
            mock_responses.DESCRIBE_TARGET_HEALTH_RESPONSE
        }

        statusops.status('my-application', 'environment-1', True)

        log_alert_mock.assert_not_called()
        echo_mock.assert_has_calls([
            mock.call('Environment details for:', 'environment-1'),
            mock.call('  Application name:', 'my-application'),
            mock.call('  Region:', 'us-west-2'),
            mock.call('  Deployed Version:', 'Sample Application'),
            mock.call('  Environment ID:', 'e-sfsdfsfasdads'),
            mock.call(
                '  Platform:',
                PlatformVersion(
                    'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
                )),
            mock.call('  Tier:', Tier.from_raw_string('webserver')),
            mock.call('  CNAME:',
                      'environment-1.us-west-2.elasticbeanstalk.com'),
            mock.call(
                '  Updated:',
                datetime.datetime(2018,
                                  3,
                                  27,
                                  23,
                                  47,
                                  41,
                                  830000,
                                  tzinfo=tz.tzutc())),
            mock.call('  Status:', 'Ready'),
            mock.call('  Health:', 'Green'),
            mock.call('  Running instances:', 1),
            mock.call('          ', 'i-01641763db1c0cb47: healthy'),
            mock.call('Current CodeCommit settings:'),
            mock.call('  Repository: repository'),
            mock.call('  Branch: branch')
        ])
コード例 #4
0
    def test_status__verbose_mode__elb(
            self, get_health_of_instances_mock, get_environment_resources_mock,
            get_default_repository_mock, get_default_branch_mock, echo_mock,
            log_alert_mock, find_solution_stack_from_string_mock,
            get_environment_mock):
        environment_object = Environment.json_to_environment_object(
            mock_responses.DESCRIBE_ENVIRONMENTS_RESPONSE['Environments'][0])
        environment_object.platform = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_environment_mock.return_value = environment_object
        find_solution_stack_from_string_mock.return_value = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_default_branch_mock.return_value = 'branch'
        get_default_repository_mock.return_value = 'repository'
        get_environment_resources_mock.return_value = mock_responses.DESCRIBE_ENVIRONMENT_RESOURCES_RESPONSE
        get_health_of_instances_mock.return_value = mock_responses.DESCRIBE_INSTANCE_HEALTH[
            'InstanceStates']

        statusops.status('my-application', 'environment-1', True)

        log_alert_mock.assert_not_called()
        echo_mock.assert_has_calls([
            mock.call('Environment details for:', 'environment-1'),
            mock.call('  Application name:', 'my-application'),
            mock.call('  Region:', 'us-west-2'),
            mock.call('  Deployed Version:', 'Sample Application'),
            mock.call('  Environment ID:', 'e-sfsdfsfasdads'),
            mock.call(
                '  Platform:',
                PlatformVersion(
                    'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
                )),
            mock.call('  Tier:', Tier.from_raw_string('webserver')),
            mock.call('  CNAME:',
                      'environment-1.us-west-2.elasticbeanstalk.com'),
            mock.call(
                '  Updated:',
                datetime.datetime(2018,
                                  3,
                                  27,
                                  23,
                                  47,
                                  41,
                                  830000,
                                  tzinfo=tz.tzutc())),
            mock.call('  Status:', 'Ready'),
            mock.call('  Health:', 'Green'),
            mock.call('  Running instances:', 2),
            mock.call('     ', 'i-23452345346456566:', 'InService'),
            mock.call('     ', 'i-21312312312312312:', 'OutOfService'),
            mock.call('Current CodeCommit settings:'),
            mock.call('  Repository: repository'),
            mock.call('  Branch: branch')
        ])
コード例 #5
0
    def test_status__non_verbose_mode__codecommit_not_setup__using_non_latest_platform(
            self, get_default_repository_mock, get_default_branch_mock,
            echo_mock, log_alert_mock, find_solution_stack_from_string_mock,
            get_environment_mock):
        environment_object = Environment.json_to_environment_object(
            mock_responses.DESCRIBE_ENVIRONMENTS_RESPONSE['Environments'][0])
        environment_object.platform = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.5'
        )
        get_environment_mock.return_value = environment_object
        get_environment_mock.platform = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.5'
        )
        find_solution_stack_from_string_mock.return_value = PlatformVersion(
            'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.6'
        )
        get_default_branch_mock.return_value = None
        get_default_repository_mock.return_value = None

        statusops.status('my-application', 'environment-1', False)

        log_alert_mock.assert_called_once_with(
            'There is a newer version of the platform used by your environment. '
            'You can upgrade your environment to the most recent platform version by typing "eb upgrade".'
        )
        echo_mock.assert_has_calls([
            mock.call('Environment details for:', 'environment-1'),
            mock.call('  Application name:', 'my-application'),
            mock.call('  Region:', 'us-west-2'),
            mock.call('  Deployed Version:', 'Sample Application'),
            mock.call('  Environment ID:', 'e-sfsdfsfasdads'),
            mock.call(
                '  Platform:',
                PlatformVersion(
                    'arn:aws:elasticbeanstalk:us-west-2::platform/PHP 7.1 running on 64bit Amazon Linux/2.6.5'
                )),
            mock.call('  Tier:', Tier.from_raw_string('webserver')),
            mock.call('  CNAME:',
                      'environment-1.us-west-2.elasticbeanstalk.com'),
            mock.call(
                '  Updated:',
                datetime.datetime(2018,
                                  3,
                                  27,
                                  23,
                                  47,
                                  41,
                                  830000,
                                  tzinfo=tz.tzutc())),
            mock.call('  Status:', 'Ready'),
            mock.call('  Health:', 'Green')
        ])
コード例 #6
0
    def complete_command(self, commands):
        app_name = fileoperations.get_application_name()

        self.complete_region(commands)

        # We only care about top command, because there are no positional
        ## args for this command
        cmd = commands[-1]
        if cmd in ['-t', '--tier']:
            io.echo(*Tier.get_all_tiers())
        if cmd in ['-s', '--solution']:
            io.echo(*elasticbeanstalk.get_available_solution_stacks())
        if cmd in ['-vl', '--versionlabel']:
            io.echo(*elasticbeanstalk.get_app_version_labels(app_name))
コード例 #7
0
def get_environment_tier(tier):
    """
    Set the 'tier' for the environment from the raw value received for the `--tier`
    argument.

    If a configuration template corresponding to `template_name` is also resolved,
    and the tier corresponding to the configuration template is a 'worker' tier,
    any previously set value for 'tier' is replaced with the value from the saved
    config.
    :return: A Tier object representing the environment's tier type
    """
    if tier:
        tier = Tier.from_raw_string(tier)

    return tier
コード例 #8
0
    def do_command(self):
        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
        platform = 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
        enable_spot = self.app.pargs.enable_spot
        spot_max_price = self.app.pargs.spot_max_price
        instance_types = self.app.pargs.instance_types
        on_demand_base_capacity = self.app.pargs.on_demand_base_capacity
        on_demand_above_base_capacity = self.app.pargs.on_demand_above_base_capacity
        max_instances = self.app.pargs.max_instances
        min_instances = self.app.pargs.min_instances

        interactive = False if env_name else True

        provided_env_name = env_name

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

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

        if (max_instances or min_instances) and scale:
            raise InvalidOptionsError(strings['create.scaleandminmax'])

        if (max_instances or min_instances) and single:
            raise InvalidOptionsError(strings['create.singleandminmax'])

        if single and elb_type:
            raise InvalidOptionsError(strings['create.single_and_elb_type'])

        if cname and tier and Tier.looks_like_worker_tier(tier):
            raise InvalidOptionsError(strings['worker.cname'])

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

        if tier and Tier.looks_like_worker_tier(tier):
            if self.app.pargs.vpc_elbpublic or self.app.pargs.vpc_elbsubnets or self.app.pargs.vpc_publicip:
                raise InvalidOptionsError(
                    strings['create.worker_and_incompatible_vpc_arguments'])

        if (not tier or Tier.looks_like_webserver_tier(tier)) and single:
            if self.app.pargs.vpc_elbpublic or self.app.pargs.vpc_elbsubnets:
                raise InvalidOptionsError(
                    strings['create.single_and_elbpublic_or_elb_subnet'])

        if (spot_max_price or on_demand_base_capacity
                or on_demand_above_base_capacity) and not enable_spot:
            raise InvalidOptionsError(strings['create.missing_enable_spot'])

        if instance_types is "":
            raise InvalidOptionsError(
                strings['spot.instance_types_validation'])

        if itype and instance_types:
            raise InvalidOptionsError(strings['create.itype_and_instances'])

        platform = _determine_platform(platform, iprofile)

        app_name = self.get_app_name()
        tags = tagops.get_and_validate_tags(tags)
        envvars = get_and_validate_envars(envvars)
        process_app_version = fileoperations.env_yaml_exists() or process
        template_name = get_template_name(app_name, cfg)
        tier = get_environment_tier(tier)
        env_name = provided_env_name or get_environment_name(app_name, group)
        cname = cname or get_environment_cname(env_name, provided_env_name,
                                               tier)
        key_name = key_name or commonops.get_default_keyname()
        elb_type = elb_type or get_elb_type_from_customer(
            interactive, single, tier)
        enable_spot = enable_spot or spotops.get_spot_request_from_customer(
            interactive)
        instance_types = instance_types or spotops.get_spot_instance_types_from_customer(
            interactive, enable_spot)
        database = self.form_database_object()
        vpc = self.form_vpc_object(tier, single)

        if not timeout and database:
            timeout = 15

        env_request = CreateEnvironmentRequest(
            app_name=app_name,
            env_name=env_name,
            group_name=group,
            cname=cname,
            template_name=template_name,
            platform=platform,
            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,
            enable_spot=enable_spot,
            instance_types=instance_types,
            spot_max_price=spot_max_price,
            on_demand_base_capacity=on_demand_base_capacity,
            on_demand_above_base_capacity=on_demand_above_base_capacity,
            min_instances=min_instances,
            max_instances=max_instances)

        env_request.option_settings += envvars

        createops.make_new_env(env_request,
                               branch_default=branch_default,
                               process_app_version=process_app_version,
                               nohang=nohang,
                               interactive=interactive,
                               timeout=timeout,
                               source=source)
コード例 #9
0
 def test_from_raw_string__invalid_input(self):
     with self.assertRaises(NotFoundError):
         Tier.from_raw_string('invalid/input')
コード例 #10
0
 def test_from_raw_string__worker(self):
     for customer_input in ['Worker', 'Worker/SQS/HTTP']:
         tier = Tier.from_raw_string(customer_input)
         self.assertEqual('Worker', tier.name)
         self.assertEqual('SQS/HTTP', tier.type)
         self.assertEqual('', tier.version)
コード例 #11
0
 def test_from_raw_string__webserver(self):
     for customer_input in ['WebServer', 'WebServer/Standard']:
         tier = Tier.from_raw_string(customer_input)
         self.assertEqual('WebServer', tier.name)
         self.assertEqual('Standard', tier.type)
         self.assertEqual('1.0', tier.version)
コード例 #12
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 or solution_stack_ops.get_default_solution_stack(
        )
        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

        provided_env_name = env_name

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

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

        if single and elb_type:
            raise InvalidOptionsError(strings['create.single_and_elb_type'])

        if cname and tier and Tier.looks_like_worker_tier(tier):
            raise InvalidOptionsError(strings['worker.cname'])

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

        if tier and Tier.looks_like_worker_tier(tier):
            if self.app.pargs.vpc_elbpublic or self.app.pargs.vpc_elbsubnets or self.app.pargs.vpc_publicip:
                raise InvalidOptionsError(
                    strings['create.worker_and_incompatible_vpc_arguments'])

        if (not tier or Tier.looks_like_webserver_tier(tier)) and single:
            if self.app.pargs.vpc_elbpublic or self.app.pargs.vpc_elbsubnets:
                raise InvalidOptionsError(
                    strings['create.single_and_elbpublic_or_elb_subnet'])

        app_name = self.get_app_name()
        tags = createops.get_and_validate_tags(tags)
        envvars = get_and_validate_envars(envvars)
        process_app_version = fileoperations.env_yaml_exists() or process
        platform = get_platform(solution_string, iprofile)
        template_name = get_template_name(app_name, cfg)
        tier = get_environment_tier(tier)
        env_name = provided_env_name or get_environment_name(app_name, group)
        cname = cname or get_environment_cname(env_name, provided_env_name,
                                               tier)
        key_name = key_name or commonops.get_default_keyname()
        elb_type = elb_type or get_elb_type_from_customer(
            interactive, single, region, tier)
        database = self.form_database_object()
        vpc = self.form_vpc_object(tier, single)

        # avoid prematurely timing out in the CLI when an environment is launched with a RDS DB
        if not timeout and database:
            timeout = 15

        env_request = CreateEnvironmentRequest(app_name=app_name,
                                               env_name=env_name,
                                               group_name=group,
                                               cname=cname,
                                               template_name=template_name,
                                               platform=platform,
                                               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)

        env_request.option_settings += envvars

        createops.make_new_env(env_request,
                               branch_default=branch_default,
                               process_app_version=process_app_version,
                               nohang=nohang,
                               interactive=interactive,
                               timeout=timeout,
                               source=source)