Option Types and Validation

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
  • 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.

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.HostAddress(version=None, type_name='host address value')

Host Address type.

Represents both valid IP addresses and valid host domain names including fully qualified domain names. Performs strict checks for both IP addresses and valid hostnames, matching the opt values to the respective types as per RFC1912.

Parameters
  • version – defines which version should be explicitly checked (4 or 6) in case of an IP address

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

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

Host domain name 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 either valid values or tuples of valid values with descriptions.

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.

Changed in version 5.2: The choices parameter will now accept a sequence of tuples, where each tuple is of form (choice, description)

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. Should be an instance of ConfigType.

  • 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
  • num_type – the type of number used for casting (i.e int, float)

  • 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.

  • choices – Optional sequence of either valid values or tuples of valid values with descriptions.

New in version 3.14.

Changed in version 5.2: The choices parameter will now accept a sequence of tuples, where each tuple is of form (choice, description)

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

Port type

Represents a L4 Port.

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 either valid values or tuples of valid values with descriptions.

New in version 3.16.

Changed in version 5.2: The choices parameter will now accept a sequence of tuples, where each tuple is of form (choice, description)

class oslo_config.types.Range(min=None, max=None, inclusive=True, type_name='range value')

Range type.

Represents a range of integers. A range is identified by an integer both sides of a ‘-‘ character. Negatives are allowed. A single number is also a valid range.

Parameters
  • min – Optional check that lower bound is greater than or equal to min.

  • max – Optional check that upper bound is less than or equal to max.

  • inclusive – True if the right bound is to be included in the range.

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

New in version 3.18.

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 either valid values or tuples of valid values with descriptions. 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.

Changed in version 5.2: The choices parameter will now accept a sequence of tuples, where each tuple is of form (choice, description)

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

URI type

Represents URI. Value will be validated as RFC 3986.

Parameters
  • 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.

  • schemes – List of valid schemes.

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

Changed in version 3.14: Added max_length parameter.

Changed in version 3.18: Added schemes parameter.

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.