Exemplo n.º 1
0
def _add_rds_extension(parameter_pool, option_settings, option_to_remove):
    region = parameter_pool.get_value(ParameterName.Region)
    
    #Generate snippet    
    env_name = parameter_pool.get_value(ParameterName.EnvironmentName)
    if has_rds_instance(parameter_pool, env_name):
        spec = None
    else:
        spec = TemplateSpecification()
        snippet = TemplateSnippet()
        snippet.snippet_name = RdsDefault.SnippetName
        snippet.source_url = RdsDefault.get_snippet_url(region)
        snippet.order = RdsDefault.SnippetAddOrder
        spec.template_snippets = [snippet]
    
    #Add/update option settings
    #TODO: change option_settings to o(1) structure while retain order for output
    for pname in RdsDefault.OptionMinSet:
        if parameter_pool.has(pname) and parameter_pool.get_value(pname) is not None:
            _update_option_setting(option_settings, 
                                   RdsDefault.Namespace, 
                                   RdsDefault.OptionNames[pname], 
                                   parameter_pool.get_value(pname))
    
    _trim_rds_options(option_settings, option_to_remove)
                    
    return spec
Exemplo n.º 2
0
def is_rds_snippet_compatible(parameter_pool,
                              solution_stack,
                              snippet_url=None):
    if snippet_url is None:
        snippet_url = parameter_pool.get_value(ParameterName.RdsSnippetUrl)
    eb_client = api_wrapper.create_eb_client(parameter_pool)

    app_name = parameter_pool.get_value(ParameterName.ApplicationName)
    api_wrapper.create_application(parameter_pool,
                                   app_name,
                                   eb_client=eb_client)

    spec = TemplateSpecification(TemplateSource(solution_stack), [
        TemplateSnippet(RdsDefault.SnippetName,
                        snippet_url,
                        order=RdsDefault.SnippetAddOrder)
    ])
    try:
        log.info('Send request for ValidateConfigurationSettings call.')
        response = eb_client.validate_configuration_settings(
            application_name=app_name, template_specification=spec)
        log.info('Received response for ValidateConfigurationSettings call.')
        api_wrapper.log_response('ValidateConfigurationSettings',
                                 response.result)
    except MissingParameterException:
        return False
    else:
        log.info('Received response for ValidateConfigurationSettings call.')
        api_wrapper.log_response('ValidateConfigurationSettings',
                                 response.result)

    return True
    def execute(self, parameter_pool):
        eb_client = self._get_eb_client(parameter_pool)
        app_name = parameter_pool.get_value(ParameterName.ApplicationName,
                                            False)
        env_name = parameter_pool.get_value(ParameterName.EnvironmentName,
                                            False)
        stack_name = parameter_pool.get_value(ParameterName.SolutionStack,
                                              False)
        prompt.action(
            UpdateEnvironmentOptionSettingOpMessage.Start.format(env_name))

        spec = TemplateSpecification()

        # Try load option setting file if exist
        option_location = parameter_pool.get_value(
            ParameterName.OptionSettingFile, False)
        option_settings = config_file.load_env_option_setting_file(
            option_location, quiet=True)
        if option_settings is not None and len(option_settings) > 0:
            prompt.info(
                UpdateEnvironmentOptionSettingOpMessage.UsingOptionSetting.
                format(option_location))
        else:
            option_settings = dict()

        option_remove = dict()
        self._option_setting_handler(parameter_pool, spec, stack_name,
                                     option_settings, option_remove)

        self._validate_change(parameter_pool, eb_client, app_name, env_name,
                              option_settings, option_remove, spec)

        try:
            response = eb_client.update_environment(
                env_name,
                option_settings=option_settings,
                option_remove=option_remove,
                template_specification=spec)
        except:
            raise
        else:
            log.info(u'Received response for UpdateEnvironemnt call.')
            prompt.result(
                UpdateEnvironmentOptionSettingOpMessage.Succeed.format(
                    env_name))

            self._log_api_result(self.__class__.__name__, u'UpdateEnvironment',
                                 response.result)

            parameter_pool.put(
                Parameter(ParameterName.UpdateEnvironmentRequestID,
                          response.request_id,
                          ParameterSource.OperationOutput))

            ret_result = OperationResult(
                self, response.request_id,
                UpdateEnvironmentOptionSettingOpMessage.Succeed.format(
                    env_name), response.result)
        return ret_result
    def execute(self, parameter_pool):
        eb_client = ElasticBeanstalkClient(
            parameter_pool.get_value(ParameterName.AwsAccessKeyId),
            parameter_pool.get_value(ParameterName.AwsSecretAccessKey),
            parameter_pool.get_value(ParameterName.ServiceEndpoint))
        app_name = parameter_pool.get_value(ParameterName.ApplicationName)
        env_name = parameter_pool.get_value(ParameterName.EnvironmentName)
        stack_name = parameter_pool.get_value(ParameterName.SolutionStack)
        prompt.action(
            UpdateEnvironmentOptionSettingOpMessage.Start.format(env_name))

        location = parameter_pool.get_value(ParameterName.OptionSettingFile)
        option_settings = config_file.load_env_option_setting_file(location,
                                                                   quiet=True)
        if option_settings is not None and len(option_settings) > 0:
            prompt.info(
                UpdateEnvironmentOptionSettingOpMessage.UsingOptionSetting.
                format(location))
        else:
            option_settings = []

        option_remove = set()
        spec = TemplateSpecification()
        rds_utils.rds_handler(parameter_pool, spec, stack_name,
                              option_settings, option_remove)
        self._option_setting_handler(option_settings, option_remove)

        self._validate_change(parameter_pool, eb_client, app_name, env_name,
                              option_settings, option_remove, spec)

        try:
            response = eb_client.update_environment(
                env_name,
                option_settings=option_settings,
                option_remove=option_remove,
                template_specification=spec)
        except:
            raise
        else:
            log.info('Received response for UpdateEnvironemnt call.')
            prompt.result(
                UpdateEnvironmentOptionSettingOpMessage.Succeed.format(
                    env_name))

            self._log_api_result(self.__class__.__name__, 'UpdateEnvironment',
                                 response.result)

            parameter_pool.put(
                Parameter(ParameterName.UpdateEnvironmentRequestID,
                          response.request_id,
                          ParameterSource.OperationOutput))

            ret_result = OperationResult(
                self, response.request_id,
                UpdateEnvironmentOptionSettingOpMessage.Succeed.format(
                    env_name), response.result)
        return ret_result
Exemplo n.º 5
0
    def execute(self, parameter_pool):
        eb_client = ElasticBeanstalkClient(parameter_pool.get_value(ParameterName.AwsAccessKeyId), 
                                           parameter_pool.get_value(ParameterName.AwsSecretAccessKey),
                                           parameter_pool.get_value(ParameterName.ServiceEndpoint))
        app_name = parameter_pool.get_value(ParameterName.ApplicationName)
        version_name = parameter_pool.get_value(ParameterName.ApplicationVersionName)        
        env_name = parameter_pool.get_value(ParameterName.EnvironmentName)
        stack_name = parameter_pool.get_value(ParameterName.SolutionStack)

        # Try load option setting file if exist
        option_file_location = parameter_pool.get_value(ParameterName.OptionSettingFile)             
        option_settings = config_file.load_env_option_setting_file(option_file_location,
                                                                   quiet = True)
        if option_settings is not None and len(option_settings) > 0:
            prompt.info(CreateEnvironmentOpMessage.UsingOptionSetting.format(option_file_location))
        else:
            option_settings = []

        option_remove = set()
        spec = TemplateSpecification()
        rds_utils.rds_handler(parameter_pool, spec, stack_name, option_settings, option_remove)
        self._option_setting_handler(option_settings, option_remove)
                 
        prompt.action(CreateEnvironmentOpMessage.Start.format(env_name))
        try:
            response = eb_client.create_environment(application = app_name,
                                                    environment = env_name,
                                                    solution_stack = stack_name,
                                                    version_label = version_name,
                                                    option_settings = option_settings,
                                                    option_remove = option_remove,
                                                    template_specification = spec,
                                                    )
        except AlreadyExistException:
            log.info(u'Environment "{0}" already exist.'.format(env_name))
            prompt.result(CreateEnvironmentOpMessage.AlreadyExist.format(env_name))
   
            ret_result = OperationResult(self, 
                                         None, 
                                        CreateEnvironmentOpMessage.AlreadyExist.format(env_name), 
                                         None)
        else:
            log.info(u'Received response for CreateEnvironemnt call.')
            prompt.info(CreateEnvironmentOpMessage.Succeed)
            prompt.result(CreateEnvironmentOpMessage.WaitAfterLaunch.format(env_name))
            self._log_api_result(self.__class__.__name__, u'CreateEnvironment', response.result)            
            
            parameter_pool.put(Parameter(ParameterName.CreateEnvironmentRequestID,
                                         response.request_id,
                                         ParameterSource.OperationOutput))
            
            ret_result = OperationResult(self,
                                         response.request_id, 
                                         CreateEnvironmentOpMessage.Succeed,
                                         response.result)
        return ret_result
Exemplo n.º 6
0
def _remove_rds_extension(parameter_pool, option_settings, option_to_remove):
    region = parameter_pool.get_value(ParameterName.Region)
    
    #Generate snippet
    spec = TemplateSpecification()
    snippet = TemplateSnippet()
    snippet.snippet_name = RdsDefault.SnippetName
    snippet.source_url = RdsDefault.get_snippet_url(region)
    snippet.order = RdsDefault.SnippetRemoveOrder
    spec.template_snippets = [snippet]
    
    #Remove option settings
    for pname in RdsDefault.OptionNames:
        _remove_option_setting(option_settings, 
                               option_to_remove,
                               RdsDefault.Namespace, 
                               RdsDefault.OptionNames[pname])

    return spec
Exemplo n.º 7
0
def has_default_app(parameter_pool, solution_stack, eb_client = None):
    appsource_options = {DefaultAppSource.Namespace : {DefaultAppSource.OptionName}}
    
    if not eb_client:
        eb_client = api_wrapper.create_eb_client(parameter_pool)
    
    spec = TemplateSpecification()
    spec.template_source.solution_stack_name = solution_stack,     
    
    options = api_wrapper.retrieve_configuration_options(eb_client = eb_client,
                                            solution_stack = solution_stack,
                                            options = appsource_options,
                                            template_specification = spec)
    for option in options:
        if misc.string_equal_ignore_case(DefaultAppSource.Namespace, option.namespace) \
            and misc.string_equal_ignore_case(DefaultAppSource.OptionName, option.name):
            return True
        
    return False
Exemplo n.º 8
0
    def execute(self, parameter_pool):
        eb_client = self._get_eb_client(parameter_pool)
        app_name = parameter_pool.get_value(ParameterName.ApplicationName,
                                            False)
        version_name = eb_utils.check_app_version(parameter_pool, eb_client)
        env_name = parameter_pool.get_value(ParameterName.EnvironmentName,
                                            False)
        stack_name = parameter_pool.get_value(ParameterName.SolutionStack,
                                              False)
        tier = parameter_pool.get_value(ParameterName.EnvironmentTier, False)

        spec = TemplateSpecification()

        # Try load option setting file if exist
        option_location = parameter_pool.get_value(
            ParameterName.OptionSettingFile, False)
        option_settings = config_file.load_env_option_setting_file(
            option_location, quiet=True)
        if option_settings is not None and len(option_settings) > 0:
            prompt.info(
                CreateEnvironmentOpMessage.UsingOptionSetting.format(
                    option_location))
        else:
            option_settings = dict()

        option_remove = dict()

        # Process extensions first before we process options
        self._extension_handler(parameter_pool, spec, stack_name,
                                option_settings, option_remove)

        # Process options
        self._option_setting_handler(parameter_pool, spec, stack_name, None,
                                     option_settings, option_remove)

        prompt.action(CreateEnvironmentOpMessage.Start.format(env_name))
        try:
            response = eb_client.create_environment(
                application=app_name,
                environment=env_name,
                solution_stack=stack_name,
                version_label=version_name,
                option_settings=option_settings,
                option_remove=option_remove,
                template_specification=spec,
                tier=tier)
        except AlreadyExistException:
            log.info(u'Environment "{0}" already exist.'.format(env_name))
            prompt.result(
                CreateEnvironmentOpMessage.AlreadyExist.format(env_name))

            ret_result = OperationResult(
                self, None,
                CreateEnvironmentOpMessage.AlreadyExist.format(env_name), None)
        else:
            log.info(u'Received response for CreateEnvironemnt call.')
            prompt.info(CreateEnvironmentOpMessage.Succeed)
            prompt.result(
                CreateEnvironmentOpMessage.WaitAfterLaunch.format(env_name))
            self._log_api_result(self.__class__.__name__, u'CreateEnvironment',
                                 response.result)

            parameter_pool.put(
                Parameter(ParameterName.CreateEnvironmentRequestID,
                          response.request_id,
                          ParameterSource.OperationOutput))

            ret_result = OperationResult(self, response.request_id,
                                         CreateEnvironmentOpMessage.Succeed,
                                         response.result)
        return ret_result