Option Types and Validation¶
Type conversion and validation classes for configuration options.
Use these classes as values for the type argument to
oslo_config.cfg.Opt
and its subclasses.
-
class
oslo_config.types.
Boolean
¶ Boolean type.
Values are case insensitive and can be set using 1/0, yes/no, true/false or on/off.
-
class
oslo_config.types.
Dict
(value_type=None, bounds=False)¶ Dictionary type.
Dictionary type values are key:value pairs separated by commas. The resulting value is a dictionary of these key/value pairs. Type of dictionary key is always string, but dictionary value type can be customized.
Parameters: - value_type – type of values in dictionary
- bounds – if True, value should be inside “{” and “}” pair
-
class
oslo_config.types.
Float
¶ Float type.
-
class
oslo_config.types.
IPAddress
(version=None)¶ IP address type
Represents either ipv4 or ipv6. Without specifying version parameter both versions are checked
Parameters: version – defines which version should be explicitly checked (4 or 6)
-
class
oslo_config.types.
Integer
(min=None, max=None)¶ Integer type.
Converts value to an integer optionally doing range checking. If value is whitespace or empty string will return None.
Parameters: - min – Optional check that value is greater than or equal to min
- max – Optional check that value is less than or equal to max
-
class
oslo_config.types.
List
(item_type=None, bounds=False)¶ List type.
Represent values of other (item) type, separated by commas. The resulting value is a list containing those values.
List doesn’t know if item type can also contain commas. To workaround this it tries the following: if the next part fails item validation, it appends comma and next item until validation succeeds or there is no parts left. In the later case it will signal validation error.
Parameters: - item_type – type of list items
- bounds – if True, value should be inside “[” and “]” pair
-
class
oslo_config.types.
String
(choices=None, quotes=False, regex=None)¶ String type.
String values do not get transformed and are returned as str objects.
Parameters: - choices – Optional sequence of valid values. Mutually exclusive with ‘regex’.
- quotes – If True and string is enclosed with single or double quotes, will strip those quotes. Will signal error if string have quote at the beginning and no quote at the end. Turned off by default. Useful if used with container types like List.
- regex – Optional regular expression (string or compiled regex) that the value must match on an unanchored search. Mutually exclusive with ‘choices’.