Example #1
0
    def ask_environment_name(cls, parameter_pool):
        # Auto generate environment name if not specified by user
        if not parameter_pool.has(ParameterName.EnvironmentName):
            old_env_name = None
            app_name = parameter_pool.get_value(ParameterName.ApplicationName,
                                                False)
            env_name = cls.generate_env_name(app_name)
            cls.ask_parameter(parameter_pool,
                              ParameterName.EnvironmentName,
                              autogen_value=env_name)
        else:
            old_env_name = parameter_pool.get_value(
                ParameterName.EnvironmentName, False)
            cls.ask_parameter(parameter_pool, ParameterName.EnvironmentName)

        # Post processing
        new_env_name = parameter_pool.get_value(ParameterName.EnvironmentName,
                                                False)
        new_env_source = parameter_pool.get_source(
            ParameterName.EnvironmentName)

        # Reload RDS password if environment name changes
        if old_env_name != new_env_name:
            location = parameter_pool.get_value(
                ParameterName.AwsCredentialFile)
            rds_password = config_file.read_rds_master_password(
                new_env_name, location)
            if rds_password:
                parameter_pool.put(
                    Parameter(ParameterName.RdsMasterPassword, rds_password,
                              new_env_source))
            else:
                parameter_pool.remove(ParameterName.RdsMasterPassword)

        # Generate option setting file pathname
        if parameter_pool.get_source(ParameterName.OptionSettingFile) == ParameterSource.Default\
            or not misc.string_equal_ignore_case(old_env_name, new_env_name):
            new_opsetting_path = os.path.join(
                os.getcwdu(), EbLocalDir.Path,
                OptionSettingFile.Name + u'.' + new_env_name)
            old_opsetting_path = parameter_pool.get_value(
                ParameterName.OptionSettingFile, False)

            # Rename old style optionsetting file
            if parameter_pool.get_source(ParameterName.OptionSettingFile) == ParameterSource.Default\
                and parameter_pool.has(ParameterName.OriginalSolutionStack)\
                and old_opsetting_path and os.path.exists(old_opsetting_path):
                os.rename(old_opsetting_path, new_opsetting_path)

            # Update optionsetting file name in parameter pool
            parameter_pool.put(
                Parameter(ParameterName.OptionSettingFile, new_opsetting_path,
                          new_env_source))
    def ask_environment_name(cls, parameter_pool):
        # Auto generate environment name if not specified by user
        if not parameter_pool.has(ParameterName.EnvironmentName):
            old_env_name = None
            app_name = parameter_pool.get_value(ParameterName.ApplicationName)
            env_name = re.sub(ServiceDefault.Environment.REGEX_NAME_FILTER, 
                               u'', app_name, flags = re.UNICODE)
            if len(env_name) > 0:
                env_name = env_name + ServiceDefault.Environment.NAME_POSTFIX
                if len(env_name) > ServiceDefault.Environment.MAX_NAME_LEN:
                    env_name = env_name[:ServiceDefault.Environment.MAX_NAME_LEN]
            else:
                env_name = None
            cls.ask_parameter(parameter_pool, 
                               ParameterName.EnvironmentName,
                               autogen_value = env_name)
        else:
            old_env_name = parameter_pool.get_value(ParameterName.EnvironmentName)
            cls.ask_parameter(parameter_pool, ParameterName.EnvironmentName)            
    
        # Post processing
        new_env_name = parameter_pool.get_value(ParameterName.EnvironmentName)
        new_env_source = parameter_pool.get_source(ParameterName.EnvironmentName)
        
        # Reload RDS password if environment name changes
        if old_env_name != new_env_name:
            location = parameter_pool.get_value(ParameterName.AwsCredentialFile) \
                if parameter_pool.has(ParameterName.AwsCredentialFile) else None
            rds_password = config_file.read_rds_master_password(new_env_name, location)
            if rds_password:
                parameter_pool.put(Parameter(ParameterName.RdsMasterPassword,
                                             rds_password,
                                             new_env_source))
            else:
                parameter_pool.remove(ParameterName.RdsMasterPassword)
    
        # Generate option setting file pathname
        if parameter_pool.get_source(ParameterName.OptionSettingFile) == ParameterSource.Default\
            or not misc.string_equal_ignore_case(old_env_name, new_env_name):
            new_opsetting_path = os.path.join(os.getcwdu(), EbLocalDir.Path, 
                                           OptionSettingFile.Name + u'.' + new_env_name)
            old_opsetting_path = parameter_pool.get_value(ParameterName.OptionSettingFile)
            
            # Rename old style optionsetting file 
            if parameter_pool.get_source(ParameterName.OptionSettingFile) == ParameterSource.Default\
                and parameter_pool.has(ParameterName.OriginalSolutionStack)\
                and old_opsetting_path and os.path.exists(old_opsetting_path):
                os.rename(old_opsetting_path, new_opsetting_path)

            # Update optionsetting file name in parameter pool                
            parameter_pool.put(Parameter(ParameterName.OptionSettingFile,
                                         new_opsetting_path,
                                         new_env_source))
Example #3
0
    def ask_environment_name(cls, parameter_pool):
        # Auto generate environment name if not specified by user
        if not parameter_pool.has(ParameterName.EnvironmentName):
            old_env_name = None
            app_name = parameter_pool.get_value(ParameterName.ApplicationName, False)
            env_name = cls.generate_env_name(app_name)
            cls.ask_parameter(parameter_pool, 
                               ParameterName.EnvironmentName,
                               autogen_value = env_name)
        else:
            old_env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False)
            #cls.ask_parameter(parameter_pool, ParameterName.EnvironmentName)
            print "Env Name is %s \n" % old_env_name
            return old_env_name

    
        # Post processing
        new_env_name = parameter_pool.get_value(ParameterName.EnvironmentName, False)
        new_env_source = parameter_pool.get_source(ParameterName.EnvironmentName)
        
        # Reload RDS password if environment name changes
        if old_env_name != new_env_name:
            location = parameter_pool.get_value(ParameterName.AwsCredentialFile)
            rds_password = config_file.read_rds_master_password(new_env_name, location)
            if rds_password:
                parameter_pool.put(Parameter(ParameterName.RdsMasterPassword,
                                             rds_password,
                                             new_env_source))
            else:
                parameter_pool.remove(ParameterName.RdsMasterPassword)
    
        # Generate option setting file pathname
        if parameter_pool.get_source(ParameterName.OptionSettingFile) == ParameterSource.Default\
            or not misc.string_equal_ignore_case(old_env_name, new_env_name):
            new_opsetting_path = os.path.join(os.getcwdu(), EbLocalDir.Path, 
                                           OptionSettingFile.Name + u'.' + new_env_name)
            old_opsetting_path = parameter_pool.get_value(ParameterName.OptionSettingFile, False)
            
            # Rename old style optionsetting file 
            if parameter_pool.get_source(ParameterName.OptionSettingFile) == ParameterSource.Default\
                and parameter_pool.has(ParameterName.OriginalSolutionStack)\
                and old_opsetting_path and os.path.exists(old_opsetting_path):
                os.rename(old_opsetting_path, new_opsetting_path)

            # Update optionsetting file name in parameter pool                
            parameter_pool.put(Parameter(ParameterName.OptionSettingFile,
                                         new_opsetting_path,
                                         new_env_source))