oslo_limit.limit module

class oslo_limit.limit.Enforcer(usage_callback, cache=True)

Bases: object

calculate_usage(project_id, resources_to_check)

Calculate resource usage and limits for resources_to_check.

From the list of resources_to_check, we collect the project’s limit and current usage for each, exactly like we would for enforce(). This is useful for reporting current project usage and limits in a situation where enforcement is not desired.

This should not be used to conduct custom enforcement, but rather only for reporting.

Parameters:
  • project_id (string) – The project for which to check usage and limits, or None.

  • resources_to_check (list) – A list of resource names to query.

Returns:

A dictionary of name:limit.ProjectUsage for the requested names against the provided project.

enforce(project_id, deltas)

Check resource usage against limits for resources in deltas

From the deltas we extract the list of resource types that need to have limits enforced on them.

From keystone we fetch limits relating to this project_id (if not None) and the endpoint specified in the configuration.

Using the usage_callback specified when creating the enforcer, we fetch the existing usage.

We then add the existing usage to the provided deltas to get the total proposed usage. This total proposed usage is then compared against all appropriate limits that apply.

Note if there are no registered limits for a given resource type, we fail the enforce in the same way as if we defaulted to a limit of zero, i.e. do not allow any use of a resource type that does not have a registered limit.

Note that if a project_id of None is provided, we just compare against the registered limits (i.e. use this for non-project-scoped limits)

Parameters:
  • project_id (string) – The project to check usage and enforce limits against (or None).

  • deltas (dictionary) – An dictionary containing resource names as keys and requests resource quantities as positive integers. We only check limits for resources in deltas. Specify a quantity of zero to check current usage.

Raises:

exception.ClaimExceedsLimit – when over limits

get_project_limits(project_id, resources_to_check)
get_registered_limits(resources_to_check)
class oslo_limit.limit.ProjectUsage(limit, usage)

Bases: tuple

limit

Alias for field number 0

usage

Alias for field number 1