9271654adf
More specifically uses global CONF for the quantum.conf file. Added support for the RYU plugin (similar to ovs and lb, which use non-global conf for plugins) patch 27: clean up find_config_file patch 28: for config file use old paths (plugin unit tests) this hopefully will be replaced when we move to common config file patch 30: rebase and merge (utils.py and policy.py) Change-Id: Ic0bf5bdd44f24a557240f7afe4e070dee448c63c
120 lines
3.6 KiB
Python
120 lines
3.6 KiB
Python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Copyright 2011 Nicira Networks, Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
"""
|
|
Routines for configuring Quantum
|
|
"""
|
|
|
|
import logging
|
|
import logging.handlers
|
|
import os
|
|
import sys
|
|
|
|
from paste import deploy
|
|
|
|
from quantum.openstack.common import cfg
|
|
from quantum.version import version_string
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
bind_opts = [
|
|
cfg.StrOpt('bind_host', default='0.0.0.0'),
|
|
cfg.IntOpt('bind_port', default=9696),
|
|
cfg.StrOpt('api_extensions_path', default=""),
|
|
cfg.StrOpt('core_plugin',
|
|
default='quantum.plugins.sample.SamplePlugin.FakePlugin'),
|
|
]
|
|
|
|
# Register the configuration options
|
|
cfg.CONF.register_opts(bind_opts)
|
|
|
|
|
|
def parse(args):
|
|
cfg.CONF(args=args, project='quantum',
|
|
version='%%prog %s' % version_string())
|
|
|
|
|
|
def setup_logging(conf):
|
|
"""
|
|
Sets up the logging options for a log with supplied name
|
|
|
|
:param conf: a cfg.ConfOpts object
|
|
"""
|
|
|
|
if conf.log_config:
|
|
# Use a logging configuration file for all settings...
|
|
if os.path.exists(conf.log_config):
|
|
logging.config.fileConfig(conf.log_config)
|
|
return
|
|
else:
|
|
raise RuntimeError("Unable to locate specified logging "
|
|
"config file: %s" % conf.log_config)
|
|
|
|
root_logger = logging.root
|
|
if conf.debug:
|
|
root_logger.setLevel(logging.DEBUG)
|
|
elif conf.verbose:
|
|
root_logger.setLevel(logging.INFO)
|
|
else:
|
|
root_logger.setLevel(logging.WARNING)
|
|
|
|
formatter = logging.Formatter(conf.log_format, conf.log_date_format)
|
|
|
|
if conf.use_syslog:
|
|
try:
|
|
facility = getattr(logging.handlers.SysLogHandler,
|
|
conf.syslog_log_facility)
|
|
except AttributeError:
|
|
raise ValueError(_("Invalid syslog facility"))
|
|
|
|
handler = logging.handlers.SysLogHandler(address='/dev/log',
|
|
facility=facility)
|
|
elif conf.log_file:
|
|
logfile = conf.log_file
|
|
if conf.log_dir:
|
|
logfile = os.path.join(conf.log_dir, logfile)
|
|
handler = logging.handlers.WatchedFileHandler(logfile)
|
|
else:
|
|
handler = logging.StreamHandler(sys.stdout)
|
|
|
|
handler.setFormatter(formatter)
|
|
root_logger.addHandler(handler)
|
|
|
|
|
|
def load_paste_app(app_name, config_file):
|
|
"""
|
|
Builds and returns a WSGI app from a paste config file.
|
|
|
|
:param app_name: Name of the application to load
|
|
:param config_file: name of the configuration file
|
|
:raises RuntimeError when config file cannot be located or application
|
|
cannot be loaded from config file
|
|
"""
|
|
|
|
config_path = os.path.abspath(cfg.CONF.find_file(config_file))
|
|
LOG.info("Config paste file: %s", config_path)
|
|
|
|
try:
|
|
app = deploy.loadapp("config:%s" % config_path, name=app_name)
|
|
except (LookupError, ImportError):
|
|
msg = ("Unable to load %(app_name)s from "
|
|
"configuration file %(config_path)s.") % locals()
|
|
LOG.exception(msg)
|
|
raise RuntimeError(msg)
|
|
return app
|