# to a single node will be avaialable.
requested_resources = deltas.keys()
with db_api.autonested_transaction(context.session):
+ # get_tenant_quotes needs in input a dictionary mapping resource
+ # name to BaseResosurce instances so that the default quota can be
+ # retrieved
+ current_limits = self.get_tenant_quotas(
+ context, resources, tenant_id)
+ unlimited_resources = set([resource for (resource, limit) in
+ current_limits.items() if limit < 0])
+ # Do not even bother counting resources and calculating headroom
+ # for resources with unlimited quota
+ LOG.debug(("Resources %s have unlimited quota limit. It is not "
+ "required to calculated headroom "),
+ ",".join(unlimited_resources))
+ requested_resources = (set(requested_resources) -
+ unlimited_resources)
# Gather current usage information
# TODO(salv-orlando): calling count() for every resource triggers
# multiple queries on quota usage. This should be improved, however
(resource, resources[resource].count(
context, plugin, tenant_id, resync_usage=False)) for
resource in requested_resources)
- # get_tenant_quotes needs in inout a dictionary mapping resource
- # name to BaseResosurce instances so that the default quota can be
- # retrieved
- current_limits = self.get_tenant_quotas(
- context, resources, tenant_id)
# Adjust for expired reservations. Apparently it is cheaper than
# querying everytime for active reservations and counting overall
# quantity of resources reserved
for resource in requested_resources:
expired_reservations = expired_deltas.get(resource, 0)
total_usage = current_usages[resource] - expired_reservations
- # A negative quota limit means infinite
- if current_limits[resource] < 0:
- LOG.debug(("Resource %(resource)s has unlimited quota "
- "limit. It is possible to allocate %(delta)s "
- "items."), {'resource': resource,
- 'delta': deltas[resource]})
- continue
res_headroom = current_limits[resource] - total_usage
LOG.debug(("Attempting to reserve %(delta)d items for "
"resource %(resource)s. Total usage: %(total)d; "