neutron_lib.api package

neutron_lib.api package

Subpackages

Submodules

neutron_lib.api.attributes module

class neutron_lib.api.attributes.AttributeInfo(resource_attrs)

Bases: object

Provides operations on a resource’s attribute map.

AttributeInfo wraps an API resource’s attribute dict and provides methods for filling defaults, validating, converting, etc. based on the underlying attributes.

convert_values(res_dict, exc_cls=<function <lambda>>)

Convert and validate attribute values for a request.

Parameters:
  • res_dict – The resource attributes from the request.
  • exc_cls – Exception to be raised on error that must take a single error message as it’s only constructor arg.
Raises:

exc_cls If any errors occur converting/validating the res_dict.

fill_post_defaults(res_dict, exc_cls=<function <lambda>>, check_allow_post=True)

Fill in default values for attributes in a POST request.

When a POST request is made, the attributes with default values do not need to be specified by the user. This function fills in the values of any unspecified attributes if they have a default value.

If an attribute is not specified and it does not have a default value, an exception is raised.

If an attribute is specified and it is not allowed in POST requests, an exception is raised. The caller can override this behavior by setting check_allow_post=False (used by some internal admin operations).

Parameters:
  • res_dict – The resource attributes from the request.
  • exc_cls – Exception to be raised on error that must take a single error message as it’s only constructor arg.
  • check_allow_post – Raises an exception if a non-POST-able attribute is specified.
Raises:

exc_cls If check_allow_post is True and this instance of ResourceAttributes doesn’t support POST.

populate_project_id(context, res_dict, is_create)

Populate the owner information in a request body.

Ensure both project_id and tenant_id attributes are present. Validate that the requestor has the required privileges. For a create request, copy owner info from context to request body if needed and verify that owner is specified if required.

Parameters:
  • context – The request context.
  • res_dict – The resource attributes from the request.
  • attr_info – The attribute map for the resource.
  • is_create – Is this a create request?
Raises:

HTTPBadRequest If neither the project_id nor tenant_id are specified in the res_dict.

verify_attributes(attrs_to_verify)

Reject unknown attributes.

Consumers should ensure the project info is populated in the attrs_to_verify before calling this method.

Parameters:attrs_to_verify – The attributes to verify against this resource attributes.
Raises:HTTPBadRequest: If attrs_to_verify contains any unrecognized for this resource attributes instance.
neutron_lib.api.attributes.populate_project_info(attributes)

Ensure that both project_id and tenant_id attributes are present.

If either project_id or tenant_id is present in attributes then ensure that both are present.

If neither are present then attributes is not updated.

Parameters:attributes – A dictionary of resource/API attributes or API request/response dict.
Returns:attributes (updated with project_id if applicable).
Raises:HTTPBadRequest if the attributes project_id and tenant_id don’t match.

neutron_lib.api.converters module

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_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_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_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.extensions module

class neutron_lib.api.extensions.APIExtensionDescriptor

Bases: neutron_lib.api.extensions.ExtensionDescriptor

Base class that defines the contract for extensions.

Concrete implementations of API extensions should first provide an API definition in neutron_lib.api.definitions. The API definition module (object reference) can then be specified as a class level attribute on the concrete extension.

For example:

from neutron_lib.api.definitions import provider_net
from neutron_lib.api import extensions


class Providernet(extensions.APIExtensionDescriptor):
    api_definition = provider_net
    # nothing else needed if default behavior is acceptable

If extension implementations need to override the default behavior of this class they can override the respective method directly.

api_definition = <neutron_lib.constants.Sentinel object>
classmethod get_alias()

The alias for the API definition.

classmethod get_description()

Friendly description for the API definition.

classmethod get_extended_resources(version)

Retrieve the extended resource map for the API definition.

Parameters:version – The API version to retrieve the resource attribute map for.
Returns:The extended resource map for the underlying API definition if the version is 2.0. The extended resource map returned includes both the API definition’s RESOURCE_ATTRIBUTE_MAP and SUB_RESOURCE_ATTRIBUTE_MAP where applicable. If the version is not 2.0, an empty dict is returned.
classmethod get_name()

The name of the API definition.

classmethod get_optional_extensions()

Returns the API definition’s optional extensions.

classmethod get_required_extensions()

Returns the API definition’s required extensions.

classmethod get_updated()

The timestamp when the API definition was last updated.

classmethod update_attributes_map(attributes, extension_attrs_map=None)

Update attributes map for this extension.

Behaves like ExtensionDescriptor.update_attributes_map(), but if extension_attrs_map is not given the dict returned from self.get_extended_resources(‘2.0’) is used.

class neutron_lib.api.extensions.ExtensionDescriptor

Bases: object

Base class that defines the contract for extensions.

get_actions()

List of extensions.ActionExtension extension objects.

Actions are verbs callable from the API.

get_alias()

The alias for the extension.

e.g. ‘FOXNSOX’

get_description()

Friendly description for the extension.

e.g. ‘The Fox In Socks Extension’

get_extended_resources(version)

Retrieve extended resources or attributes for core resources.

Extended attributes are implemented by a core plugin similarly to the attributes defined in the core, and can appear in request and response messages. Their names are scoped with the extension’s prefix. The core API version is passed to this function, which must return a map[<resource_name>][<attribute_name>][<attribute_property>] specifying the extended resource attribute properties required by that API version. Extension can add resources and their attr definitions too. The returned map can be integrated into RESOURCE_ATTRIBUTE_MAP.

get_name()

The name of the extension.

e.g. ‘Fox In Socks’

get_optional_extensions()

Returns a list of optionally required extensions.

Unlike get_required_extensions. This will not fail the loading of the extension if one of these extensions is not present. This is useful for an extension that extends multiple resources across other extensions that should still work for the remaining extensions when one is missing.

get_pecan_resources()

List of PecanResourceExtension extension objects.

Resources define new nouns, and are accessible through URLs. The controllers associated with each instance of extensions.ResourceExtension should be a subclass of neutron.pecan_wsgi.controllers.utils.NeutronPecanController. If a resource is defined in both get_resources and get_pecan_resources, the resource defined in get_pecan_resources will take precedence.

get_plugin_interface()

Returns an abstract class which defines contract for the plugin.

The abstract class should inherit from neutron_lib.services.base.ServicePluginBase. Methods in this abstract class should be decorated as abstractmethod

get_request_extensions()

List of extensions.RequestExtension extension objects.

Request extensions are used to handle custom request data.

get_required_extensions()

Return list of extensions required for processing this descriptor.

Without these extensions present in a neutron deployment, the introduced extension cannot load or function properly.

get_resources()

List of extensions.ResourceExtension extension objects.

Resources define new nouns, and are accessible through URLs.

get_updated()

The timestamp when the extension was last updated.

e.g. ‘2011-01-22T13:25:27-06:00’

update_attributes_map(extended_attributes, extension_attrs_map=None)

Update attributes map for this extension.

This is default method for extending an extension’s attributes map. An extension can use this method and supplying its own resource attribute map in extension_attrs_map argument to extend all its attributes that needs to be extended. If an extension does not implement update_attributes_map, the method does nothing and just return.

neutron_lib.api.extensions.is_extension_supported(plugin, alias)

Validate that the extension is supported.

Parameters:
  • plugin – The plugin class.
  • alias – The alias to check.
Returns:

True if the alias is supported else False.

neutron_lib.api.faults module

neutron_lib.api.utils module

NOTE: Do not use this module to add random utils. We want to avoid having a generic utils.py dumping ground.

neutron_lib.api.utils.populate_project_info(*args, **kwargs)

Ensure that both project_id and tenant_id attributes are present.

If either project_id or tenant_id is present in attributes then ensure that both are present.

If neither are present then attributes is not updated.

Parameters:attributes – A dictionary of resource/API attributes or API request/response dict.
Returns:attributes (updated with project_id if applicable).
Raises:HTTPBadRequest if the attributes project_id and tenant_id don’t match.

Module contents

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.