oslo.config/doc/source/reference/deprecating.rst
Doug Hellmann bd463ee3b6 move some documentation out of the source files
The cfg module is very large, and starts with a huge block of
documentation. This patch moves that information into separate files
in the reference section of the docs. A few formatting fixes need to
be made to have it build cleanly, but the content is not changed in a
substantive way.

Change-Id: I86aa90bbf180b5dc9acbcedb024e5361d49954c3
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2018-07-19 17:26:38 -04:00

1.3 KiB

Option Deprecation

If you want to rename some options, move them to another group or remove completely, you may change their declarations using deprecated_name, deprecated_group and deprecated_for_removal parameters to the Opt constructor:

from oslo_config import cfg

conf = cfg.ConfigOpts()

opt_1 = cfg.StrOpt('opt_1', default='foo', deprecated_name='opt1')
opt_2 = cfg.StrOpt('opt_2', default='spam', deprecated_group='DEFAULT')
opt_3 = cfg.BoolOpt('opt_3', default=False, deprecated_for_removal=True)

conf.register_opt(opt_1, group='group_1')
conf.register_opt(opt_2, group='group_2')
conf.register_opt(opt_3)

conf(['--config-file', 'config.conf'])

assert conf.group_1.opt_1 == 'bar'
assert conf.group_2.opt_2 == 'eggs'
assert conf.opt_3

Assuming that the file config.conf has the following content:

[group_1]
opt1 = bar

[DEFAULT]
opt_2 = eggs
opt_3 = True

the script will succeed, but will log three respective warnings about the given deprecated options.

There are also deprecated_reason and deprecated_since parameters for specifying some additional information about a deprecation.

All the mentioned parameters can be mixed together in any combinations.