[PYTHON] oslo.config config file search path

Oslo.config developed and used for easy operation around configuration files in OpenStack.

If you do not specify the configuration file to refer to in the cli option, it will search the configuration file with the specified file name from the specified folder.

The folders are first referenced in the following order. (https://github.com/openstack/oslo.config/blob/2.5.0/oslo_config/cfg.py#L498 _get_config_dirs function)

  1. ~/.${project}/
  2. ~/
  3. /etc/${project}/
  4. /etc/

${project}Is the value specified at initialization. If you specify as follows, it will be searched from `~ / .foo /` etc.

from oslo.config import cfg

def init_oslo_config():
    cfg.CONF(project='foo')

The file name is searched for the following. (https://github.com/openstack/oslo.config/blob/2.5.0/oslo_config/cfg.py#L542 find_config_files function)

${project}Is the same as above${prog}This is also specified at the time of initialization.

from oslo.config import cfg

def init_oslo_config():
    cfg.CONF(project='foo', prog='bar')

However, if prog is not specified at initialization, the process name (os.path.basename (sys.argv [0]) `` `) will be $ {prog} ```. ..

The rules of reference are

For example, if `$ {project}` is * foo *, $ {prog} ``` is * bar * and the file exists as below, it will be referred to as the configuration file `/etc/foo/foo.conf`, `~ / bar.conf`.

This behavior can be confirmed as follows, so try it when an unexpected configuration file is referenced.

from oslo.config import cfg
print cfg.find_config_files('foo', 'bar')

If the same option is specified in the referenced configuration file, `$ {prog}` takes precedence. This is because the config file that is loaded is second-come-first-served and is referenced in the order `$ {project}`, `$ {prog}`.

However, these files will not be used if at least one `--config-file` is specified as a parameter at process startup.

Recommended Posts

oslo.config config file search path
[Linux] File search
Nginx config file
In-graph path search using Networkx
File / folder path manipulation in Python
How to create a config file
Get the file path using Pathlib