def set_middleware_defaults(): """Update default configuration options for oslo.middleware.""" # CORS Defaults # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults(cors.CORS_OPTS, allow_headers=['X-Auth-Token', 'X-Openstack-Request-Id', 'X-Project-Id', 'X-Identity-Status', 'X-User-Id', 'X-Storage-Token', 'X-Domain-Id', 'X-User-Domain-Id', 'X-Project-Domain-Id', 'X-Roles'], expose_headers=['X-Auth-Token', 'X-Openstack-Request-Id', 'X-Project-Id', 'X-Identity-Status', 'X-User-Id', 'X-Storage-Token', 'X-Domain-Id', 'X-User-Domain-Id', 'X-Project-Domain-Id', 'X-Roles'], allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'] )
def set_defaults(**kwargs): """Override the default values for configuration options. This method permits a project to override the default CORS option values. For example, it may wish to offer a set of sane default headers which allow it to function with only minimal additional configuration. :param allow_credentials: Whether to permit credentials. :type allow_credentials: bool :param expose_headers: A list of headers to expose. :type expose_headers: List of Strings :param max_age: Maximum cache duration in seconds. :type max_age: Int :param allow_methods: List of HTTP methods to permit. :type allow_methods: List of Strings :param allow_headers: List of HTTP headers to permit from the client. :type allow_headers: List of Strings """ # Since 'None' is a valid config override, we have to use kwargs. Else # there's no good way for a user to override only one option, because all # the others would be overridden to 'None'. valid_params = set(k.name for k in CORS_OPTS if k.name != 'allowed_origin') passed_params = set(k for k in kwargs) wrong_params = passed_params - valid_params if wrong_params: raise AttributeError( 'Parameter(s) [%s] invalid, please only use [%s]' % (wrong_params, valid_params)) # Set global defaults. cfg.set_defaults(CORS_OPTS, **kwargs)
def get_ksa_adapter_opts(default_service_type, deprecated_opts=None): """Get auth, Session, and Adapter conf options from keystonauth1.loading. :param default_service_type: Default for the service_type conf option on the Adapter. :param deprecated_opts: dict of deprecated opts to register with the ksa Adapter opts. Works the same as the deprecated_opts kwarg to: keystoneauth1.loading.session.Session.register_conf_options :return: List of cfg.Opts. """ opts = ks_loading.get_adapter_conf_options(include_deprecated=False, deprecated_opts=deprecated_opts) for opt in opts[:]: # Remove version-related opts. Required/supported versions are # something the code knows about, not the operator. if opt.dest in _ADAPTER_VERSION_OPTS: opts.remove(opt) # Override defaults that make sense for nova cfg.set_defaults(opts, valid_interfaces=['internal', 'public'], service_type=default_service_type) return opts
def add_auth_opts(options, service_type=None): """Add auth options to sample config As these are dynamically registered at runtime, this adds options for most used auth_plugins when generating sample config. """ def add_options(opts, opts_to_add): for new_opt in opts_to_add: for opt in opts: if opt.name == new_opt.name: break else: opts.append(new_opt) opts = copy.deepcopy(options) opts.insert(0, kaloading.get_auth_common_conf_options()[0]) # NOTE(dims): There are a lot of auth plugins, we just generate # the config options for a few common ones plugins = ['password', 'v2password', 'v3password'] for name in plugins: plugin = kaloading.get_plugin_loader(name) add_options(opts, kaloading.get_auth_plugin_conf_options(plugin)) add_options(opts, kaloading.get_session_conf_options()) if service_type: adapter_opts = kaloading.get_adapter_conf_options( include_deprecated=False) # adding defaults for valid interfaces cfg.set_defaults(adapter_opts, service_type=service_type, valid_interfaces=DEFAULT_VALID_INTERFACES) add_options(opts, adapter_opts) opts.sort(key=lambda x: x.name) return opts
def set_middleware_defaults(): """Update default configuration options for oslo.middleware.""" # CORS Defaults # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults( cors.CORS_OPTS, allow_headers=[ "X-Auth-Token", "X-Identity-Status", "X-Roles", "X-Service-Catalog", "X-User-Id", "X-Tenant-Id", "X-OpenStack-Request-ID", "X-Trace-Info", "X-Trace-HMAC", "OpenStack-API-Version", ], expose_headers=[ "X-Auth-Token", "X-Subject-Token", "X-Service-Token", "X-OpenStack-Request-ID", "OpenStack-API-Version", ], allow_methods=["GET", "PUT", "POST", "DELETE", "PATCH", "HEAD"], )
def set_defaults(**kwargs): """Override the default values for configuration options. This method permits a project to override the default CORS option values. For example, it may wish to offer a set of sane default headers which allow it to function with only minimal additional configuration. :param allow_credentials: Whether to permit credentials. :type allow_credentials: bool :param expose_headers: A list of headers to expose. :type expose_headers: List of Strings :param max_age: Maximum cache duration in seconds. :type max_age: Int :param allow_methods: List of HTTP methods to permit. :type allow_methods: List of Strings :param allow_headers: List of HTTP headers to permit from the client. :type allow_headers: List of Strings """ # Since 'None' is a valid config override, we have to use kwargs. Else # there's no good way for a user to override only one option, because all # the others would be overridden to 'None'. valid_params = set(k.name for k in CORS_OPTS if k.name != 'allowed_origin') passed_params = set(k for k in kwargs) wrong_params = passed_params - valid_params if wrong_params: raise AttributeError('Parameter(s) [%s] invalid, please only use [%s]' % (wrong_params, valid_params)) # Set global defaults. cfg.set_defaults(CORS_OPTS, **kwargs)
def set_transport_defaults(control_exchange): """Set defaults for messaging transport configuration options. :param control_exchange: the default exchange under which topics are scoped :type control_exchange: str """ cfg.set_defaults(_transport_opts, control_exchange=control_exchange)
def _init_from_oslo(self, conf): '''Initialize this middleware from an oslo.config instance.''' # First, check the configuration and register global options. conf.register_opts(CORS_OPTS, 'cors') # Clone our original CORS_OPTS, and set the defaults to whatever is # set in the global conf instance. This is done explicitly (instead # of **kwargs), since we don't accidentally want to catch # allowed_origin. subgroup_opts = copy.deepcopy(CORS_OPTS) cfg.set_defaults(subgroup_opts, allow_credentials=conf.cors.allow_credentials, expose_headers=conf.cors.expose_headers, max_age=conf.cors.max_age, allow_methods=conf.cors.allow_methods, allow_headers=conf.cors.allow_headers) # If the default configuration contains an allowed_origin, don't # forget to register that. if conf.cors.allowed_origin: self.add_origin(**conf.cors) # Iterate through all the loaded config sections, looking for ones # prefixed with 'cors.' for section in conf.list_all_sections(): if section.startswith('cors.'): # Register with the preconstructed defaults conf.register_opts(subgroup_opts, section) self.add_origin(**conf[section])
def prepare_service(argv=[], conf=cfg.CONF): log.register_options(conf) config.parse_args(argv) cfg.set_defaults(_options.log_opts, default_log_levels=_DEFAULT_LOG_LEVELS) log.setup(conf, 'python-watcher') conf.log_opt_values(LOG, logging.DEBUG)
def prepare_service(argv=None): eventlet.monkey_patch() gettextutils.install('gringotts', lazy=False) # Override the default control_exchange, default is 'openstack' rpc.set_defaults(control_exchange='gringotts') cfg.set_defaults(log.log_opts, default_log_levels=['amqplib=WARN', 'qpid.messaging=INFO', 'sqlalchemy=WARN', 'keystoneclient=INFO', 'stevedore=INFO', 'eventlet.wsgi.server=WARN' ]) if argv is None: argv = sys.argv cfg.CONF(argv[1:], project='gringotts') log.setup('gringotts') #NOTE(suo): Import services/submodules to register methods # If use `from gringotts.services import *` will cause SynaxWarning, # so we import every submodule implicitly. from gringotts import services for m in services.SUBMODULES: importutils.import_module("gringotts.services.%s" % m) LOG.warn('Loaded resources: %s' % services.RESOURCE_GET_MAP.keys())
def set_middleware_defaults(): """Update default configuration options for oslo.middleware.""" # CORS Defaults # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults(cors.CORS_OPTS, allow_headers=['X-Auth-Token', 'X-Identity-Status', 'X-Roles', 'X-Service-Catalog', 'X-User-Id', 'X-Tenant-Id', 'X-OpenStack-Request-ID', 'X-Trace-Info', 'X-Trace-HMAC', 'OpenStack-API-Version'], expose_headers=['X-Auth-Token', 'X-Subject-Token', 'X-Service-Token', 'X-OpenStack-Request-ID', 'OpenStack-API-Version'], allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'HEAD'] )
def setup_app(pecan_config=None, extra_hooks=None): # FIXME: Replace DBHook with a hooks.TransactionHook app_hooks = [ hooks.ConfigHook(), hooks.DBHook( storage.get_connection_from_config(cfg.CONF, 'metering'), storage.get_connection_from_config(cfg.CONF, 'event'), storage.get_connection_from_config(cfg.CONF, 'alarm'), ), hooks.PipelineHook(), hooks.TranslationHook() ] if extra_hooks: app_hooks.extend(extra_hooks) if not pecan_config: pecan_config = get_pecan_config() pecan.configuration.set_config(dict(pecan_config), overwrite=True) cfg.set_defaults(API_OPTS, pecan_debug=CONF.debug) app = pecan.make_app(pecan_config.app.root, debug=CONF.api.pecan_debug, force_canonical=getattr(pecan_config.app, 'force_canonical', True), hooks=app_hooks, wrap_app=middleware.ParsableErrorMiddleware, guess_content_type_from_ext=False) return app
def set_cors_middleware_defaults(): """Update default configuration options for oslo.middleware.""" # CORS Defaults # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults(cors.CORS_OPTS, allow_headers=['Content-MD5', 'X-Image-Meta-Checksum', 'X-Storage-Token', 'Accept-Encoding', 'X-Auth-Token', 'X-Identity-Status', 'X-Roles', 'X-Service-Catalog', 'X-User-Id', 'X-Tenant-Id', 'X-OpenStack-Request-ID'], expose_headers=['X-Image-Meta-Checksum', 'X-Auth-Token', 'X-Subject-Token', 'X-Service-Token', 'X-OpenStack-Request-ID'], allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'] )
def set_defaults(): from oslo_middleware import cors cfg.set_defaults(cors.CORS_OPTS, allow_headers=[ 'Authorization', 'X-Auth-Token', 'X-Subject-Token', 'X-User-Id', 'X-Domain-Id', 'X-Project-Id', 'X-Roles' ])
def setup_app(pecan_config=None, extra_hooks=None): # FIXME: Replace DBHook with a hooks.TransactionHook app_hooks = [hooks.ConfigHook(), hooks.DBHook( storage.get_connection_from_config(cfg.CONF, 'metering'), storage.get_connection_from_config(cfg.CONF, 'event'), storage.get_connection_from_config(cfg.CONF, 'alarm'),), hooks.PipelineHook(), hooks.TranslationHook()] if extra_hooks: app_hooks.extend(extra_hooks) if not pecan_config: pecan_config = get_pecan_config() pecan.configuration.set_config(dict(pecan_config), overwrite=True) cfg.set_defaults(API_OPTS, pecan_debug=CONF.debug) app = pecan.make_app( pecan_config.app.root, debug=CONF.api.pecan_debug, force_canonical=getattr(pecan_config.app, 'force_canonical', True), hooks=app_hooks, wrap_app=middleware.ParsableErrorMiddleware, guess_content_type_from_ext=False ) return app
def api_app(conf): cfg.CONF(args=[], project='kiloeyes') log_levels = (cfg.CONF.default_log_levels) cfg.set_defaults(log.log_opts, default_log_levels=log_levels) log.setup('kiloeyes') dispatcher_manager = named.NamedExtensionManager( namespace=namespace.DISPATCHER_NS, names=cfg.CONF.dispatcher, invoke_on_load=True, invoke_args=[cfg.CONF]) if not list(dispatcher_manager): LOG.error('Failed to load any dispatchers for %s' % namespace.DISPATCHER_NS) return None # Create the application app = resource_api.ResourceAPI() # add each dispatcher to the application to serve requests offered by # each dispatcher for driver in dispatcher_manager: app.add_route(None, driver.obj) LOG.debug('Dispatcher drivers have been added to the routes!') return app
def set_external_opts_defaults(): """Update default configuration options for oslo.middleware.""" # CORS Defaults # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults(cors.CORS_OPTS, allow_headers=[ 'X-Auth-Token', 'X-Openstack-Request-Id', 'X-Subject-Token', 'X-Project-Id', 'X-Project-Name', 'X-Project-Domain-Id', 'X-Project-Domain-Name', 'X-Domain-Id', 'X-Domain-Name' ], expose_headers=[ 'X-Auth-Token', 'X-Openstack-Request-Id', 'X-Subject-Token' ], allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH']) # configure OSprofiler options profiler.set_defaults(CONF, enabled=False, trace_sqlalchemy=False) # Oslo.cache is always enabled by default for request-local caching # TODO(morganfainberg): Fix this to not use internal interface when # oslo.cache has proper interface to set defaults added. This is # just a bad way to do this. opts = cache._opts.list_opts() for opt_list in opts: if opt_list[0] == 'cache': for o in opt_list[1]: if o.name == 'enabled': o.default = True
def add_auth_options(options, service_type): def add_options(opts, opts_to_add): for new_opt in opts_to_add: for opt in opts: if opt.name == new_opt.name: break else: opts.append(new_opt) opts = copy.deepcopy(options) opts.insert(0, loading.get_auth_common_conf_options()[0]) # NOTE(dims): There are a lot of auth plugins, we just generate # the config options for a few common ones plugins = ['password', 'v2password', 'v3password'] for name in plugins: plugin = loading.get_plugin_loader(name) add_options(opts, loading.get_auth_plugin_conf_options(plugin)) add_options(opts, loading.get_session_conf_options()) adapter_opts = loading.get_adapter_conf_options(include_deprecated=False) cfg.set_defaults(adapter_opts, service_type=service_type, valid_interfaces=DEFAULT_VALID_INTERFACES) add_options(opts, adapter_opts) opts.sort(key=lambda x: x.name) return opts
def list_opts(): def add_options(opts, opts_to_add): for new_opt in opts_to_add: for opt in opts: if opt.name == new_opt.name: break else: opts.append(new_opt) opts_copy = copy.deepcopy(opts) opts_copy.insert(0, loading.get_auth_common_conf_options()[0]) plugins = ['password', 'v2password', 'v3password'] for name in plugins: plugin = loading.get_plugin_loader(name) add_options(opts_copy, loading.get_auth_plugin_conf_options(plugin)) add_options(opts_copy, loading.get_session_conf_options()) adapter_opts = loading.get_adapter_conf_options(include_deprecated=False) # adding defaults for valid interfaces cfg.set_defaults(adapter_opts, service_type='identity', valid_interfaces=['internal', 'public']) add_options(opts_copy, adapter_opts) opts_copy.sort(key=lambda x: x.name) return opts_copy
def set_cors_middleware_defaults(): """Update default configuration options for oslo.middleware.""" # CORS Defaults # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults(cors.CORS_OPTS, allow_headers=['X-Auth-Token', 'X-OpenStack-Request-ID'], expose_headers=['X-OpenStack-Request-ID'], allow_methods=['GET', 'POST'])
def prepare_service(argv=None): log_levels = (cfg.CONF.default_log_levels + ['stevedore=INFO', 'keystoneclient=INFO']) cfg.set_defaults(log.log_opts, default_log_levels=log_levels) if argv is None: argv = sys.argv cfg.CONF(argv[1:], project='ceilometer', validate_default_values=True) log.setup('ceilometer')
def set_defaults(): cfg.set_defaults(cors.CORS_OPTS, allow_headers=[ 'X-Auth-Token', 'X-Subject-Token', 'X-User-Id', 'X-Domain-Id', 'X-Project-Id', 'X-Roles'])
def test_set_defaults_func(self): cfg.set_defaults([self.normal_opt], normal_opt=self.id()) self.conf([]) loc = self.conf.get_location('normal_opt') self.assertEqual( cfg.Locations.set_default, loc.location, ) self.assertIn('test_get_location.py', loc.detail)
def get_ksa_adapter_opts(default_service_type, deprecated_opts=None): opts = ks_loading.get_adapter_conf_options(include_deprecated=False, deprecated_opts=deprecated_opts) cfg.set_defaults(opts, valid_interfaces=['internal', 'public'], service_type=default_service_type) return opts
def set_defaults(): """Set all oslo.config default overrides for cue.""" # CORS Defaults # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults( cors.CORS_OPTS, allow_headers=['X-Auth-Token', 'X-Server-Management-Url'], expose_headers=['X-Auth-Token', 'X-Server-Management-Url'], allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'])
def prepare_service(argv=[]): cfg.set_defaults(logging.log_opts, default_log_levels=['amqplib=WARN', 'qpid.messaging=INFO', 'stevedore=INFO', 'eventlet.wsgi.server=WARN' ]) cfg.CONF(argv[1:], project='climate') logging.setup('climate')
def prepare_service(argv=[]): options.set_defaults(sql_connection=_DEFAULT_SQL_CONNECTION, sqlite_db='kite.sqlite') cfg.set_defaults(log.log_opts, default_log_levels=['sqlalchemy=WARN', 'eventlet.wsgi.server=WARN' ]) parse_args(argv) log.setup('kite')
def set_defaults(logging_context_format_string=None, default_log_levels=None): # Just in case the caller is not setting the # default_log_level. This is insurance because # we introduced the default_log_level parameter # later in a backwards in-compatible change if default_log_levels is not None: cfg.set_defaults(log_opts, default_log_levels=default_log_levels) if logging_context_format_string is not None: cfg.set_defaults(log_opts, logging_context_format_string=logging_context_format_string)
def setup_app(pecan_config=None): if not pecan_config: pecan_config = get_pecan_config() # Setup logging cfg.set_defaults(_options.log_opts, default_log_levels=[ 'storyboard=INFO', 'storyboard.openstack.common.db=WARN', 'sqlalchemy=WARN' ]) log.setup(CONF, 'storyboard') hooks = [ session_hook.DBSessionHook(), user_id_hook.UserIdHook(), validation_hook.ValidationHook() ] # Setup search engine search_engine_name = CONF.search_engine search_engine_cls = search_engine_impls.ENGINE_IMPLS[search_engine_name] search_engine.set_engine(search_engine_cls()) # Load user preference plugins initialize_user_preferences() # Initialize scheduler initialize_scheduler() # Setup notifier if CONF.enable_notifications: hooks.append(NotificationHook()) app = pecan.make_app( pecan_config.app.root, debug=CONF.debug, hooks=hooks, force_canonical=getattr(pecan_config.app, 'force_canonical', True), guess_content_type_from_ext=False ) app = token_middleware.AuthTokenMiddleware(app) # Setup CORS if CONF.cors.allowed_origins: app = CORSMiddleware(app, allowed_origins=CONF.cors.allowed_origins, allowed_methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowed_headers=['origin', 'authorization', 'accept', 'x-total', 'x-limit', 'x-marker', 'x-client', 'content-type'], max_age=CONF.cors.max_age) return app
def setup_app(pecan_config=None): if not pecan_config: pecan_config = get_pecan_config() # Setup logging cfg.set_defaults(_options.log_opts, default_log_levels=[ 'storyboard=INFO', 'storyboard.openstack.common.db=WARN', 'sqlalchemy=WARN' ]) log.setup(CONF, 'storyboard') hooks = [ session_hook.DBSessionHook(), user_id_hook.UserIdHook(), validation_hook.ValidationHook() ] # Setup search engine search_engine_name = CONF.search_engine search_engine_cls = search_engine_impls.ENGINE_IMPLS[search_engine_name] search_engine.set_engine(search_engine_cls()) # Load user preference plugins initialize_user_preferences() # Initialize scheduler initialize_scheduler() # Setup notifier if CONF.enable_notifications: hooks.append(NotificationHook()) app = pecan.make_app(pecan_config.app.root, debug=CONF.debug, hooks=hooks, force_canonical=getattr(pecan_config.app, 'force_canonical', True), guess_content_type_from_ext=False) app = token_middleware.AuthTokenMiddleware(app) # Setup CORS if CONF.cors.allowed_origins: app = CORSMiddleware( app, allowed_origins=CONF.cors.allowed_origins, allowed_methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowed_headers=[ 'origin', 'authorization', 'accept', 'x-total', 'x-limit', 'x-marker', 'x-client', 'content-type' ], max_age=CONF.cors.max_age) return app
def prepare_service(argv=None): gettextutils.install('kiloeyes') gettextutils.enable_lazy() log_levels = (cfg.CONF.default_log_levels) cfg.set_defaults(log.log_opts, default_log_levels=log_levels) if argv is None: argv = sys.argv cfg.CONF(argv[1:], project='kiloeyes') log.setup('kiloeyes') LOG.info('Service has started!')
def set_defaults(logging_context_format_string=None, default_log_levels=None): """Set default values for the configuration options used by oslo.log.""" # Just in case the caller is not setting the # default_log_level. This is insurance because # we introduced the default_log_level parameter # later in a backwards in-compatible change if default_log_levels is not None: cfg.set_defaults(_options.log_opts, default_log_levels=default_log_levels) if logging_context_format_string is not None: cfg.set_defaults(_options.log_opts, logging_context_format_string=logging_context_format_string)
def set_cors_middleware_defaults(): """Update default configuration options for oslo.middleware.""" # CORS Defaults # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ # TODO(jdandrea): Adjust allow/expose headers for Conductor vs OpenStack cfg.set_defaults( cors.CORS_OPTS, allow_headers=['X-Auth-Token', 'X-Conductor-Request-Id'], expose_headers=['X-Auth-Token', 'X-Conductor-Request-Id'], allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS', 'HEAD'])
def setup_config_and_logging(argv=(), conf=cfg.CONF): """register logging config options and parse commandline arguments""" log.register_options(conf) parse_args(argv) # Set log levels for external libraries cfg.set_defaults(_options.log_opts, default_log_levels=_DEFAULT_LOG_LEVELS) log.setup(conf, 'radloggerpy') # Write all configuration options and values to log conf.log_opt_values(LOG, log.DEBUG)
def prepare_service(argv=None): i18n.enable_lazy() log_levels = (cfg.CONF.default_log_levels + ['stevedore=INFO', 'keystoneclient=INFO']) cfg.set_defaults(log.log_opts, default_log_levels=log_levels) if argv is None: argv = sys.argv cfg.CONF(argv[1:], project='ceilometer', validate_default_values=True) log.setup('ceilometer') messaging.setup()
def prepare_service(argv=[]): rpc.set_defaults(control_exchange='sysinv') cfg.set_defaults(log.log_opts, default_log_levels=[ 'amqplib=WARN', 'qpid.messaging=INFO', 'sqlalchemy=WARN', 'keystoneclient=INFO', 'stevedore=INFO', 'eventlet.wsgi.server=WARN' ]) cfg.CONF(argv[1:], project='sysinv') log.setup('sysinv')
def set_defaults(): from oslo_middleware import cors cfg.set_defaults(cors.CORS_OPTS, allow_headers=[ 'Authorization', 'X-Auth-Token', 'X-Subject-Token', 'X-User-Id', 'X-Domain-Id', 'X-Project-Id', 'X-Roles'])
def set_cors_middleware_defaults(): """Update default configuration options for oslo.middleware.""" # CORS Defaults # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults(cors.CORS_OPTS, allow_headers=['X-Auth-Token', 'X-OpenStack-Request-ID'], expose_headers=['X-OpenStack-Request-ID'], allow_methods=['GET', 'POST'] )
def prepare_service(argv=(), conf=cfg.CONF): log.register_options(conf) gmr_opts.set_defaults(conf) config.parse_args(argv) cfg.set_defaults(_options.log_opts, default_log_levels=_DEFAULT_LOG_LEVELS) log.setup(conf, 'python-watcher') conf.log_opt_values(LOG, logging.DEBUG) gmr.TextGuruMeditation.register_section(_('Plugins'), opts.show_plugins) gmr.TextGuruMeditation.setup_autorun(version, conf=conf)
def set_defaults(logging_context_format_string=None, default_log_levels=None): # Just in case the caller is not setting the # default_log_level. This is insurance because # we introduced the default_log_level parameter # later in a backwards in-compatible change if default_log_levels is not None: cfg.set_defaults(log_opts, default_log_levels=default_log_levels) if logging_context_format_string is not None: cfg.set_defaults( log_opts, logging_context_format_string=logging_context_format_string)
def set_cors_middleware_defaults(): """Update default configuration options for oslo.middleware.""" # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults(cors.CORS_OPTS, allow_headers=[ 'X-Auth-Token', MIN_VERSION_HEADER, MAX_VERSION_HEADER, VERSION_HEADER ], allow_methods=[ 'GET', 'POST', 'PUT', 'HEAD', 'PATCH', 'DELETE', 'OPTIONS' ])
def _init_conf(self): '''Initialize this middleware from an oslo.config instance.''' # Set up a location for our latent configuration options self._latent_configuration = { 'allow_headers': [], 'expose_headers': [], 'methods': [] } # First, check the configuration and register global options. self.oslo_conf.register_opts(CORS_OPTS, 'cors') allowed_origin = self._conf_get('allowed_origin', 'cors') allow_credentials = self._conf_get('allow_credentials', 'cors') expose_headers = self._conf_get('expose_headers', 'cors') max_age = self._conf_get('max_age', 'cors') allow_methods = self._conf_get('allow_methods', 'cors') allow_headers = self._conf_get('allow_headers', 'cors') # Clone our original CORS_OPTS, and set the defaults to whatever is # set in the global conf instance. This is done explicitly (instead # of **kwargs), since we don't accidentally want to catch # allowed_origin. subgroup_opts = copy.deepcopy(CORS_OPTS) cfg.set_defaults(subgroup_opts, allow_credentials=allow_credentials, expose_headers=expose_headers, max_age=max_age, allow_methods=allow_methods, allow_headers=allow_headers) # If the default configuration contains an allowed_origin, don't # forget to register that. self.add_origin(allowed_origin=allowed_origin, allow_credentials=allow_credentials, expose_headers=expose_headers, max_age=max_age, allow_methods=allow_methods, allow_headers=allow_headers) # Iterate through all the loaded config sections, looking for ones # prefixed with 'cors.' for section in self.oslo_conf.list_all_sections(): if section.startswith('cors.'): debtcollector.deprecate('Multiple configuration blocks are ' 'deprecated and will be removed in ' 'future versions. Please consolidate ' 'your configuration in the [cors] ' 'configuration block.') # Register with the preconstructed defaults self.oslo_conf.register_opts(subgroup_opts, section) self.add_origin(**self.oslo_conf[section])
def tempest_set_log_file(filename): """Provide an API for tempest to set the logging filename. .. warning:: Only Tempest should use this function. We don't want applications to set a default log file, so we don't want this in set_defaults(). Because tempest doesn't use a configuration file we don't have another convenient way to safely set the log file default. """ cfg.set_defaults(_options.logging_cli_opts, log_file=filename)
def prepare_service(argv=(), conf=cfg.CONF): log.register_options(conf) gmr_opts.set_defaults(conf) config.parse_args(argv) cfg.set_defaults(_options.log_opts, default_log_levels=_DEFAULT_LOG_LEVELS) log.setup(conf, 'python-watcher') conf.log_opt_values(LOG, logging.DEBUG) gmr.TextGuruMeditation.register_section(_('Plugins'), opts.show_plugins) gmr.TextGuruMeditation.setup_autorun(version)
def prepare_service(argv=[]): config.parse_args(default_config_files=cfg.find_config_files( project='eon')) cfg.set_defaults(log.log_opts, default_log_levels=[ 'amqplib=WARN', 'qpid.messaging=INFO', 'sqlalchemy=WARN', 'keystoneclient=INFO', 'stevedore=INFO', 'eventlet.wsgi.server=WARN', 'iso8601=WARN' ]) cfg.CONF(argv[1:], project='eon') log.setup('eon')
def set_cors_middleware_defaults(): """Update default configuration options for oslo.middleware.""" # TODO(krotscheck): Update with https://review.openstack.org/#/c/285368/ cfg.set_defaults( cors.CORS_OPTS, allow_headers=['X-Auth-Token', MIN_VERSION_HEADER, MAX_VERSION_HEADER, VERSION_HEADER], allow_methods=['GET', 'POST', 'PUT', 'HEAD', 'PATCH', 'DELETE', 'OPTIONS'] )
def prepare_service(argv=[]): cfg.set_defaults(log.log_opts, default_log_levels=['amqp=WARN', 'amqplib=WARN', 'qpid.messaging=INFO', 'sqlalchemy=WARN', 'keystoneclient=INFO', 'stevedore=INFO', 'eventlet.wsgi.server=WARN', 'iso8601=WARN' ]) cfg.CONF(argv[1:], project='tuskar') log.setup('tuskar')
def main(argv=["--config-file", "/etc/monasca/anomaly-engine.yaml"]): log_levels = cfg.CONF.default_log_levels cfg.set_defaults(log.log_opts, default_log_levels=log_levels) cfg.CONF(["--config-file", "/etc/monasca/anomaly-engine.yaml"], project="monasca-anomaly") log.setup("monasca-anomaly") for instance in cfg.CONF.rde.instances: # get instance config instance_opts = [ cfg.StrOpt("kafka_group"), cfg.BoolOpt("normalized"), cfg.BoolOpt("ad3"), cfg.FloatOpt("anom_threshold"), cfg.FloatOpt("normal_threshold"), cfg.IntOpt("fault_ittr"), cfg.IntOpt("normal_ittr"), cfg.StrOpt("sample_name"), cfg.ListOpt("dimension_match"), cfg.ListOpt("sample_metrics"), ] instance_group = cfg.OptGroup(name=instance, title=instance) cfg.CONF.register_group(instance_group) cfg.CONF.register_opts(instance_opts, instance_group) # start and add to processors rde_anomaly_processor = multiprocessing.Process(target=RDEAnomalyProcessor(instance).run) processors.append(rde_anomaly_processor) # nupic_anomaly_processor = multiprocessing.Process(target=NupicAnomalyProcessor().run) # processors.append(nupic_anomaly_processor) # ks_anomaly_processor = multiprocessing.Process(target=KsAnomalyProcessor().run) # processors.append(ks_anomaly_processor) try: LOG.info("Starting processes") for process in processors: process.start() # The signal handlers must be added after the processes start otherwise they run on all processes signal.signal(signal.SIGCHLD, clean_exit) signal.signal(signal.SIGINT, clean_exit) signal.signal(signal.SIGTERM, clean_exit) while True: time.sleep(5) except Exception: LOG.exception("Error! Exiting.") for process in processors: process.terminate()
def setup(): oslo_messaging.set_transport_defaults('ceilometer') # NOTE(sileht): When batch is not enabled, oslo.messaging read all messages # in the queue and can consume a lot of memory, that works for rpc because # you never have a lot of message, but sucks for notification. The # default is not changeable on oslo.messaging side. And we can't expose # this option to set set_transport_defaults because it a driver option. # 100 allow to prefetch a lot of messages but limit memory to 1G per # workers in worst case (~ 1M Nova notification) # And even driver options are located in private module, this is not going # to break soon. cfg.set_defaults( impl_rabbit.rabbit_opts, rabbit_qos_prefetch_count=100, )