def get_environment_settings(app_name, env_name): LOG.debug('Inside get_environment_settings api wrapper') result = _make_api_call('describe_configuration_settings', ApplicationName=app_name, EnvironmentName=env_name) return Environment.json_to_environment_object(result['ConfigurationSettings'][0])
def create_environment(environment): """ Creates an Elastic Beanstalk environment """ LOG.debug('Inside create_environment api wrapper') kwargs = environment.convert_to_kwargs() if environment.database: # need to know region for database string region = aws.get_region_name() # Database is a dictionary kwargs['TemplateSpecification'] = { 'TemplateSnippets': [{ 'SnippetName': 'RdsExtensionEB', 'Order': 10000, 'SourceUrl': 'https://s3.amazonaws.com/' 'elasticbeanstalk-env-resources-' + region + '/eb_snippets/rds/rds.json' }] } result = _make_api_call('create_environment', **kwargs) # convert to object env = Environment.json_to_environment_object(result) request_id = result['ResponseMetadata']['RequestId'] return env, request_id
def create_environment(environment): """ Creates an Elastic Beanstalk environment """ LOG.debug('Inside create_environment api wrapper') kwargs = environment.convert_to_kwargs() if environment.database: # need to know region for database string region = aws.get_region_name() # Database is a dictionary kwargs['TemplateSpecification'] = { 'TemplateSnippets': [ {'SnippetName': 'RdsExtensionEB', 'Order': 10000, 'SourceUrl': 'https://s3.amazonaws.com/' 'elasticbeanstalk-env-resources-' + region + '/eb_snippets/rds/rds.json'} ] } result = _make_api_call('create_environment', **kwargs) # convert to object env = Environment.json_to_environment_object(result) request_id = result['ResponseMetadata']['RequestId'] return env, request_id
def get_environment(app_name=None, env_name=None, env_id=None, include_deleted=False, deleted_back_to=None, want_solution_stack=False): LOG.debug('Inside get_environment api wrapper') kwargs = {} if app_name is not None: kwargs['ApplicationName'] = app_name if env_name is not None: kwargs['EnvironmentNames'] = [env_name] if env_id is not None: kwargs['EnvironmentIds'] = [env_id] if include_deleted and deleted_back_to is not None: kwargs['IncludedDeletedBackTo'] = deleted_back_to result = _make_api_call('describe_environments', IncludeDeleted=include_deleted, **kwargs) envs = result['Environments'] if len(envs) < 1: env_str = env_id if env_name is None else env_name raise NotFoundError('Environment "' + env_str + '" not Found.') else: return Environment.json_to_environment_object(envs[0], want_solution_stack)
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') ])
def test_clone_env__environment_name_is_unavailable( self, prompt_for_environment_name_mock, get_unique_name_mock, get_environment_names_mock, echo_mock, prompt_for_cname_mock, clone_environment_mock ): clone_request_mock = mock.MagicMock() clone_request_mock.app_name = 'my-application' clone_request_mock.env_name = 'unavailable-environment-name' prompt_for_cname_mock.return_value = 'my-environment-cname' get_environment_names_mock.return_value = ['environment-1', 'environment-2'] get_unique_name_mock.return_value = 'environment-3' prompt_for_environment_name_mock.return_value = 'my-environment' environment_mock = Environment.json_to_environment_object(mock_responses.CREATE_ENVIRONMENT_RESPONSE) clone_environment_mock.side_effect = [ cloneops.InvalidParameterValueError('Environment unavailable-environment-name already exists.'), (environment_mock, 'request-id') ] self.assertEqual( (environment_mock, 'request-id'), cloneops.clone_env(clone_request_mock) ) echo_mock.assert_called_once_with('An environment with that name already exists.') get_environment_names_mock.assert_called_once_with('my-application') get_unique_name_mock.assert_called_once_with( 'unavailable-environment-name', ['environment-1', 'environment-2'] ) self.assertEqual('my-environment', clone_request_mock.env_name)
def get_environment_settings(app_name, env_name): LOG.debug('Inside get_environment_settings api wrapper') result = _make_api_call('describe_configuration_settings', ApplicationName=app_name, EnvironmentName=env_name) return Environment.json_to_environment_object( result['ConfigurationSettings'][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') ])
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') ])
def clone_environment(clone): LOG.debug('Inside clone_environment api wrapper') kwargs = clone.convert_to_kwargs() kwargs['TemplateSpecification'] = \ {'TemplateSource': {'EnvironmentName': clone.original_name}} result = _make_api_call('create_environment', **kwargs) environment = Environment.json_to_environment_object(result) request_id = result['ResponseMetadata']['RequestId'] return environment, request_id
def test_clone_env( self, clone_environment_mock ): clone_request_mock = mock.MagicMock() environment_mock = Environment.json_to_environment_object(mock_responses.CREATE_ENVIRONMENT_RESPONSE) clone_environment_mock.return_value = (environment_mock, 'request-id') self.assertEqual( (environment_mock, 'request-id'), cloneops.clone_env(clone_request_mock) )
def clone_environment(clone): LOG.debug('Inside clone_environment api wrapper') kwargs = clone.convert_to_kwargs() kwargs['TemplateSpecification'] = \ {'TemplateSource': {'EnvironmentName': clone.original_name}} result = _make_api_call('create_environment', **kwargs) # convert to object environment = Environment.json_to_environment_object(result) request_id = result['ResponseMetadata']['RequestId'] return environment, request_id
def test_clone_env__cname_is_unavailable( self, echo_mock, prompt_for_cname_mock, clone_environment_mock ): clone_request_mock = mock.MagicMock() prompt_for_cname_mock.return_value = 'my-environment-cname' environment_mock = Environment.json_to_environment_object(mock_responses.CREATE_ENVIRONMENT_RESPONSE) clone_environment_mock.side_effect = [ cloneops.InvalidParameterValueError('DNS name (in-use-cname.com) is not available.'), (environment_mock, 'request-id') ] self.assertEqual( (environment_mock, 'request-id'), cloneops.clone_env(clone_request_mock) ) echo_mock.assert_called_once_with('The CNAME you provided is already in use.\n')