我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用oslo_config.cfg.NoSuchOptError()。
def _get_allowed_hostclass(self, project_name): """Get the allowed list of hostclass from configuration.""" try: group = CONF[project_name] except cfg.NoSuchOptError: # dynamically add the group into the configuration group = cfg.OptGroup(project_name, 'project options') CONF.register_group(group) CONF.register_opt(cfg.ListOpt('allowed_classes'), group=project_name) try: allowed_classes = CONF[project_name].allowed_classes except cfg.NoSuchOptError: LOG.error('No allowed_classes config option in [%s]', project_name) return [] else: if allowed_classes: return allowed_classes else: return []
def __init__(self, message=None, **kwargs): self.kwargs = kwargs if 'code' not in self.kwargs and hasattr(self, 'code'): self.kwargs['code'] = self.code if message: self.message = message try: self.message = self.message % kwargs except KeyError: # kwargs doesn't match a variable in the message # log the issue and the kwargs LOG.exception('Exception in string format operation, ' 'kwargs: %s', kwargs) try: ferr = CONF.fatal_exception_format_errors except cfg.NoSuchOptError: ferr = CONF.oslo_versionedobjects.fatal_exception_format_errors if ferr: raise super(ZunException, self).__init__(self.message)
def safe_get(self, value): try: return self.__getattr__(value) except cfg.NoSuchOptError: return None
def __init__(self, message=None, **kwargs): self.kwargs = kwargs if 'code' not in self.kwargs: try: self.kwargs['code'] = self.code except AttributeError: pass if message: self.message = message try: self.message = self.message % kwargs except Exception as e: # kwargs doesn't match a variable in the message # log the issue and the kwargs LOG.exception('Exception in string format operation') for name, value in kwargs.items(): LOG.error("%(name)s: %(value)s" % {'name': name, 'value': value}) try: if CONF.fatal_exception_format_errors: raise e except cfg.NoSuchOptError: # Note: work around for Bug: #1447873 if CONF.oslo_versionedobjects.fatal_exception_format_errors: raise e super(GluonException, self).__init__(self.message)
def get_project_name(project_id): """Given a keystone project-id return the name of the project.""" # Handle case where no credentials are configured try: ks = get_client() except cfg.NoSuchOptError: return None try: data = ks.get('projects/%s' % project_id) except keystone_exception.NotFound: return None else: project_data = data[1].get('project', {}) return project_data.get('name')
def get_user_name(user_id): """Given a keystone user-id return the name of the user.""" # Handle case where no credentials are configured try: ks = get_client() except cfg.NoSuchOptError: return None try: data = ks.get('users/%s' % user_id) except keystone_exception.NotFound: return None else: user_data = data[1].get('user', {}) return user_data.get('name')
def get_fqdn(hostname, project_name=None): domain = get_domain() try: project_subdomain = CONF.project_subdomain except cfg.NoSuchOptError: return '%s.%s' % (hostname, domain) if project_subdomain: LOG.warn('Project subdomain is experimental') return '%s.%s.%s' % (hostname, project_name, domain) else: return '%s.%s' % (hostname, domain)
def set_cloud_config_values(conf, args): """Set values from client's cloud config file. If the cloud config files was provided, set admin and non-admin credentials and uri. Note: the values may be later overriden by values specified in CLI. :conf TempestConf object :args parsed arguments including client config values """ cloud_creds = args.config.get('auth') if cloud_creds: try: if args.non_admin: conf.set('identity', 'username', cloud_creds['username']) conf.set('identity', 'tenant_name', cloud_creds['project_name']) conf.set('identity', 'password', cloud_creds['password']) else: conf.set('identity', 'admin_username', cloud_creds['username']) conf.set('identity', 'admin_tenant_name', cloud_creds['project_name']) conf.set('identity', 'admin_password', cloud_creds['password']) conf.set('identity', 'uri', cloud_creds['auth_url']) except cfg.NoSuchOptError: LOG.warning( 'Could not load some identity options from cloud config file')
def is_loaded(self): try: return OVN_ML2_MECH_DRIVER_NAME in cfg.CONF.ml2.mechanism_drivers except cfg.NoSuchOptError: return False
def set_mysql_engine(): try: mysql_engine = neutron_config.command.mysql_engine except cfg.NoSuchOptError: mysql_engine = None global MYSQL_ENGINE MYSQL_ENGINE = (mysql_engine or model_base.BASEV2.__table_args__['mysql_engine'])
def create_node(self, instance, image_meta, *args, **kwargs): config = self.load_config() # Get info image_id = getattr(image_meta.properties, 'os_distro') flavor_name = instance.flavor['name'] node_config = {'name': instance.uuid} # Find image for image in self.driver.list_images(): if image.id == image_id: node_config['image'] = image break else: Exception('Image with id "{}" not found'.format(image_id)) # Find size for size in self.driver.list_sizes(): if size.id == flavor_name: node_config['size'] = size break else: Exception('Flavor with id "{}" not found'.format(flavor_name)) # Find location for location in self.driver.list_locations(): if location.id == config['location']: node_config['location'] = location break else: Exception('Location with id "{}" not found'.format(config['location'])) # Root password try: if config.get('root_password'): node_config['auth'] = NodeAuthPassword(config.get('root_password')) except cfg.NoSuchOptError: pass instance = self.driver.create_node(**node_config) return instance