Merge "Support for directory source of config files"
This commit is contained in:
commit
90609a35fc
@ -79,7 +79,7 @@ Turns on the DEBUG level in logging.
|
||||
|
||||
* ``--config-file=PATH``
|
||||
|
||||
Optional. Default: ``None``
|
||||
Optional. Default: See below for default search order.
|
||||
|
||||
Specified on the command line only.
|
||||
|
||||
@ -98,6 +98,35 @@ The filename that is searched for depends on the server application name. So,
|
||||
if you are starting up the API server, ``glance-api.conf`` is searched for,
|
||||
otherwise ``glance-registry.conf``.
|
||||
|
||||
* ``--config-dir=DIR``
|
||||
|
||||
Optional. Default: ``None``
|
||||
|
||||
Specified on the command line only.
|
||||
|
||||
Takes a path to a configuration directory from which all *.conf fragments
|
||||
are loaded. This provides an alternative to multiple --config-file options
|
||||
when it is inconvenient to explicitly enumerate all the config files, for
|
||||
example when an unknown number of config fragments are being generated
|
||||
by a deployment framework.
|
||||
|
||||
If --config-dir is set, then --config-file is ignored.
|
||||
|
||||
An example usage would be:
|
||||
|
||||
$ glance-api --config-dir=/etc/glance/glance-api.d
|
||||
|
||||
$ ls /etc/glance/glance-api.d
|
||||
00-core.conf
|
||||
01-s3.conf
|
||||
02-swift.conf
|
||||
03-ssl.conf
|
||||
... etc.
|
||||
|
||||
The numeric prefixes in the example above are only necessary if a specific
|
||||
parse ordering is required (i.e. if an individual config option set in an
|
||||
earlier fragment is overridden in a later fragment).
|
||||
|
||||
Configuring Server Startup Options
|
||||
----------------------------------
|
||||
|
||||
|
@ -125,6 +125,17 @@ def _get_deployment_flavor(conf):
|
||||
return '' if not flavor else ('-' + flavor)
|
||||
|
||||
|
||||
def _get_paste_config_path(conf):
|
||||
paste_suffix = '-paste.ini'
|
||||
conf_suffix = '.conf'
|
||||
if conf.config_dir:
|
||||
return os.path.join(conf.config_dir, conf.prog + paste_suffix)
|
||||
else:
|
||||
# Assume paste config is in a paste.ini file corresponding
|
||||
# to the last config file
|
||||
return conf.config_file[-1].replace(conf_suffix, paste_suffix)
|
||||
|
||||
|
||||
def _get_deployment_config_file(conf):
|
||||
"""
|
||||
Retrieve the deployment_config_file config item, formatted as an
|
||||
@ -134,12 +145,7 @@ def _get_deployment_config_file(conf):
|
||||
"""
|
||||
_register_paste_deploy_opts(conf)
|
||||
config_file = conf.paste_deploy.config_file
|
||||
if not config_file:
|
||||
# Assume paste config is in a paste.ini file corresponding
|
||||
# to the last config file
|
||||
path = conf.config_file[-1].replace(".conf", "-paste.ini")
|
||||
else:
|
||||
path = config_file
|
||||
path = _get_paste_config_path(conf) if not config_file else config_file
|
||||
return os.path.abspath(path)
|
||||
|
||||
|
||||
|
@ -90,16 +90,21 @@ the purposes of --help and CLI arg validation)::
|
||||
def add_common_opts(conf):
|
||||
conf.register_cli_opts(cli_opts)
|
||||
|
||||
The config manager has a single CLI option defined by default, --config-file::
|
||||
The config manager has two CLI options defined by default, --config-file
|
||||
and --config-dir::
|
||||
|
||||
class ConfigOpts(object):
|
||||
|
||||
config_file_opt = MultiStrOpt('config-file',
|
||||
...
|
||||
|
||||
def __init__(self, ...):
|
||||
...
|
||||
self.register_cli_opt(self.config_file_opt)
|
||||
|
||||
opts = [
|
||||
MultiStrOpt('config-file',
|
||||
...),
|
||||
StrOpt('config-dir',
|
||||
...),
|
||||
]
|
||||
|
||||
self.register_cli_opts(opts)
|
||||
|
||||
Option values are parsed from any supplied config files using
|
||||
openstack.common.iniparser. If none are specified, a default set is used
|
||||
@ -221,6 +226,7 @@ log files:
|
||||
|
||||
import collections
|
||||
import copy
|
||||
import glob
|
||||
import functools
|
||||
import optparse
|
||||
import os
|
||||
@ -826,14 +832,26 @@ class ConfigOpts(collections.Mapping):
|
||||
|
||||
self.__cache = {}
|
||||
|
||||
self.register_cli_opt(
|
||||
MultiStrOpt('config-file',
|
||||
default=self.default_config_files,
|
||||
metavar='PATH',
|
||||
help='Path to a config file to use. Multiple config '
|
||||
'files can be specified, with values in later '
|
||||
'files taking precedence. The default files used '
|
||||
'are: %s' % (self.default_config_files, )))
|
||||
opts = [
|
||||
MultiStrOpt('config-file',
|
||||
default=self.default_config_files,
|
||||
metavar='PATH',
|
||||
help='Path to a config file to use. Multiple config '
|
||||
'files can be specified, with values in later '
|
||||
'files taking precedence. The default files '
|
||||
' used are: %s' %
|
||||
(self.default_config_files, )),
|
||||
StrOpt('config-dir',
|
||||
metavar='DIR',
|
||||
help='Path to a config directory to pull *.conf '
|
||||
'files from. This file set is sorted, so as to '
|
||||
'provide a predictable parse order if individual '
|
||||
'options are over-ridden. The set is parsed after '
|
||||
'the file(s), if any, specified via --config-file, '
|
||||
'hence over-ridden options in the directory take '
|
||||
'precedence.'),
|
||||
]
|
||||
self.register_cli_opts(opts)
|
||||
|
||||
def __clear_cache(f):
|
||||
@functools.wraps(f)
|
||||
@ -854,6 +872,10 @@ class ConfigOpts(collections.Mapping):
|
||||
The object may be called multiple times, each time causing the previous
|
||||
set of values to be overwritten.
|
||||
|
||||
If the --config-dir option is set, any *.conf files from this
|
||||
directory are pulled in, after all the file(s) specified by the
|
||||
--config-file option.
|
||||
|
||||
:params args: command line arguments (defaults to sys.argv[1:])
|
||||
:returns: the list of arguments left over after parsing options
|
||||
:raises: SystemExit, ConfigFilesNotFoundError, ConfigFileParseError
|
||||
@ -866,8 +888,14 @@ class ConfigOpts(collections.Mapping):
|
||||
|
||||
self._cli_values = vars(values)
|
||||
|
||||
if self.config_file:
|
||||
self._parse_config_files(self.config_file)
|
||||
def _list_config_dir():
|
||||
return sorted(glob.glob(os.path.join(self.config_dir, '*.conf')))
|
||||
|
||||
from_file = list(self.config_file)
|
||||
|
||||
from_dir = _list_config_dir() if self.config_dir else []
|
||||
|
||||
self._parse_config_files(from_file + from_dir)
|
||||
|
||||
return args
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user