The cinder.api.openstack.wsgi Module

class ActionDispatcher

Bases: object

Maps method name to local methods through action name.

default(data)
dispatch(*args, **kwargs)

Find and call local method.

class Controller(view_builder=None)

Bases: object

Default controller.

classmethod api_version(min_ver, max_ver=None, experimental=False)

Decorator for versioning API methods.

Add the decorator to any method which takes a request object as the first parameter and belongs to a class which inherits from wsgi.Controller.

Parameters:
  • min_ver – string representing minimum version
  • max_ver – optional string representing maximum version
static assert_valid_body(body, entity_name)
static get_policy_checker(prefix)
static is_valid_body(body, entity_name)
static validate_name_and_description(body)
static validate_string_length(value, entity_name, min_length=0, max_length=None, remove_whitespaces=False)

Check the length of specified string.

Parameters:
  • value – the value of the string
  • entity_name – the name of the string
  • min_length – the min_length of the string
  • max_length – the max_length of the string
  • remove_whitespaces – True if trimming whitespaces is needed else False
wsgi_actions = {}
wsgi_extensions = []
class ControllerMetaclass

Bases: type

Controller metaclass.

This metaclass automates the task of assembling a dictionary mapping action keys to method names.

static consolidate_vers(versioned_methods)

Consolidates a list of versioned methods dictionaries.

class DictSerializer

Bases: cinder.api.openstack.wsgi.ActionDispatcher

Default request body serialization.

default(data)
serialize(data, action='default')
exception Fault(exception)

Bases: webob.exc.HTTPException

Wrap webob.exc.HTTPException to provide API friendly response.

class JSONDeserializer

Bases: cinder.api.openstack.wsgi.TextDeserializer

default(datastring)
class JSONDictSerializer

Bases: cinder.api.openstack.wsgi.DictSerializer

Default JSON request body serialization.

default(data)
exception OverLimitFault(message, details, retry_time)

Bases: webob.exc.HTTPException

Rate-limited request response.

class Request(*args, **kwargs)

Bases: webob.request.Request

Add some OpenStack API-specific logic to the base webob.Request.

best_match_content_type()

Determine the requested response content-type.

best_match_language()

Determines best available locale from the Accept-Language header.

Returns:the best language match or None if the ‘Accept-Language’ header was not available in the request.
cache_db_backup(backup)
cache_db_backups(backups)
cache_db_items(key, items, item_key='id')

Get cached database items.

Allow API methods to store objects from a DB query to be used by API extensions within the same API request.

An instance of this class only lives for the lifetime of a single API request, so there’s no need to implement full cache management.

cache_db_snapshot(snapshot)
cache_db_snapshots(snapshots)
cache_db_volume(volume)
cache_db_volume_type(volume_type)
cache_db_volume_types(volume_types)
cache_db_volumes(volumes)
cache_resource(resource_to_cache, id_attribute='id', name=None)

Cache the given resource.

Allow API methods to cache objects, such as results from a DB query, to be used by API extensions within the same API request.

The resource_to_cache can be a list or an individual resource, but ultimately resources are cached individually using the given id_attribute.

Different resources types might need to be cached during the same request, they can be cached using the name parameter. For example:

Controller 1:
request.cache_resource(db_volumes, ‘volumes’) request.cache_resource(db_volume_types, ‘types’)
Controller 2:
db_volumes = request.cached_resource(‘volumes’) db_type_1 = request.cached_resource_by_id(‘1’, ‘types’)

If no name is given, a default name will be used for the resource.

An instance of this class only lives for the lifetime of a single API request, so there’s no need to implement full cache management.

cached_resource(name=None)

Get the cached resources cached under the given resource name.

Allow an API extension to get previously stored objects within the same API request.

Note that the object data will be slightly stale.

Returns:a dict of id_attribute to the resource from the cached resources, an empty map if an empty collection was cached, or None if nothing has been cached yet under this name
cached_resource_by_id(resource_id, name=None)

Get a resource by ID cached under the given resource name.

Allow an API extension to get a previously stored object within the same API request. This is basically a convenience method to lookup by ID on the dictionary of all cached resources.

Note that the object data will be slightly stale.

Returns:the cached resource or None if the item is not in the cache
get_content_type()

Determine content type of the request body.

Does not do any body introspection, only checks header

get_db_backup(backup_id)
get_db_backups()
get_db_item(key, item_key)

Get database item.

Allow an API extension to get a previously stored object within the same API request.

Note that the object data will be slightly stale.

get_db_items(key)

Get database items.

Allow an API extension to get previously stored objects within the same API request.

Note that the object data will be slightly stale.

get_db_snapshot(snapshot_id)
get_db_snapshots()
get_db_volume(volume_id)
get_db_volume_type(volume_type_id)
get_db_volume_types()
get_db_volumes()
set_api_version_request(url)

Set API version request based on the request header information.

Microversions starts with /v3, so if a client sends a request for version 1.0 or 2.0 with the /v3 endpoint, throw an exception. Sending a header with any microversion to a /v1 or /v2 endpoint will be ignored. Note that a microversion must be set for the legacy endpoints. This will appear as 1.0 and 2.0 for /v1 and /v2.

class Resource(controller, action_peek=None, **deserializers)

Bases: cinder.wsgi.common.Application

WSGI app that handles (de)serialization and controller dispatch.

WSGI app that reads routing information supplied by RoutesMiddleware and calls the requested action method upon its controller. All controller action methods must accept a ‘req’ argument, which is the incoming wsgi.Request. If the operation is a PUT or POST, the controller method must also accept a ‘body’ argument (the deserialized request body). They may raise a webob.exc exception or return a dict, which will be serialized by requested content type.

Exceptions derived from webob.exc.HTTPException will be automatically wrapped in Fault() to provide API friendly error responses.

deserialize(meth, content_type, body)
dispatch(method, request, action_args)

Dispatch a call to the action-specific method.

get_action_args(request_environment)

Parse dictionary created by routes library.

get_body(request)
get_method(request, action, content_type, body)

Look up the action-specific method and its extensions.

post_process_extensions(extensions, resp_obj, request, action_args)
pre_process_extensions(extensions, request, action_args)
register_actions(controller)

Registers controller actions with this resource.

register_extensions(controller)

Registers controller extensions with this resource.

support_api_request_version = True
class ResourceExceptionHandler

Bases: object

Context manager to handle Resource exceptions.

Used when processing exceptions generated by API implementation methods (or their extensions). Converts most exceptions to Fault exceptions, with the appropriate logging.

class ResponseObject(obj, code=None, headers=None, **serializers)

Bases: object

Bundles a response object with appropriate serializers.

Object that app methods may return in order to bind alternate serializers with a response object to be serialized. Its use is optional.

attach(**kwargs)

Attach slave templates to serializers.

code

Retrieve the response status.

get_serializer(content_type, default_serializers=None)

Returns the serializer for the wrapped object.

Returns the serializer for the wrapped object subject to the indicated content type. If no serializer matching the content type is attached, an appropriate serializer drawn from the default serializers will be used. If no appropriate serializer is available, raises InvalidContentType.

headers

Retrieve the headers.

preserialize(content_type, default_serializers=None)

Prepares the serializer that will be used to serialize.

Determines the serializer that will be used and prepares an instance of it for later call. This allows the serializer to be accessed by extensions for, e.g., template extension.

serialize(request, content_type, default_serializers=None)

Serializes the wrapped object.

Utility method for serializing the wrapped object. Returns a webob.Response object.

class TextDeserializer

Bases: cinder.api.openstack.wsgi.ActionDispatcher

Default request body deserialization.

default(datastring)
deserialize(datastring, action='default')
action(name)

Mark a function as an action.

The given name will be taken as the action key in the body.

This is also overloaded to allow extensions to provide non-extending definitions of create and delete operations.

action_peek_json(body)

Determine action to invoke.

deserializers(**deserializers)

Attaches deserializers to a method.

This decorator associates a dictionary of deserializers with a method. Note that the function attributes are directly manipulated; the method is not wrapped.

extends(*args, **kwargs)

Indicate a function extends an operation.

Can be used as either:

@extends
def index(...):
    pass

or as:

@extends(action='resize')
def _action_resize(...):
    pass
response(code)

Attaches response code to a method.

This decorator associates a response code with a method. Note that the function attributes are directly manipulated; the method is not wrapped.

serializers(**serializers)

Attaches serializers to a method.

This decorator associates a dictionary of serializers with a method. Note that the function attributes are directly manipulated; the method is not wrapped.

Previous topic

The cinder.api.openstack.versioned_method Module

Next topic

The cinder.api.urlmap Module

This Page