cinder.api.common module

class METADATA_TYPES(value)

Bases: Enum

An enumeration.

image = 2
user = 1
class ViewBuilder

Bases: object

Model API responses as dictionaries.

convert_filter_attributes(filters, resource)
get_cluster_host(req: Request, params: dict, cluster_version=None) tuple[str | None, str | None]

Get cluster and host from the parameters.

This method checks the presence of cluster and host parameters and returns them depending on the cluster_version.

If cluster_version is False we will never return the cluster_name and we will require the presence of the host parameter.

If cluster_version is None we will always check for the presence of the cluster parameter, and if cluster_version is a string with a version we will only check for the presence of the parameter if the version of the request is not less than it. In both cases we will require one and only one parameter, host or cluster.

get_enabled_resource_filters(resource: str | None = None) dict[str, Any]

Get list of configured/allowed filters for the specified resource.

This method checks resource_query_filters_file and returns dictionary which contains the specified resource and its allowed filters:

{
    "resource": ["filter1", "filter2", "filter3"]
}

if resource is not specified, all of the configuration will be returned, and if the resource is not found, empty dict will be returned.

get_pagination_params(params: dict, max_limit: int | None = None) tuple

Return marker, limit, offset tuple from request.

Parameters:

paramswsgi.Request’s GET dictionary, possibly containing ‘marker’, ‘limit’, and ‘offset’ variables. ‘marker’ is the id of the last element the client has seen, ‘limit’ is the maximum number of items to return and ‘offset’ is the number of items to skip from the marker or from the first element. If ‘limit’ is not specified, or > max_limit, we default to max_limit. Negative values for either offset or limit will cause exc.HTTPBadRequest() exceptions to be raised. If no offset is present we’ll default to 0 and if no marker is present we’ll default to None.

Max_limit:

Max value ‘limit’ return value can take

Returns:

Tuple (marker, limit, offset)

get_request_url(request: Request) str
get_sort_params(params: dict, default_key: str = 'created_at', default_dir: str = 'desc') tuple[list[str], list[str]]

Retrieves sort keys/directions parameters.

Processes the parameters to create a list of sort keys and sort directions that correspond to either the ‘sort’ parameter or the ‘sort_key’ and ‘sort_dir’ parameter values. The value of the ‘sort’ parameter is a comma- separated list of sort keys, each key is optionally appended with ‘:<sort_direction>’.

Note that the ‘sort_key’ and ‘sort_dir’ parameters are deprecated in kilo and an exception is raised if they are supplied with the ‘sort’ parameter.

The sort parameters are removed from the request parameters by this function.

Parameters:
  • params – webob.multidict of request parameters (from cinder.api.openstack.wsgi.Request.params)

  • default_key – default sort key value, added to the list if no sort keys are supplied

  • default_dir – default sort dir value, added to the list if the corresponding key does not have a direction specified

Returns:

list of sort keys, list of sort dirs

Raises:

webob.exc.HTTPBadRequest – If both ‘sort’ and either ‘sort_key’ or ‘sort_dir’ are supplied parameters

get_time_comparison_operators() tuple[str, ...]

Get time comparison operators.

This method returns tuple which contains the allowed comparison operators.

limited(items: list, request: Request, max_limit: int | None = None) list

Return a slice of items according to requested offset and limit.

Parameters:
  • items – A sliceable entity

  • requestwsgi.Request possibly containing ‘offset’ and ‘limit’ GET variables. ‘offset’ is where to start in the list, and ‘limit’ is the maximum number of items to return. If ‘limit’ is not specified, 0, or > max_limit, we default to max_limit. Negative values for either offset or limit will cause exc.HTTPBadRequest() exceptions to be raised.

  • max_limit – The maximum number of items to return from ‘items’

process_general_filtering(resource)
reject_invalid_filters(context: context.RequestContext, filters, resource: str, enable_like_filter: bool = False)
remove_version_from_href(href: str) str

Removes the first API version from the href.

Given: ‘http://cinder.example.com/v1.1/123’ Returns: ‘http://cinder.example.com/123

Given: ‘http://cinder.example.com/v1.1’ Returns: ‘http://cinder.example.com

Given: ‘http://cinder.example.com/volume/drivers/v1.1/flashsystem’ Returns: ‘http://cinder.example.com/volume/drivers/flashsystem