Option Definitions

class oslo.config.cfg.Opt(name, type=None, dest=None, short=None, default=None, positional=False, metavar=None, help=None, secret=False, required=False, deprecated_name=None, deprecated_group=None, deprecated_opts=None, sample_default=None)

Base class for all configuration options.

An Opt object has no public methods, but has a number of public string properties:

name:
the name of the option, which may include hyphens
type:
a callable object that takes string and returns converted and validated value
dest:
the (hyphen-less) ConfigOpts property which contains the option value
short:
a single character CLI option name
default:
the default value of the option
sample_default:
a sample default value string to include in sample config files
positional:
True if the option is a positional CLI argument
metavar:
the name shown as the argument to a CLI option in –help output
help:
an string explaining how the options value is used
class oslo.config.cfg.StrOpt(name, choices=None, **kwargs)

Option with String type (for backward compatibility).

Parameters:choices – Optional sequence of valid values.
class oslo.config.cfg.BoolOpt(name, **kwargs)

Boolean options.

Bool opts are set to True or False on the command line using –optname or –noopttname respectively.

In config files, boolean values are cast with Boolean type.

class oslo.config.cfg.IntOpt(name, **kwargs)

Opt with Integer type (for backward compatibility).

class oslo.config.cfg.FloatOpt(name, **kwargs)

Opt with Float type (for backward compatibility).

class oslo.config.cfg.ListOpt(name, **kwargs)

Opt with List(String) type (for backward compatibility).

class oslo.config.cfg.DictOpt(name, **kwargs)

Opt with Dict(String) type (for backward compatibility).

class oslo.config.cfg.MultiStrOpt(name, **kwargs)

Multi opt with String item type (for backward compatibility).

class oslo.config.cfg.IPOpt(name, version=None, **kwargs)

Opt with IPAddress type (either IPv4, IPv6 or both).

class oslo.config.cfg.DeprecatedOpt(name, group=None)

Represents a Deprecated option.

Here’s how you can use it:

oldopts = [cfg.DeprecatedOpt('oldfoo', group='oldgroup'),
           cfg.DeprecatedOpt('oldfoo2', group='oldgroup2')]
cfg.CONF.register_group(cfg.OptGroup('blaa'))
cfg.CONF.register_opt(cfg.StrOpt('foo', deprecated_opts=oldopts),
                      group='blaa')

Multi-value options will return all new and deprecated options. For single options, if the new option is present (“[blaa]/foo” above) it will override any deprecated options present. If the new option is not present and multiple deprecated options are present, the option corresponding to the first element of deprecated_opts will be chosen.

If group is None, the DeprecatedOpt lookup will happen within the same group the new option is in. For example:

oldopts = [cfg.DeprecatedOpt('oldfoo'),
           cfg.DeprecatedOpt('oldfoo2', group='DEFAULT')]

cfg.CONF.register_group(cfg.OptGroup('blaa'))
cfg.CONF.register_opt(cfg.StrOpt('foo', deprecated_opts=oldopts),
                      group='blaa')

In the example above, oldfoo will be looked up in the blaa group and oldfoo2 in the DEFAULT group.

class oslo.config.cfg.SubCommandOpt(name, dest=None, handler=None, title=None, description=None, help=None)

Sub-command options.

Sub-command options allow argparse sub-parsers to be used to parse additional command line arguments.

The handler argument to the SubCommandOpt constructor is a callable which is supplied an argparse subparsers object. Use this handler callable to add sub-parsers.

The opt value is SubCommandAttr object with the name of the chosen sub-parser stored in the ‘name’ attribute and the values of other sub-parser arguments available as additional attributes.

class oslo.config.cfg.OptGroup(name, title=None, help=None)

Represents a group of opts.

CLI opts in the group are automatically prefixed with the group name.

Each group corresponds to a section in config files.

An OptGroup object has no public methods, but has a number of public string properties:

name:
the name of the group
title:
the group title as displayed in –help
help:
the group description as displayed in –help

Previous topic

The cfg Module

Next topic

Option Types and Validation

This Page