Base class for all configuration options.
The only required parameter is the option’s name. However, it is common to also supply a default and help string for all options.
Parameters: |
|
---|
An Opt object has no public methods, but has a number of public properties:
the name of the option, which may include hyphens
a callable object that takes string and returns converted and validated value. Default types are available from oslo_config.types
the (hyphen-less) ConfigOpts property which contains the option value
a single character CLI option name
the default value of the option
a sample default value string to include in sample config files
True if the option is a positional CLI argument
the name shown as the argument to a CLI option in –help output
a string explaining how the option’s value is used
in sample files, a bool value indicating the option is advanced
Changed in version 1.2: Added deprecated_opts parameter.
Changed in version 1.4: Added sample_default parameter.
Changed in version 1.9: Added deprecated_for_removal parameter.
Changed in version 2.7: An exception is now raised if the default value has the wrong type.
Changed in version 3.2: Added deprecated_reason parameter.
Changed in version 3.5: Added mutable parameter.
Changed in version 3.12: Added deprecated_since parameter.
Changed in version 3.15: Added advanced parameter and attribute.
Option with String type
Option with type oslo_config.types.String
Parameters: |
|
---|
Changed in version 2.7: Added quotes parameter
Changed in version 2.7: Added regex parameter
Changed in version 2.7: Added ignore_case parameter
Changed in version 2.7: Added max_length parameter
Boolean options.
Bool opts are set to True or False on the command line using –optname or –nooptname respectively.
In config files, boolean values are cast with Boolean type.
Parameters: |
|
---|
Option with Integer type
Option with type oslo_config.types.Integer
Parameters: |
|
---|
Changed in version 1.15: Added min and max parameters.
Option with Float type
Option with type oslo_config.types.Float :param min: minimum value the float can take :param max: maximum value the float can take
Parameters: |
|
---|
Changed in version 3.14: Added min and max parameters.
Option with List(String) type
Option with type oslo_config.types.List
Parameters: |
|
---|
Changed in version 2.5: Added item_type and bounds parameters.
Option with Dict(String) type
Option with type oslo_config.types.Dict
Parameters: |
|
---|
New in version 1.2.
Multi-value option.
Multi opt values are typed opts which may be specified multiple times. The opt value is a list containing all the values specified.
Parameters: |
|
---|
For example:
cfg.MultiOpt('foo',
item_type=types.Integer(),
default=None,
help="Multiple foo option")
The command line --foo=1 --foo=2 would result in cfg.CONF.foo containing [1,2]
New in version 1.3.
MultiOpt with a MultiString item_type.
MultiOpt with a default oslo_config.types.MultiString item type.
Parameters: |
|
---|
Opt with IPAddress type
Option with type oslo_config.types.IPAddress
Parameters: |
|
---|
New in version 1.4.
Option for a TCP/IP port number. Ports can range from 0 to 65535.
Option with type oslo_config.types.Integer
Parameters: |
|
---|
New in version 2.6.
Changed in version 3.2: Added choices parameter.
Changed in version 3.4: Allow port number with 0.
Changed in version 3.16: Added min and max parameters.
Option for a hostname. Only accepts valid hostnames.
Option with type oslo_config.types.Hostname
New in version 3.8.
Opt with URI type
Option with type oslo_config.types.URI
Parameters: | max_length – If positive integer, the value must be less than or equal to this parameter. |
---|
New in version 3.12.
Changed in version 3.14: Added max_length parameter
Represents a Deprecated option.
Here’s how you can use it:
oldopts = [cfg.DeprecatedOpt('oldopt1', group='group1'),
cfg.DeprecatedOpt('oldopt2', group='group2')]
cfg.CONF.register_group(cfg.OptGroup('group1'))
cfg.CONF.register_opt(cfg.StrOpt('newopt', deprecated_opts=oldopts),
group='group1')
For options which have a single value (like in the example above), if the new option is present (“[group1]/newopt” above), it will override any deprecated options present (“[group1]/oldopt1” and “[group2]/oldopt2” above).
If no group is specified for a DeprecatedOpt option (i.e. the group is None), lookup will happen within the same group the new option is in. For example, if no group was specified for the second option ‘oldopt2’ in oldopts list:
oldopts = [cfg.DeprecatedOpt('oldopt1', group='group1'),
cfg.DeprecatedOpt('oldopt2')]
cfg.CONF.register_group(cfg.OptGroup('group1'))
cfg.CONF.register_opt(cfg.StrOpt('newopt', deprecated_opts=oldopts),
group='group1')
then lookup for that option will happen in group ‘group1’.
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.
Multi-value options will return all new and deprecated options. So if we have a multi-value option “[group1]/opt1” whose deprecated option is “[group2]/opt2”, and the conf file has both these options specified like so:
[group1]
opt1=val10,val11
[group2]
opt2=val21,val22
Then the value of “[group1]/opt1” will be [‘val11’, ‘val12’, ‘val21’, ‘val22’].
New in version 1.2.
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.
Parameters: |
|
---|
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:
the name of the group
the group title as displayed in –help
the group description as displayed in –help
Parameters: |
|
---|