Backend Drivers¶
Oslo.config’s primary source of configuration data are plaintext, INI-like style, configuration files. With the addition of backend drivers support, it is possible to store configuration data in different places and with different formats, as long as there exists a proper driver to connect to those external sources and provide a way to fetch configuration values from them.
A backend driver implementation is divided in two main classes, a driver
class of type ConfigurationSourceDriver
and a configuration source
class of type ConfigurationSource
.
IMPORTANT: At this point, all backend drivers are only able to provide immutable values. This protects applications and services from having options in external sources mutated when they reload configuration files.
Abstract Classes¶
The Driver Class¶
-
class
oslo_config.sources.
ConfigurationSourceDriver
¶ A backend driver option for oslo.config.
For each group name listed in config_source on the DEFAULT group, a
ConfigurationSourceDriver
is responsible for creating one new instance of aConfigurationSource
. The proper driver class to be used is selected based on the driver option inside each one of the groups listed in config_source and loaded through entry points managed by stevedore using the namespace oslo.config.driver:[DEFAULT] config_source = source1 config_source = source2 ... [source1] driver = remote_file ... [source2] driver = castellan ...
Each specific driver knows all the available options to properly instatiate a ConfigurationSource using the values comming from the given group in the open_source_from_opt_group() method and is able to generate sample config through the list_options_for_discovery() method.
-
abstract
list_options_for_discovery
()¶ Return the list of options available to configure a new source.
Drivers should advertise all supported options in this method for the purpose of sample generation by oslo-config-generator.
For an example on how to implement this method you can check the remote_file driver at oslo_config.sources._uri.URIConfigurationSourceDriver.
- Returns
a list of supported options of a ConfigurationSource.
-
abstract
open_source_from_opt_group
(conf, group_name)¶ Return an open configuration source.
Uses group_name to find the configuration settings for the new source and then open the configuration source and return it.
If a source cannot be open, raises an appropriate exception.
- Parameters
conf (ConfigOpts) – The active configuration option handler from which to seek configuration values.
group_name (str) – The configuration option group name where the options for the source are stored.
- Returns
an instance of a subclass of ConfigurationSource
-
abstract
The Configuration Source Class¶
-
class
oslo_config.sources.
ConfigurationSource
¶ A configuration source option for oslo.config.
A configuration source is able to fetch configuration values based on a (group, option) key from an external source that supports key-value mapping such as INI files, key-value stores, secret stores, and so on.
-
abstract
get
(group_name, option_name, opt)¶ Return the value of the option from the group.
- Parameters
group_name (str) – Name of the group.
option_name (str) – Name of the option.
opt (Opt) – The option definition.
- Returns
A tuple (value, location) where value is the option value or oslo_config.sources._NoValue if the (group, option) is not present in the source, and location is a LocationInfo.
-
abstract
Known Backend Drivers¶
Remote File¶
The remote_file backend driver is the first driver implemented by oslo.config. It extends the previous limit of only accessing local files to a new scenario where it is possible to access configuration data over the network. The remote_file driver is based on the requests module and is capable of accessing remote files through HTTP or HTTPS.
To definition of a remote_file configuration data source can be as minimal as:
[DEFAULT]
config_source = external_config_group
[external_config_group]
driver = remote_file
uri = http://mydomain.com/path/to/config/data.conf
Or as complete as:
[DEFAULT]
config_source = external_config_group
[external_config_group]
driver = remote_file
uri = https://mydomain.com/path/to/config/data.conf
ca_path = /path/to/server/ca.pem
client_key = /path/to/my/key.pem
client_cert = /path/to/my/cert.pem
On the following sessions, you can find more information about this driver’s classes and its options.
The Driver Class¶
-
class
oslo_config.sources._uri.
URIConfigurationSourceDriver
¶ A backend driver for remote files served through http[s].
- Required options:
uri: URI containing the file location.
- Non-required options:
- ca_path: The path to a CA_BUNDLE file or directory with
certificates of trusted CAs.
- client_cert: Client side certificate, as a single file path
containing either the certificate only or the private key and the certificate.
- client_key: Client side private key, in case client_cert is
specified but does not includes the private key.
The Configuration Source Class¶
-
class
oslo_config.sources._uri.
URIConfigurationSource
(uri, ca_path=None, client_cert=None, client_key=None)¶ A configuration source for remote files served through http[s].
- Parameters
uri – The Uniform Resource Identifier of the configuration to be retrieved.
ca_path – The path to a CA_BUNDLE file or directory with certificates of trusted CAs.
client_cert – Client side certificate, as a single file path containing either the certificate only or the private key and the certificate.
client_key – Client side private key, in case client_cert is specified but does not includes the private key.
Environment¶
The environment backend driver provides a method of accessing configuration data in environment variables. It is enabled by default and requires no additional configuration to use. The environment is checked after command line options, but before configuration files.
Environment variables are checked for any configuration data. The variable names take the form:
A prefix of
OS_
The group name, uppercased
Separated from the option name by a __ (double underscore)
Followed by the name
For an option that looks like this in the usual INI format:
[placement_database]
connection = sqlite:///
the corresponding environment variable would be
OS_PLACEMENT_DATABASE__CONNECTION
.
The Driver Class¶
-
class
oslo_config.sources._environment.
EnvironmentConfigurationSourceDriver
¶ A backend driver for environment variables.
This configuration source is available by default and does not need special configuration to use. The sample config is generated automatically but is not necessary.