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, deprecated_for_removal=False, deprecated_reason=None, deprecated_since=None, mutable=False, advanced=False)¶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:
name
¶the name of the option, which may include hyphens
type
¶a callable object that takes string and returns converted and
validated value. Default types are available from
oslo_config.types
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
¶a string explaining how the option’s value is used
advanced
¶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.
oslo_config.cfg.
StrOpt
(name, choices=None, quotes=None, regex=None, ignore_case=None, max_length=None, **kwargs)¶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
oslo_config.cfg.
BoolOpt
(name, **kwargs)¶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: |
|
---|
oslo_config.cfg.
IntOpt
(name, min=None, max=None, **kwargs)¶Option with Integer type
Option with type
oslo_config.types.Integer
Parameters: |
|
---|
Changed in version 1.15: Added min and max parameters.
oslo_config.cfg.
FloatOpt
(name, min=None, max=None, **kwargs)¶Option with Float type
Option with type
oslo_config.types.Float
Parameters: |
|
---|
Changed in version 3.14: Added min and max parameters.
oslo_config.cfg.
ListOpt
(name, item_type=None, bounds=None, **kwargs)¶Option with List(String) type
Option with type
oslo_config.types.List
Parameters: |
|
---|
Changed in version 2.5: Added item_type and bounds parameters.
oslo_config.cfg.
DictOpt
(name, **kwargs)¶Option with Dict(String) type
Option with type
oslo_config.types.Dict
Parameters: |
|
---|
New in version 1.2.
oslo_config.cfg.
MultiOpt
(name, item_type, **kwargs)¶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.
oslo_config.cfg.
MultiStrOpt
(name, **kwargs)¶MultiOpt with a MultiString item_type
.
MultiOpt with a default oslo_config.types.MultiString
item
type.
Parameters: |
|
---|
oslo_config.cfg.
IPOpt
(name, version=None, **kwargs)¶Opt with IPAddress type
Option with type
oslo_config.types.IPAddress
Parameters: |
|
---|
New in version 1.4.
oslo_config.cfg.
PortOpt
(name, min=None, max=None, choices=None, **kwargs)¶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.
oslo_config.cfg.
HostnameOpt
(name, **kwargs)¶Option for a hostname. Only accepts valid hostnames.
Option with type
oslo_config.types.Hostname
Parameters: |
|
---|
New in version 3.8.
oslo_config.cfg.
HostAddressOpt
(name, version=None, **kwargs)¶Option for either an IP or a hostname.
Accepts valid hostnames and valid IP addresses.
Option with type
oslo_config.types.HostAddress
Parameters: |
|
---|
New in version 3.22.
oslo_config.cfg.
URIOpt
(name, max_length=None, schemes=None, **kwargs)¶Opt with URI type
Option with type
oslo_config.types.URI
Parameters: |
|
---|
New in version 3.12.
Changed in version 3.14: Added max_length parameter
Changed in version 3.18: Added schemes parameter
oslo_config.cfg.
DeprecatedOpt
(name, group=None)¶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.
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.
Parameters: |
|
---|
oslo_config.cfg.
OptGroup
(name, title=None, help=None, dynamic_group_owner='', driver_option='')¶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
Parameters: |
|
---|
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.