Merge "Use parent's project id in the quota enforcement for some resources"
This commit is contained in:
commit
9089232090
@ -15,12 +15,14 @@
|
||||
|
||||
import collections
|
||||
|
||||
from neutron_lib import context
|
||||
from neutron_lib.db import api as db_api
|
||||
from neutron_lib import exceptions
|
||||
from oslo_log import log as logging
|
||||
from pecan import hooks
|
||||
|
||||
from neutron import manager
|
||||
from neutron.pecan_wsgi.hooks import utils
|
||||
from neutron import quota
|
||||
from neutron.quota import resource_registry
|
||||
|
||||
@ -38,8 +40,19 @@ class QuotaEnforcementHook(hooks.PecanHook):
|
||||
if state.request.method != 'POST' or not resource or not items:
|
||||
return
|
||||
plugin = manager.NeutronManager.get_plugin_for_resource(collection)
|
||||
parent_id = state.request.context.get('parent_id')
|
||||
parent_project_id = None
|
||||
if parent_id and any(not x.get('tenant_id') for x in items):
|
||||
parent_getter = getattr(
|
||||
plugin, 'get_%s' % utils.get_controller(state).parent)
|
||||
try:
|
||||
parent_project_id = parent_getter(
|
||||
context.get_admin_context(), parent_id).get('project_id')
|
||||
except exceptions.NotFound:
|
||||
pass
|
||||
# Store requested resource amounts grouping them by tenant
|
||||
deltas = collections.Counter(map(lambda x: x['tenant_id'], items))
|
||||
deltas = collections.Counter(
|
||||
map(lambda x: x.get('tenant_id', parent_project_id), items))
|
||||
# Perform quota enforcement
|
||||
reservations = []
|
||||
neutron_context = state.request.context.get('neutron_context')
|
||||
|
Loading…
Reference in New Issue
Block a user