def trim_vpc_options(parameter_pool, option_settings, option_to_remove): if OptionSettingVPC.Namespace in option_settings\ and OptionSettingVPC.MagicOptionName in option_settings[OptionSettingVPC.Namespace]\ and not misc.is_blank_string(option_settings[OptionSettingVPC.Namespace]\ [OptionSettingVPC.MagicOptionName]): # VPC enabled for namespace in OptionSettingVPC.TrimOption: for option in OptionSettingVPC.TrimOption[namespace]: remove_option_setting(option_settings, option_to_remove, namespace, option) # Reapply DBSubnets if RDS is enabled if parameter_pool.get_value(PName.RdsEnabled): option_location = parameter_pool.get_value(PName.OptionSettingFile, False) ori_option_settings = config_file.load_env_option_setting_file( option_location, quiet=True) if OptionSettingVPC.Namespace in ori_option_settings\ and OptionSettingVPC.DBSubnets in ori_option_settings[OptionSettingVPC.Namespace]: dbsubnets = ori_option_settings[OptionSettingVPC.Namespace][ OptionSettingVPC.DBSubnets] if not misc.is_blank_string(dbsubnets): add_option_setting(option_settings, option_to_remove, OptionSettingVPC.Namespace, OptionSettingVPC.DBSubnets, dbsubnets) else: # VPC disabled remove_option_namespace(option_settings, option_to_remove, OptionSettingVPC.Namespace)
def trim_vpc_options(parameter_pool, option_settings, option_to_remove): if OptionSettingVPC.Namespace in option_settings\ and OptionSettingVPC.MagicOptionName in option_settings[OptionSettingVPC.Namespace]\ and not misc.is_blank_string(option_settings[OptionSettingVPC.Namespace]\ [OptionSettingVPC.MagicOptionName]): # VPC enabled for namespace in OptionSettingVPC.TrimOption: for option in OptionSettingVPC.TrimOption[namespace]: remove_option_setting(option_settings, option_to_remove, namespace, option) # Reapply DBSubnets if RDS is enabled if parameter_pool.get_value(PName.RdsEnabled): option_location = parameter_pool.get_value(PName.OptionSettingFile, False) ori_option_settings = config_file.load_env_option_setting_file(option_location, quiet = True) if OptionSettingVPC.Namespace in ori_option_settings\ and OptionSettingVPC.DBSubnets in ori_option_settings[OptionSettingVPC.Namespace]: dbsubnets = ori_option_settings[OptionSettingVPC.Namespace][OptionSettingVPC.DBSubnets] if not misc.is_blank_string(dbsubnets): add_option_setting(option_settings, option_to_remove, OptionSettingVPC.Namespace, OptionSettingVPC.DBSubnets, dbsubnets) else: # VPC disabled remove_option_namespace(option_settings, option_to_remove, OptionSettingVPC.Namespace)
def trim_vpc_options(option_settings, option_to_remove): if OptionSettingVPC.Namespace in option_settings\ and OptionSettingVPC.MagicOptionName in option_settings[OptionSettingVPC.Namespace]\ and not misc.is_blank_string(option_settings[OptionSettingVPC.Namespace]\ [OptionSettingVPC.MagicOptionName]): # VPC enabled for namespace in OptionSettingVPC.TrimOption: for option in OptionSettingVPC.TrimOption[namespace]: remove_option_setting(option_settings, option_to_remove, namespace, option) else: # VPC disabled remove_option_namespace(option_settings, option_to_remove, OptionSettingVPC.Namespace)
def load_eb_config_file(location, parameter_pool, quiet = False): log.info(u'Reading EB configuration from file: "{0}"'.format(location)) try: try: parser = SectionedConfigParser() parser.read(location) log.debug(u'Found a sectioned config file.') extra_config = dict() extra_config[EbConfigFile.RootSectionName] = dict() branches = dict() for section in parser.sections(): log.debug(u'Reading section "{0}" from config file.'.format(section)) # Known sections if section in EbConfigFile.KnownSections.keys(): for key, value in parser.items(section): if ConfigFileParameters.has_key(key): from_file, _ = ConfigFileParameters[key] if from_file: value = from_file(value) parameter_pool.put(Parameter(key, value, ParameterSource.ConfigFile)) else: extra_config[EbConfigFile.RootSectionName][key] = value elif section == EbConfigFile.BranchSectionName: #branch section branch_mapping = dict() for key, value in parser.items(section): branch_mapping[key] = value parameter_pool.put(Parameter(ParameterName.BranchMapping, branch_mapping, ParameterSource.ConfigFile)) elif section.startswith(EbConfigFile.BranchSectionPrefix): #branch environment session parsed = section.split(EbConfigFile.SectionNameDelimiter) if len(parsed) != 2 or misc.is_blank_string(parsed[1]): continue # skip if no environment name branch_name = parsed[1] branches[branch_name] = dict() for key, value in parser.items(section): if ConfigFileParameters.has_key(key): from_file, _ = ConfigFileParameters[key] if from_file: value = from_file(value) branches[branch_name][key] = value else: if not extra_config.has_key(section): extra_config[section] = dict() extra_config[section][key] = value else: # unknown sections new_section = dict() for key, value in parser.items(section): new_section[key] = value extra_config[section] = new_section parameter_pool.put(Parameter(ParameterName.ConfigFileExtra, extra_config, ParameterSource.ConfigFile)) parameter_pool.put(Parameter(ParameterName.Branches, branches, ParameterSource.ConfigFile)) except MissingSectionHeaderError as ex: # old format: sectionless config file log.debug(u'Found a section-less config file.') nosect_parser = NoSectionConfigParser() nosect_parser.read(location) for name, (from_file, _) in ConfigFileParameters.iteritems(): if nosect_parser.has_option(name): value = nosect_parser.get(name) if from_file is not None: value = from_file(value) parameter_pool.put(Parameter(name, value, ParameterSource.ConfigFile)) # Add original parameter infos for name, ori_name in EbConfigFile.BranchResetParameters.iteritems(): if parameter_pool.has(name): parameter_pool.put(Parameter(ori_name, parameter_pool.get_value(name), ParameterSource.ConfigFile)) log.info(u'Finished reading from EB configuration file.') except BaseException as ex: log.error(u'Failed to parse EB configuration from file, because: "{0}"'.format(ex)) if not quiet: if (isinstance(ex, OSError) or isinstance(ex, IOError)) and\ ex.errno == FileErrorConstant.FileNotFoundErrorCode: raise EBConfigFileNotExistError(ex) else: msg = ConfigFileErrorMessage.ReadError.format(location) prompt.error(msg) raise EBConfigFileNotExistError(msg) else: pass # if failed, just skip