neutron_lib.api.converters module¶
- neutron_lib.api.converters.convert_allocation_pools_to_canonical_format(value)¶
Convert allocation pools to canonical format.
- Parameters:
value – The allocation pools which need to be checked.
- Returns:
Allocation pools with addresses in canonical format.
- Raises:
InvalidInput – If the value is not a list of allocation pools.
- neutron_lib.api.converters.convert_cidr_to_canonical_format(value)¶
CIDR is validated and converted to canonical format.
- Parameters:
value – The CIDR which needs to be checked.
- Returns:
‘value’ if ‘value’ is CIDR with IPv4 address,
CIDR with canonical IPv6 address if ‘value’ is IPv6 CIDR.
- Raises:
InvalidInput if ‘value’ is None, not a valid CIDR or invalid IP Format.
- neutron_lib.api.converters.convert_ip_to_canonical_format(value)¶
IP Address is validated and then converted to canonical format.
- Parameters:
value – The IP Address which needs to be checked.
- Returns:
None if ‘value’ is None,
’value’ if ‘value’ is IPv4 address,
’value’ if ‘value’ is not an IP Address
canonical IPv6 address if ‘value’ is IPv6 address.
- neutron_lib.api.converters.convert_kvp_list_to_dict(kvp_list)¶
Convert a list of ‘key=value’ strings to a dict.
- Parameters:
kvp_list – A list of key value pair strings. For more info on the format see; convert_kvp_str_to_list().
- Returns:
A dict who’s key value pairs are populated by parsing ‘kvp_list’.
- Raises:
InvalidInput – If any of the key value strings are malformed.
- neutron_lib.api.converters.convert_kvp_str_to_list(data)¶
Convert a value of the form ‘key=value’ to [‘key’, ‘value’].
- Parameters:
data – The string to parse for a key value pair.
- Returns:
A list where element 0 is the key and element 1 is the value.
- Raises:
InvalidInput – If ‘data’ is not a key value string.
- neutron_lib.api.converters.convert_none_to_empty_dict(value)¶
Convert the value to an empty dict if it’s None.
- Parameters:
value – The value to convert.
- Returns:
An empty dict if ‘value’ is None, otherwise ‘value’.
- neutron_lib.api.converters.convert_none_to_empty_list(value)¶
Convert value to an empty list if it’s None.
- Parameters:
value – The value to convert.
- Returns:
An empty list of ‘value’ is None, otherwise ‘value’.
- neutron_lib.api.converters.convert_none_to_empty_string(value)¶
Convert the value to an empty string if it’s None.
- Parameters:
value – The value to convert.
- Returns:
An empty string if ‘value’ is None, otherwise ‘value’.
- neutron_lib.api.converters.convert_prefix_forced_case(data, prefix)¶
If <prefix> is a prefix of data, case insensitive, then force its case
This converter forces the case of a given prefix of a string.
Example, with prefix=”Foo”: * ‘foobar’ converted into ‘Foobar’ * ‘fOozar’ converted into ‘Foozar’ * ‘FOObaz’ converted into ‘Foobaz’
- Parameters:
data – The data to convert
- Returns:
if data is a string starting with <prefix> in a case insensitive comparison, then the return value is data with this prefix replaced by <prefix>
- neutron_lib.api.converters.convert_string_to_case_insensitive(data)¶
Convert a string value into a lower case string.
This effectively makes the string case-insensitive.
- Parameters:
data – The value to convert.
- Returns:
The lower-cased string representation of the value, or None is ‘data’ is None.
- Raises:
InvalidInput – If the value is not a string.
- neutron_lib.api.converters.convert_to_boolean(data)¶
Convert a data value into a python bool.
- Parameters:
data – The data value to convert to a python bool. This function supports string types, bools, and ints for conversion of representation to python bool.
- Returns:
The bool value of ‘data’ if it can be coerced.
- Raises:
InvalidInput – If the value can’t be coerced to a python bool.
- neutron_lib.api.converters.convert_to_boolean_if_not_none(data)¶
Uses convert_to_boolean() on the data if the data is not None.
- Parameters:
data – The data value to convert.
- Returns:
The ‘data’ returned from convert_to_boolean() if ‘data’ is not None. None is returned if data is None.
- neutron_lib.api.converters.convert_to_int(data)¶
Convert a data value to a python int.
- Parameters:
data – The data value to convert to a python int via python’s built-in int() constructor.
- Returns:
The int value of the data.
- Raises:
InvalidInput – If the value can’t be converted to an int.
- neutron_lib.api.converters.convert_to_int_if_not_none(data)¶
Uses convert_to_int() on the data if the data is not None.
- Parameters:
data – The data value to convert.
- Returns:
The ‘data’ returned from convert_to_int() if ‘data’ is not None. None is returned if data is None.
- neutron_lib.api.converters.convert_to_list(data)¶
Convert a value into a list.
- Parameters:
data – The value to convert.
- Returns:
A new list wrapped around ‘data’ whereupon the list is empty if ‘data’ is None.
- neutron_lib.api.converters.convert_to_mac_if_none(data)¶
Convert to a random mac address if data is None
- Parameters:
data – The data value
- Returns:
Random mac address if data is None, else return data.
- neutron_lib.api.converters.convert_to_positive_float_or_none(val)¶
Converts a value to a python float if the value is positive.
- Parameters:
val – The value to convert to a positive python float.
- Returns:
The value as a python float. If the val is None, None is returned.
- Raises:
ValueError, InvalidInput – A ValueError is raised if the ‘val’ is a float, but is negative. InvalidInput is raised if ‘val’ can’t be converted to a python float.
- neutron_lib.api.converters.convert_to_protocol(data)¶
Validate that a specified IP protocol is valid.
For the authoritative list mapping protocol names to numbers, see the IANA: http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
- Parameters:
data – The value to verify is an IP protocol.
- Returns:
If data is an int between 0 and 255 or None, return that; if data is a string then return it lower-cased if it matches one of the allowed protocol names.
- Raises:
exceptions.InvalidInput – If data is an int < 0, an int > 255, or a string that does not match one of the allowed protocol names.
- neutron_lib.api.converters.convert_to_sanitized_binding_profile_allocation(allocation, port_id, min_bw_rules)¶
Return binding-profile.allocation in the new format
- Parameters:
allocation – binding-profile.allocation attribute containting a string with RP UUID
port_id – ID of the port that is being sanitized
min_bw_rules – A list of minimum bandwidth rules associated with the port.
- Returns:
A dict with allocation in {‘<group_uuid>’: ‘<rp_uuid>’} format.
- neutron_lib.api.converters.convert_to_sanitized_mac_address(mac_address)¶
Return a MAC address with format xx:xx:xx:xx:xx:xx
- Parameters:
mac_address – (string, netaddr.EUI) The MAC address value
- Returns:
A string with the MAC address formatted. If the MAC address provided is invalid, the same input value is returned; the goal of this method is not to validate it.
- neutron_lib.api.converters.convert_to_string(data)¶
Convert a data value into a string.
- Parameters:
data – The data value to convert to a string.
- Returns:
The string value of ‘data’ if data is not None
- neutron_lib.api.converters.convert_uppercase_ip(data)¶
Uppercase “ip” if present at start of data case-insensitive
Can be used for instance to accept both “ipv4” and “IPv4”.
- Parameters:
data – The data to convert
- Returns:
if data is a string starting with “ip” case insensitive, then the return value is data with the first two letter uppercased