
Iec6b3c56d464d26e4f1fc143e6a7804add67a35d I3f2d3a12fcb53759a906fcbae6fae768833d325e I566811521da16055a73c73052ffcd497aaa8e475 I2ee04b6d5aaa26d49243cf7e0b6045026f052625 I329620f3c8aa7e7f1bdd658cbaa8ea20d9aa4ba5 I5ff3d9146b4fbec74d8d65de84d7ab61d869725c Ib38fd52811812170bdd9bf9df90a66f1a2e6c8d9 I64ce3efaec6df2e402ca2acf6a3cf1a6f2bb1909 I66c3659ab0f33772d7a51c8961a37e32c65354c2 I29ce4a6ef165daa0fe60003301a0d807fd1cce42 Ibd2a4f55e2a64d9a992833200a791dbb20c41eca I16133a213ef25a1b374f10fa80cd5a03d1f40753 Ie09f32fcacfe70f436cad71e5749edf94be038ed Iaba6a6bf07ff223e41f705f0f1db5688a5290f5c I64a0474ecfe5ea38393fe681d520a7b6ce00d959 I270b3ce5ef776522a62d9622b36f0d6b50b9cc57 Ic5f6849ea166bb0295f84685b0a2b5c4701f972a I51190cb02255254a888f66404ecdc3dfc5be0386 I0c2180c603cd09e29d4e6c5e592b987e2b447972 Iae1cdbeb7fa3e49c2cb5cac7c92eceffef477e7e I6c643f58aada0a8525711bc452d0c581625f3d26 I9c4f999b1b3006b8ae5f18a030d5b30c7e85e03b I32eaad36edcb889b448c45ba36f4e97f7c87d1e5 I8c91c40a922690b475aac1c0a3b2c0c28274b130 I574fd1dbeea58dbf41f77d295dc03c23d2feaf96 Change-Id: I0ffb3c38c0c1b3aafa8617364e22036c47aaef76
225 lines
7.0 KiB
Python
225 lines
7.0 KiB
Python
# Copyright 2011 OpenStack LLC.
|
|
# 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 Glance
|
|
"""
|
|
|
|
import logging
|
|
import logging.config
|
|
import logging.handlers
|
|
import os
|
|
import sys
|
|
|
|
from oslo.config import cfg
|
|
from paste import deploy
|
|
|
|
from muranoconductor import __version__ as version
|
|
from ConfigParser import SafeConfigParser
|
|
|
|
paste_deploy_opts = [
|
|
cfg.StrOpt('flavor'),
|
|
cfg.StrOpt('config_file'),
|
|
]
|
|
|
|
rabbit_opts = [
|
|
cfg.StrOpt('host', default='localhost'),
|
|
cfg.IntOpt('port', default=5672),
|
|
cfg.StrOpt('login', default='guest'),
|
|
cfg.StrOpt('password', default='guest'),
|
|
cfg.StrOpt('virtual_host', default='/'),
|
|
cfg.BoolOpt('ssl', default=False),
|
|
cfg.StrOpt('ca_certs', default='')
|
|
]
|
|
|
|
heat_opts = [
|
|
cfg.BoolOpt('insecure', default=False),
|
|
cfg.StrOpt('ca_file'),
|
|
cfg.StrOpt('cert_file'),
|
|
cfg.StrOpt('key_file'),
|
|
cfg.StrOpt('endpoint_type', default='publicURL')
|
|
]
|
|
|
|
keystone_opts = [
|
|
cfg.StrOpt('auth_url'),
|
|
cfg.BoolOpt('insecure', default=False),
|
|
cfg.StrOpt('ca_file'),
|
|
cfg.StrOpt('cert_file'),
|
|
cfg.StrOpt('key_file')
|
|
]
|
|
|
|
CONF = cfg.CONF
|
|
CONF.register_opts(paste_deploy_opts, group='paste_deploy')
|
|
CONF.register_opts(rabbit_opts, group='rabbitmq')
|
|
CONF.register_opts(heat_opts, group='heat')
|
|
CONF.register_opts(keystone_opts, group='keystone')
|
|
CONF.register_opt(cfg.StrOpt('file_server'))
|
|
CONF.register_cli_opt(cfg.StrOpt('data_dir', default='./'))
|
|
|
|
CONF.register_opt(cfg.IntOpt('max_environments', default=20))
|
|
|
|
|
|
CONF.import_opt('verbose', 'muranoconductor.openstack.common.log')
|
|
CONF.import_opt('debug', 'muranoconductor.openstack.common.log')
|
|
CONF.import_opt('log_dir', 'muranoconductor.openstack.common.log')
|
|
CONF.import_opt('log_file', 'muranoconductor.openstack.common.log')
|
|
CONF.import_opt('log_config', 'muranoconductor.openstack.common.log')
|
|
CONF.import_opt('log_format', 'muranoconductor.openstack.common.log')
|
|
CONF.import_opt('log_date_format', 'muranoconductor.openstack.common.log')
|
|
CONF.import_opt('use_syslog', 'muranoconductor.openstack.common.log')
|
|
CONF.import_opt('syslog_log_facility', 'muranoconductor.openstack.common.log')
|
|
|
|
|
|
def parse_args(args=None, usage=None, default_config_files=None):
|
|
CONF(args=args,
|
|
project='conductor',
|
|
version=version,
|
|
usage=usage,
|
|
default_config_files=default_config_files)
|
|
|
|
|
|
def setup_logging():
|
|
"""
|
|
Sets up the logging options for a log with supplied name
|
|
"""
|
|
|
|
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 _get_deployment_flavor():
|
|
"""
|
|
Retrieve the paste_deploy.flavor config item, formatted appropriately
|
|
for appending to the application name.
|
|
"""
|
|
flavor = CONF.paste_deploy.flavor
|
|
return '' if not flavor else ('-' + flavor)
|
|
|
|
|
|
def _get_paste_config_path():
|
|
paste_suffix = '-paste.ini'
|
|
conf_suffix = '.conf'
|
|
if CONF.config_file:
|
|
# Assume paste config is in a paste.ini file corresponding
|
|
# to the last config file
|
|
path = CONF.config_file[-1].replace(conf_suffix, paste_suffix)
|
|
else:
|
|
path = CONF.prog + '-paste.ini'
|
|
return CONF.find_file(os.path.basename(path))
|
|
|
|
|
|
def _get_deployment_config_file():
|
|
"""
|
|
Retrieve the deployment_config_file config item, formatted as an
|
|
absolute pathname.
|
|
"""
|
|
path = CONF.paste_deploy.config_file
|
|
if not path:
|
|
path = _get_paste_config_path()
|
|
if not path:
|
|
msg = "Unable to locate paste config file for %s." % CONF.prog
|
|
raise RuntimeError(msg)
|
|
return os.path.abspath(path)
|
|
|
|
|
|
def load_paste_app(app_name=None):
|
|
"""
|
|
Builds and returns a WSGI app from a paste config file.
|
|
|
|
We assume the last config file specified in the supplied ConfigOpts
|
|
object is the paste config file.
|
|
|
|
:param app_name: name of the application to load
|
|
|
|
:raises RuntimeError when config file cannot be located or application
|
|
cannot be loaded from config file
|
|
"""
|
|
if app_name is None:
|
|
app_name = CONF.prog
|
|
|
|
# append the deployment flavor to the application name,
|
|
# in order to identify the appropriate paste pipeline
|
|
app_name += _get_deployment_flavor()
|
|
|
|
conf_file = _get_deployment_config_file()
|
|
|
|
try:
|
|
logger = logging.getLogger(__name__)
|
|
logger.debug(_("Loading %(app_name)s from %(conf_file)s"),
|
|
{'conf_file': conf_file, 'app_name': app_name})
|
|
|
|
app = deploy.loadapp("config:%s" % conf_file, name=app_name)
|
|
|
|
# Log the options used when starting if we're in debug mode...
|
|
if CONF.debug:
|
|
CONF.log_opt_values(logger, logging.DEBUG)
|
|
|
|
return app
|
|
except (LookupError, ImportError), e:
|
|
msg = _("Unable to load %(app_name)s from "
|
|
"configuration file %(conf_file)s."
|
|
"\nGot: %(e)r") % locals()
|
|
logger.error(msg)
|
|
raise RuntimeError(msg)
|
|
|
|
|
|
class Config(object):
|
|
def get_setting(self, section, name, default=None):
|
|
group = CONF
|
|
if section and section != 'DEFAULT':
|
|
group = group.get(section, default)
|
|
return group.get(name, default)
|
|
|
|
def __getitem__(self, item):
|
|
parts = item.rsplit('.', 1)
|
|
return self.get_setting(
|
|
parts[0] if len(parts) == 2 else 'DEFAULT', parts[-1])
|