Example #1
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
Example #2
0
def apply_instance_profile(parameter_pool, option_settings, option_to_remove):
    app_name = parameter_pool.get_value(ParameterName.ApplicationName, False)
    solution_stack = parameter_pool.get_value(ParameterName.SolutionStack,
                                              False)
    eb_client = api_wrapper.create_eb_client(parameter_pool)
    optionDef = eb_utils.get_option_def(
        eb_client=eb_client,
        app_name=app_name,
        namespace=OptionSettingIAMProfile.Namespace,
        option_name=OptionSettingIAMProfile.OptionName,
        solution_stack=solution_stack)
    if optionDef:
        # Solution stack supports instance profile
        profile_name = parameter_pool.get_value(
            ParameterName.InstanceProfileName)

        if OptionSettingIAMProfile.Namespace in option_settings\
            and OptionSettingIAMProfile.OptionName in option_settings[OptionSettingIAMProfile.Namespace]:
            # skip reset IAM profile name if option settings already have it
            return
        else:
            eb_utils.add_option_setting(
                option_settings=option_settings,
                option_remove=option_to_remove,
                namespace=OptionSettingIAMProfile.Namespace,
                option=OptionSettingIAMProfile.OptionName,
                value=profile_name)
    else:
        eb_utils.remove_option_setting(
            option_settings=option_settings,
            option_remove=option_to_remove,
            namespace=OptionSettingIAMProfile.Namespace,
            option=OptionSettingIAMProfile.OptionName,
            add_to_remove=False)
Example #3
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, False)
    eb_client = api_wrapper.create_eb_client(parameter_pool)

    app_name = parameter_pool.get_value(ParameterName.ApplicationName, False)    
    api_wrapper.create_application(parameter_pool, app_name, eb_client = eb_client)
    
    spec = TemplateSpecification()
    spec.template_snippets.append(TemplateSnippet(RdsDefault.SnippetName,
                                                 snippet_url, 
                                                 order = RdsDefault.SnippetAddOrder))
    spec.template_source.solution_stack_name = solution_stack 
        
    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 apply_instance_profile(parameter_pool, option_settings, option_to_remove):
    app_name = parameter_pool.get_value(ParameterName.ApplicationName, False)
    solution_stack = parameter_pool.get_value(ParameterName.SolutionStack, False)
    eb_client = api_wrapper.create_eb_client(parameter_pool)
    optionDef = eb_utils.get_option_def(eb_client = eb_client, 
                                        app_name = app_name, 
                                        namespace = OptionSettingIAMProfile.Namespace, 
                                        option_name = OptionSettingIAMProfile.OptionName, 
                                        solution_stack = solution_stack)    
    if optionDef:
        # Solution stack supports instance profile
        profile_name = parameter_pool.get_value(ParameterName.InstanceProfileName)
    
        if OptionSettingIAMProfile.Namespace in option_settings\
            and OptionSettingIAMProfile.OptionName in option_settings[OptionSettingIAMProfile.Namespace]:
                # skip reset IAM profile name if option settings already have it
                return
        else:
            eb_utils.add_option_setting(option_settings = option_settings, 
                                        option_remove = option_to_remove, 
                                        namespace = OptionSettingIAMProfile.Namespace, 
                                        option = OptionSettingIAMProfile.OptionName, 
                                        value = profile_name)
    else:
        eb_utils.remove_option_setting(option_settings = option_settings,
                                       option_remove = option_to_remove, 
                                       namespace = OptionSettingIAMProfile.Namespace,
                                       option = OptionSettingIAMProfile.OptionName,
                                       add_to_remove = False)
    def ask_environment_type(cls, parameter_pool):
        # Ensure application existence        
        eb_client = api_wrapper.create_eb_client(parameter_pool)
        app_name = parameter_pool.get_value(ParameterName.ApplicationName, False)    
        api_wrapper.create_application(parameter_pool, app_name, eb_client = eb_client)

        # Get available environment types
        solution_stack = parameter_pool.get_value(ParameterName.SolutionStack, False)
        optionDef = eb_utils.get_option_def(eb_client = eb_client, 
                                            app_name = app_name, 
                                            namespace = OptionSettingEnvironmentType.Namespace, 
                                            option_name = OptionSettingEnvironmentType.OptionName, 
                                            solution_stack = solution_stack)
        
        if optionDef and len(optionDef.value_options) > 0:
            # Ask for environment type is option is available
            original_value = parameter_pool.get_value(ParameterName.EnvironmentType)
            append_message = u'' if original_value is None \
                else TerminalMessage.CurrentValue.format(original_value)        
            print(TerminalPromptAskingMessage[ParameterName.EnvironmentType].\
                  format(append_message))
            
            availableTypes = optionDef.value_options
            type_index = cls.single_choice(choice_list = availableTypes, 
                                       title = TerminalMessage.AvailableEnvironmentType, 
                                       message = None, 
                                       can_return_none = original_value is not None)
            value = availableTypes[type_index] if type_index is not None else original_value
            envtype = Parameter(ParameterName.EnvironmentType, value, ParameterSource.Terminal)
            parameter_pool.put(envtype, True)
        else:
            # Remove environment type
            parameter_pool.remove(ParameterName.EnvironmentType)
Example #6
0
    def ask_environment_type(cls, parameter_pool):
        # Ensure application existence        
        eb_client = api_wrapper.create_eb_client(parameter_pool)
        app_name = parameter_pool.get_value(ParameterName.ApplicationName, False)    
        api_wrapper.create_application(parameter_pool, app_name, eb_client = eb_client)

        # Get available environment types
        solution_stack = parameter_pool.get_value(ParameterName.SolutionStack, False)
        optionDef = eb_utils.get_option_def(eb_client = eb_client, 
                                            app_name = app_name, 
                                            namespace = OptionSettingEnvironmentType.Namespace, 
                                            option_name = OptionSettingEnvironmentType.OptionName, 
                                            solution_stack = solution_stack)
        
        if optionDef and len(optionDef.value_options) > 0:
            # Ask for environment type is option is available
            original_value = parameter_pool.get_value(ParameterName.EnvironmentType)
            append_message = '' if original_value is None \
                else TerminalMessage.CurrentValue.format(original_value)        
            print((TerminalPromptAskingMessage[ParameterName.EnvironmentType].\
                  format(append_message)))
            
            availableTypes = optionDef.value_options
            type_index = cls.single_choice(choice_list = availableTypes, 
                                       title = TerminalMessage.AvailableEnvironmentType, 
                                       message = None, 
                                       can_return_none = original_value is not None)
            value = availableTypes[type_index] if type_index is not None else original_value
            envtype = Parameter(ParameterName.EnvironmentType, value, ParameterSource.Terminal)
            parameter_pool.put(envtype, True)
        else:
            # Remove environment type
            parameter_pool.remove(ParameterName.EnvironmentType)
Example #7
0
def apply_environment_type(parameter_pool, template_spec, stack_name, env_name,
                           option_settings, option_to_remove):
    # If not specified, skip
    envtype = parameter_pool.get_value(PName.EnvironmentType)
    if envtype:
        # Describe applicable option settings
        eb_client = api_wrapper.create_eb_client(parameter_pool)
        app_name = parameter_pool.get_value(PName.ApplicationName, False)

        if env_name:
            raw_option_defs = api_wrapper.retrieve_configuration_options(
                eb_client=eb_client,
                app_name=app_name,
                env_name=env_name,
                template_specification=template_spec,
                options=None)
        else:
            raw_option_defs = api_wrapper.retrieve_configuration_options(
                eb_client=eb_client,
                app_name=app_name,
                solution_stack=stack_name,
                template_specification=template_spec,
                options=None)

        option_defs = set()
        for raw_option_def in raw_option_defs:
            option_defs.add(raw_option_def.namespace + u'-' +
                            raw_option_def.name)

        # Return if environment type option is not available
        if OptionSettingEnvironmentType.Namespace + u'-' + \
            OptionSettingEnvironmentType.OptionName not in option_defs:
            prompt.result(
                ValidationMessage.EnvTypeInapplicable.format(envtype))
            return

        # remove inapplicable option settings
        removed = False
        for namespace in option_settings.keys():

            # TODO Fix this temporary hack to let environment tier options pass through
            if namespace == u'aws:elasticbeanstalk:sqsd':
                continue

            for option_name in option_settings[namespace].keys():
                if not is_customizable_namespace(namespace)\
                    and namespace + u'-' + option_name not in option_defs:
                    remove_option_setting(option_settings, option_to_remove,
                                          namespace, option_name, False)
                    removed = True
        if removed:
            prompt.result(ValidationMessage.EnvTypeBlowAwayOptionSettings)

        # Set environment type
        add_option_setting(option_settings, option_to_remove,
                           OptionSettingEnvironmentType.Namespace,
                           OptionSettingEnvironmentType.OptionName, envtype)
Example #8
0
def apply_environment_type(parameter_pool, template_spec, stack_name, env_name, option_settings, option_to_remove):
    # If not specified, skip 
    envtype = parameter_pool.get_value(PName.EnvironmentType)
    if envtype:
        # Describe applicable option settings
        eb_client = api_wrapper.create_eb_client(parameter_pool)
        app_name = parameter_pool.get_value(PName.ApplicationName, False)
        
        if env_name:
            raw_option_defs = api_wrapper.retrieve_configuration_options(eb_client=eb_client,
                                                              app_name=app_name,
                                                              env_name=env_name,
                                                              template_specification=template_spec,
                                                              options=None)
        else:
            raw_option_defs = api_wrapper.retrieve_configuration_options(eb_client=eb_client,
                                                              app_name=app_name,
                                                              solution_stack=stack_name,
                                                              template_specification=template_spec,
                                                              options=None)
        
        option_defs = set()
        for raw_option_def in raw_option_defs:
            option_defs.add(raw_option_def.namespace + '-' + raw_option_def.name)

        # Return if environment type option is not available
        if OptionSettingEnvironmentType.Namespace + '-' + \
            OptionSettingEnvironmentType.OptionName not in option_defs:
            prompt.result(ValidationMessage.EnvTypeInapplicable.format(envtype))
            return

        # remove inapplicable option settings
        removed = False
        for namespace in list(option_settings.keys()):
            
            # TODO Fix this temporary hack to let environment tier options pass through
            if namespace == 'aws:elasticbeanstalk:sqsd':
                continue
            
            for option_name in list(option_settings[namespace].keys()):
                if not is_customizable_namespace(namespace)\
                    and namespace + '-' + option_name not in option_defs:
                    remove_option_setting(option_settings, option_to_remove, 
                                          namespace, option_name, False)
                    removed = True
        if removed:
            prompt.result(ValidationMessage.EnvTypeBlowAwayOptionSettings)

        # Set environment type
        add_option_setting(option_settings, option_to_remove, 
                           OptionSettingEnvironmentType.Namespace, 
                           OptionSettingEnvironmentType.OptionName, 
                           envtype)
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
Example #10
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
Example #11
0
def apply_environment_type(parameter_pool, stack_name, option_settings,
                           option_to_remove):
    # If not specified, skip
    envtype = parameter_pool.get_value(PName.EnvironmentType)
    if envtype:
        # Describe applicable option settings
        eb_client = api_wrapper.create_eb_client(parameter_pool)
        app_name = parameter_pool.get_value(PName.ApplicationName, False)
        raw_option_defs = api_wrapper.retrieve_configuration_options(
            eb_client=eb_client,
            app_name=app_name,
            solution_stack=stack_name,
            options=None)
        option_defs = set()
        for raw_option_def in raw_option_defs:
            option_defs.add(raw_option_def.namespace + u'-' +
                            raw_option_def.name)

        # Return if environment type option is not available
        if OptionSettingEnvironmentType.Namespace + u'-' + \
            OptionSettingEnvironmentType.OptionName not in option_defs:
            prompt.result(
                ValidationMessage.EnvTypeInapplicable.format(envtype))
            return

        # remove inapplicable option settings
        removed = False
        for namespace in option_settings.keys():
            for option_name in option_settings[namespace].keys():
                if namespace + u'-' + option_name not in option_defs:
                    remove_option_setting(option_settings, option_to_remove,
                                          namespace, option_name, False)
                    removed = True
        if removed:
            prompt.result(ValidationMessage.EnvTypeBlowAwayOptionSettings)

        # Set environment type
        add_option_setting(option_settings, option_to_remove,
                           OptionSettingEnvironmentType.Namespace,
                           OptionSettingEnvironmentType.OptionName, envtype)
Example #12
0
def apply_environment_type(parameter_pool, stack_name, option_settings, option_to_remove):
    # If not specified, skip 
    envtype = parameter_pool.get_value(PName.EnvironmentType)
    if envtype:
        # Describe applicable option settings
        eb_client = api_wrapper.create_eb_client(parameter_pool)
        app_name = parameter_pool.get_value(PName.ApplicationName, False)
        raw_option_defs = api_wrapper.retrieve_configuration_options(eb_client = eb_client, 
                                                              app_name = app_name, 
                                                              solution_stack =stack_name, 
                                                              options = None)    
        option_defs = set()
        for raw_option_def in raw_option_defs:
            option_defs.add(raw_option_def.namespace + u'-' + raw_option_def.name)

        # Return if environment type option is not available
        if OptionSettingEnvironmentType.Namespace + u'-' + \
            OptionSettingEnvironmentType.OptionName not in option_defs:
            prompt.result(ValidationMessage.EnvTypeInapplicable.format(envtype))
            return

        # remove inapplicable option settings
        removed = False
        for namespace in option_settings.keys():
            for option_name in option_settings[namespace].keys():
                if namespace + u'-' + option_name not in option_defs:
                    remove_option_setting(option_settings, option_to_remove, 
                                          namespace, option_name, False)
                    removed = True
        if removed:
            prompt.result(ValidationMessage.EnvTypeBlowAwayOptionSettings)

        # Set environment type
        add_option_setting(option_settings, option_to_remove, 
                           OptionSettingEnvironmentType.Namespace, 
                           OptionSettingEnvironmentType.OptionName, 
                           envtype)