Esempio n. 1
0
    def ask_region(cls, parameter_pool):
        original_value = parameter_pool.get_value(ParameterName.Region)

        original_source = parameter_pool.get_source(ParameterName.Region) \
            if parameter_pool.has(ParameterName.Region) else None

        if original_value is not None and \
            ParameterSource.is_ahead(original_source, ParameterSource.Terminal):
            print((TerminalPromptSettingParameterMessage[ParameterName.Region].\
                      format(ServiceRegionName[original_value])))
            region_value = original_value
        else:
            append_message = '' if original_value is None \
                else TerminalMessage.CurrentValue.format(ServiceRegionName[original_value])
            print(TerminalPromptAskingMessage[ParameterName.Region].format(
                append_message))

            region_name_list = list()
            for region in AvailableServiceRegion:
                region_name_list.append(ServiceRegionName[region])
            region_index = cls.single_choice(
                choice_list=region_name_list,
                title=TerminalMessage.AvailableRegion,
                can_return_none=original_value is not None)

            region_value = AvailableServiceRegion[region_index] \
                if region_index is not None else original_value
            region = Parameter(ParameterName.Region,
                               misc.to_unicode(region_value),
                               ParameterSource.Terminal)
            parameter_pool.put(region, True)

        # Set RDS service endpoints if not specified as CLI arguments
        log.info(
            'Generate RDS endpoint from region "{0}".'.format(region_value))
        eb_utils.generate_endpoint(parameter_pool, region_value,
                                   ParameterSource.Terminal)
        # Set RDS endpont and snippet if not specified as CLI arguments
        log.info(
            'Generate RDS snippet URL from region "{0}".'.format(region_value))
        rds_utils.generate_endpoint(parameter_pool, region_value,
                                    ParameterSource.Terminal)
    def ask_region(cls, parameter_pool):
        original_value = parameter_pool.get_value(ParameterName.Region) \
            if parameter_pool.has(ParameterName.Region) else None
        
        original_source = parameter_pool.get_source(ParameterName.Region) \
            if parameter_pool.has(ParameterName.Region) else None
        
        if original_value is not None and \
            ParameterSource.is_ahead(original_source, ParameterSource.Terminal):
            print(TerminalPromptSettingParameterMessage[ParameterName.Region].\
                      format(ServiceRegionName[original_value]))            
            region_value = original_value
        else:
            append_message = u'' if original_value is None \
                else TerminalMessage.CurrentValue.format(ServiceRegionName[original_value])        
            print TerminalPromptAskingMessage[ParameterName.Region].format(append_message)
            
            region_name_list = list()
            for region in AvailableServiceRegion:
                region_name_list.append(ServiceRegionName[region])
            region_index = cls.single_choice(region_name_list, 
                                              TerminalMessage.AvailableRegion, 
                                              None,
                                              original_value is not None)
            
            region_value = AvailableServiceRegion[region_index] \
                if region_index is not None else original_value
            region = Parameter(ParameterName.Region, 
                               misc.to_unicode(region_value), 
                               ParameterSource.Terminal)
            parameter_pool.put(region, True)

        # Set RDS service endpoints if not specified as CLI arguments
        log.info(u'Generate RDS endpoint from region "{0}".'.format(region_value))
        eb_utils.generate_endpoint(parameter_pool, region_value, ParameterSource.Terminal)
        # Set RDS endpont and snippet if not specified as CLI arguments
        log.info(u'Generate RDS snippet URL from region "{0}".'.format(region_value))
        rds_utils.generate_endpoint(parameter_pool, region_value, ParameterSource.Terminal)