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.

New in version 1.3.

class oslo_config.types.Boolean(type_name='boolean value')

Boolean type.

Values are case insensitive and can be set using 1/0, yes/no, true/false or on/off.

Parameters:type_name – Type name to be used in the sample config file.

Changed in version 2.7: Added type_name parameter.

class oslo_config.types.Dict(value_type=None, bounds=False, type_name='dict value')

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
  • type_name – Type name to be used in the sample config file.

Changed in version 2.7: Added type_name parameter.

class oslo_config.types.Float(min=None, max=None, type_name='floating point value')

Float type.

Parameters:
  • type_name – Type name to be used in the sample config file.
  • min – Optional check that value is greater than or equal to min.
  • max – Optional check that value is less than or equal to max.

Changed in version 2.7: Added type_name parameter.

Changed in version 3.14: Added min and max parameters. If choices are also supplied, they must be within the range.

class oslo_config.types.Hostname(type_name='hostname value')

Hostname type.

A hostname refers to a valid DNS or hostname. It must not be longer than 253 characters, have a segment greater than 63 characters, nor start or end with a hyphen.

Parameters:type_name – Type name to be used in the sample config file.
class oslo_config.types.IPAddress(version=None, type_name='IP address value')

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)
  • type_name – Type name to be used in the sample config file.

Changed in version 2.7: Added type_name parameter.

class oslo_config.types.Integer(min=None, max=None, type_name='integer value', choices=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.
  • type_name – Type name to be used in the sample config file.
  • choices – Optional sequence of valid values.

Changed in version 2.4: The class now honors zero for min and max parameters.

Changed in version 2.7: Added type_name parameter.

Changed in version 3.2: Added choices parameter.

Changed in version 3.16: choices is no longer mutually exclusive with min/max. If those are supplied, all choices are verified to be within the range.

class oslo_config.types.List(item_type=None, bounds=False, type_name='list value')

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
  • type_name – Type name to be used in the sample config file.

Changed in version 2.7: Added type_name parameter.

class oslo_config.types.MultiString(type_name='multi valued')

Multi-valued string.

format_defaults(default, sample_default=None)

Return a list of formatted default values.

class oslo_config.types.Number(num_type, type_name, min=None, max=None, choices=None)

Number class, base for Integer and Float.

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.
  • type_name – Type name to be used in the sample config file.
  • choices – Optional sequence of valid values.
  • num_type – the type of number used for casting (i.e int, float)

New in version 3.14.

class oslo_config.types.Port(min=None, max=None, type_name='port', choices=None)

Port type

Represents a L4 Port.

Parameters:
  • type_name – Type name to be used in the sample config file.
  • choices – Optional sequence of valid values.
  • min – Optional check that value is greater than or equal to min.
  • max – Optional check that value is less than or equal to max.

New in version 3.16.

class oslo_config.types.String(choices=None, quotes=False, regex=None, ignore_case=False, max_length=None, type_name='string value')

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’.
  • ignore_case – If True case differences (uppercase vs. lowercase) between ‘choices’ or ‘regex’ will be ignored; defaults to False.
  • max_length – Optional integer. If a positive value is specified, a maximum length of an option value must be less than or equal to this parameter. Otherwise no length check will be done.
  • type_name – Type name to be used in the sample config file.

Changed in version 2.1: Added regex parameter.

Changed in version 2.5: Added ignore_case parameter.

Changed in version 2.7: Added max_length parameter. Added type_name parameter.

class oslo_config.types.URI(max_length=None, type_name='uri value')

URI type

Represents URI. Value will be validated as RFC 3986.

Parameters:
  • type_name – Type name to be used in the sample config file.
  • max_length – Optional integer. If a positive value is specified, a maximum length of an option value must be less than or equal to this parameter. Otherwise no length check will be done.

Changed in version 3.14: Added max_length parameter.

Previous topic

Option Definitions

Next topic

The ConfigOpts Class

Project Source

This Page