neutron_lib.api.validators package

neutron_lib.api.validators package

Submodules

neutron_lib.api.validators.allowedaddresspairs module

neutron_lib.api.validators.availability_zone module

neutron_lib.api.validators.availability_zone.convert_az_list_to_string(az_list)

Convert a list of availability zones into a string.

Parameters:az_list – A list of AZs.
Returns:The az_list in string format.
neutron_lib.api.validators.availability_zone.convert_az_string_to_list(az_string)

Convert an AZ list in string format into a python list.

Parameters:az_string – The AZ list in string format.
Returns:The python list of AZs build from az_string.

neutron_lib.api.validators.dns module

neutron_lib.api.validators.dns.validate_dns_domain(data, max_len=255)

Validate DNS domain.

Parameters:
  • data – The data to validate.
  • max_len – An optional cap on the length of the string.
Returns:

None if data is valid, otherwise a human readable message indicating why validation failed.

neutron_lib.api.validators.dns.validate_dns_name(data, max_len=255)

Validate DNS name.

This method validates dns name and also needs to have dns_domain in config because this may call a method which uses the config.

Parameters:
  • data – The data to validate.
  • max_len – An optional cap on the length of the string.
Returns:

None if data is valid, otherwise a human readable message indicating why validation failed.

neutron_lib.api.validators.dns.validate_fip_dns_name(data, max_len=255)

Validate DNS name for floating IP.

Parameters:
  • data – The data to validate.
  • max_len – An optional cap on the length of the string.
Returns:

None if data is valid, otherwise a human readable message indicating why validation failed.

neutron_lib.api.validators.multiprovidernet module

neutron_lib.api.validators.multiprovidernet.convert_and_validate_segments(segments, valid_values=None)

Module contents

neutron_lib.api.validators.add_validator(validation_type, validator)

Dynamically add a validator.

This can be used by clients to add their own, private validators, rather than directly modifying the data structure. The clients can NOT modify existing validators.

neutron_lib.api.validators.get_validator(validation_type, default=None)

Get a registered validator by type.

Parameters:
  • validation_type – The type to retrieve the validator for.
  • default – A default value to return if the validator is not registered.
Returns:

The validator if registered, otherwise the default value.

neutron_lib.api.validators.is_attr_set(attribute)

Determine if an attribute value is set.

Parameters:attribute – The attribute value to check.
Returns:False if the attribute value is None or ATTR_NOT_SPECIFIED, otherwise True.
neutron_lib.api.validators.validate_any_key_specs_or_none(data, key_specs=None)

Validate each dict in a list matches at least 1 key_spec.

Parameters:
  • data – The list of dicts to validate.
  • key_specs – An iterable collection of key spec dicts that is used to check each dict in data.
Returns:

None.

Raises:

InvalidInput – If any of the dicts in data do not match at least 1 of the key_specs given.

neutron_lib.api.validators.validate_boolean(data, valid_values=None)

Validate data is a python bool compatible object.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if the value can be converted to a bool, otherwise a human readable message indicating why data is invalid.

neutron_lib.api.validators.validate_dict(data, key_specs=None)

Validate data is a dict optionally containing a specific set of keys.

Parameters:
  • data – The data to validate.
  • key_specs – The optional list of keys that must be contained in data.
Returns:

None if data is a dict and (optionally) contains only key_specs. Otherwise a human readable message is returned indicating why data is not valid.

neutron_lib.api.validators.validate_dict_or_empty(data, key_specs=None)

Validate data is {} or a dict containing a specific set of keys.

Parameters:
  • data – The data to validate.
  • key_specs – The optional list of keys that must be contained in data.
Returns:

None if data is {} or a dict (optionally) containing only key_specs. Otherwise a human readable message is returned indicating why data is not valid.

neutron_lib.api.validators.validate_dict_or_nodata(data, key_specs=None)

Validate no data or a dict containing a specific set of keys.

Parameters:
  • data – The data to validate. May be None.
  • key_specs – The optional list of keys that must be contained in data.
Returns:

None if no data/empty dict or a dict and (optionally) contains all key_specs. Otherwise a human readable message is returned indicating why data is not valid.

neutron_lib.api.validators.validate_dict_or_none(data, key_specs=None)

Validate data is None or a dict containing a specific set of keys.

Parameters:
  • data – The data to validate.
  • key_specs – The optional list of keys that must be contained in data.
Returns:

None if data is None or a dict that (optionally) contains all key_specs. Otherwise a human readable message is returned indicating why data is not valid.

neutron_lib.api.validators.validate_fixed_ips(data, valid_values=None)

Validate data is a list of fixed IP dicts.

In addition this function validates the ip_address and subnet_id if present in each fixed IP dict.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is a valid list of fixed IP dicts. Otherwise a human readable message is returned indicating why validation failed.

neutron_lib.api.validators.validate_hostroutes(data, valid_values=None)

Validate a list of unique host route dicts.

Parameters:
  • data – The data to validate. To be valid it must be a list like structure of host route dicts, each containing ‘destination’ and ‘nexthop’ key values.
  • valid_values – Not used!
Returns:

None if data is a valid list of unique host route dicts, otherwise a human readable message indicating why validation failed.

neutron_lib.api.validators.validate_integer(data, valid_values=None)

This function validates if the data is an integer.

It checks both number or string provided to validate it’s an integer and returns a message with the error if it’s not

Parameters:
  • data – The string or number to validate as integer.
  • valid_values – values to limit the ‘data’ to.
Returns:

None if data is an integer, otherwise a human readable message indicating why validation failed..

neutron_lib.api.validators.validate_ip_address(data, valid_values=None)

Validate data is an IP address.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is an IP address, otherwise a human readable message indicating why data isn’t an IP address.

neutron_lib.api.validators.validate_ip_address_or_none(data, valid_values=None)

Validate data is an IP address or None.

Parameters:
  • data – The data to validate.
  • valid_values – An optional list of values data may take on.
Returns:

None if data is None or a valid IP address, otherwise a human readable message indicating why the data is invalid.

neutron_lib.api.validators.validate_ip_or_subnet_or_none(data, valid_values=None)

Validate data is an IP address, a valid IP subnet string, or None.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is None or a valid IP address or a valid IP subnet, otherwise a human readable message indicating why the data is neither an IP address nor IP subnet.

neutron_lib.api.validators.validate_ip_pools(data, valid_values=None)

Validate that start and end IP addresses are present.

In addition to this the IP addresses will also be validated.

Parameters:
  • data – The data to validate. Must be a list-like structure of IP pool dicts that each have a ‘start’ and ‘end’ key value.
  • valid_values – Not used!
Returns:

None if data is a valid list of IP pools, otherwise a message indicating why the data is invalid.

neutron_lib.api.validators.validate_list_of_regex_or_none(data, valid_values=None)

Validate data is None or a list of items matching regex.

Parameters:
  • data – A list of data to validate.
  • valid_values – The regular expression to use with re.match on each element of the data.
Returns:

None if data is None or contains matches for valid_values, otherwise a human readable message as to why data is invalid.

neutron_lib.api.validators.validate_list_of_unique_strings(data, max_len=None)

Validate data is a list of unique strings.

Parameters:
  • data – The data to validate.
  • max_len – An optional cap on the length of the string.
Returns:

None if the data is a list of non-empty/non-blank strings, otherwise a human readable message indicating why validation failed.

neutron_lib.api.validators.validate_mac_address(data, valid_values=None)

Validate data is a MAC address.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if the data is a valid MAC address, otherwise a human readable message as to why validation failed.

neutron_lib.api.validators.validate_mac_address_or_none(data, valid_values=None)

Validate data is a MAC address if the data isn’t None.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if the data is None or a valid MAC address, otherwise a human readable message indicating why validation failed.

neutron_lib.api.validators.validate_nameservers(data, valid_values=None)

Validate a list of unique IP addresses.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is a list of valid IP addresses, otherwise a human readable message is returned indicating why validation failed.

neutron_lib.api.validators.validate_no_whitespace(data)

Validates that input has no whitespace.

Parameters:data – The data to validate. Must be a python string type suitable for searching via regex.
Returns:The data itself.
Raises:InvalidInput – If the data contains whitespace.
neutron_lib.api.validators.validate_non_negative(data, valid_values=None)

Validate data is a positive int.

Parameters:
  • data – The data to validate
  • valid_values – Not used!
Returns:

None if data is an int and is positive, otherwise a human readable message as to why data is invalid.

neutron_lib.api.validators.validate_not_empty_string(data, max_len=None)

Validate data is a non-empty/non-blank string.

Parameters:
  • data – The data to validate.
  • max_len – An optional cap on the length of the string data.
Returns:

None if the data is non-empty/non-blank, otherwise a human readable string message indicating why validation failed.

neutron_lib.api.validators.validate_not_empty_string_or_none(data, max_len=None)

Validate data is a non-empty string or None.

Parameters:
  • data – The data to validate.
  • max_len – An optional cap on the str length to validate.
Returns:

None if the data string is not None and is not an empty string, otherwise a human readable message as to why the string data is invalid.

neutron_lib.api.validators.validate_port_range_or_none(data, valid_values=None)

Validate data is a range of TCP/UDP port numbers

Parameters:
  • data – The data to validate
  • valid_values – Not used!
Returns:

None if data is an int between 0 and 65535, or two ints between 0 and 65535 with a colon between them, otherwise a human readable message as to why data is invalid.

neutron_lib.api.validators.validate_range(data, valid_values=None)

Check that integer value is within a range provided.

Test is inclusive. Allows either limit to be ignored, to allow checking ranges where only the lower or upper limit matter. It is expected that the limits provided are valid integers or the value None.

Parameters:
  • data – The data to validate.
  • valid_values – A list of 2 elements where element 0 is the min value the int data can have and element 1 is the max.
Returns:

None if the data is a valid int in the given range, otherwise a human readable message as to why validation failed.

neutron_lib.api.validators.validate_range_or_none(data, valid_values=None)

Check that the provided value is none or a ranged integer

neutron_lib.api.validators.validate_regex(data, valid_values=None)

Validate data is matched against a regex.

Parameters:
  • data – The data to validate.
  • valid_values – The regular expression to use with re.match on the data.
Returns:

None if data contains matches for valid_values, otherwise a human readable message as to why data is invalid.

neutron_lib.api.validators.validate_regex_or_none(data, valid_values=None)

Validate data is None or matched against a regex.

Parameters:
  • data – The data to validate.
  • valid_values – The regular expression to use with re.match on the data.
Returns:

None if data is None or contains matches for valid_values, otherwise a human readable message as to why data is invalid.

neutron_lib.api.validators.validate_service_plugin_type(data, valid_values=None)

Validates data is a valid service plugin.

Parameters:
  • data – The service plugin type to validate.
  • valid_values – Not used.
Returns:

None if data is a valid service plugin known to the plugin directory.

Raises:

InvalidServiceType if data is not a service known by the plugin directory.

neutron_lib.api.validators.validate_string(data, max_len=None)

Validate data is a string object optionally capping it length.

Parameters:
  • data – The data to validate.
  • max_len – An optional cap on the length of the string.
Returns:

None if the data is a valid string type and (optionally) within the given max_len. Otherwise a human readable message indicating why the data is invalid.

neutron_lib.api.validators.validate_string_or_none(data, max_len=None)

Validate data is a string or None.

Parameters:
  • data – The data to validate.
  • max_len – An optional cap on the length of the string data.
Returns:

None if the data is None or a valid string, otherwise a human readable message indicating why validation failed.

neutron_lib.api.validators.validate_subnet(data, valid_values=None)

Validate data is an IP network subnet string.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is valid IP network address. Otherwise a human readable message as to why data is invalid.

neutron_lib.api.validators.validate_subnet_list(data, valid_values=None)

Validate data is a list of subnet dicts.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is a valid list of subnet dicts, otherwise a human readable message as to why the data is invalid.

neutron_lib.api.validators.validate_subnet_or_none(data, valid_values=None)

Validate data is a valid subnet address string or None.

Parameters:
  • data – The data to validate.
  • valid_values – The optional list of values data may take on.
Returns:

None if data is None or a valid subnet, otherwise a human readable message as to why data is invalid.

neutron_lib.api.validators.validate_subnetpool_id(data, valid_values=None)

Validate data is valid subnet pool ID.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is a valid subnet pool ID, otherwise a human readable message as to why it’s invalid.

neutron_lib.api.validators.validate_subnetpool_id_or_none(data, valid_values=None)

Validate data is valid subnet pool ID or None.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is a valid subnet pool ID or None, otherwise a human readable message as to why it’s invalid.

neutron_lib.api.validators.validate_subports(data, valid_values=None)

Validate data is a list of subnet port dicts.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is a list of subport dicts each with a unique valid port_id, segmentation_id and segmentation_type. Otherwise a human readable message is returned indicating why the data is invalid.

neutron_lib.api.validators.validate_uuid(data, valid_values=None)

Validate data is UUID like.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is UUID like in form, otherwise a human readable message indicating why data is invalid.

neutron_lib.api.validators.validate_uuid_list(data, valid_values=None)

Validate data is a list of UUID like values.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is an iterable that contains valid UUID values, otherwise a message is returned indicating why validation failed.

neutron_lib.api.validators.validate_uuid_or_none(data, valid_values=None)

Validate data is UUID like or None.

Parameters:
  • data – The data to validate.
  • valid_values – Not used!
Returns:

None if data is UUID like in form or None, otherwise a human readable message indicating why data is invalid.

neutron_lib.api.validators.validate_values(data, valid_values=None, valid_values_display=None)

Validate that the provided ‘data’ is within ‘valid_values’.

Parameters:
  • data – The data to check within valid_values.
  • valid_values – A collection of values that ‘data’ must be in to be valid. The collection can be any type that supports the ‘in’ operation.
  • valid_values_display – A string to display that describes the valid values. This string is only displayed when an invalid value is encountered. If no string is provided, the string “valid_values” will be used.
Returns:

The message to return if data not in valid_values.

Raises:

TypeError if the values for ‘data’ or ‘valid_values’ are not compatible for comparison or doesn’t have __contains__. If TypeError is raised this is considered a programming error and the inputs (data) and (valid_values) must be checked so this is never raised on validation.

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.