Pecan: Fix quota enforcement
Ensure that core resources, and not only extension resources,
are registered with the quota engine. Otherwise no enforcement
will happen for them.
Further, do not pass anymore the 'resource name' to the resource's
count method as it is not necessary anymore since Liberty.
Change-Id: I895b4e69e50dbf1aac39e07eba07c3e3ff30808a
Closes-bug: #1501948
(cherry picked from commit 809ac21615
)
This commit is contained in:
parent
fa2b18c45a
commit
d1d5f2a3bc
|
@ -18,7 +18,6 @@ from pecan import hooks
|
|||
|
||||
from neutron.common import exceptions
|
||||
from neutron import manager
|
||||
from neutron.pecan_wsgi.hooks import attribute_population
|
||||
from neutron import quota
|
||||
|
||||
|
||||
|
@ -45,8 +44,6 @@ class QuotaEnforcementHook(hooks.PecanHook):
|
|||
count = quota.QUOTAS.count(neutron_context,
|
||||
resource,
|
||||
plugin,
|
||||
attribute_population._plural(
|
||||
resource),
|
||||
tenant_id)
|
||||
delta = deltas.get(tenant_id, 0) + 1
|
||||
kwargs = {resource: count + delta}
|
||||
|
|
|
@ -22,6 +22,7 @@ from neutron.i18n import _LI, _LW
|
|||
from neutron import manager
|
||||
from neutron.pecan_wsgi.controllers import root
|
||||
from neutron import policy
|
||||
from neutron.quota import resource_registry
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
@ -100,6 +101,19 @@ def initialize_all():
|
|||
LOG.debug("There are already controllers for resource:%s",
|
||||
resource)
|
||||
|
||||
# NOTE(salv-orlando): If you are care about code quality, please read below
|
||||
# Hackiness is strong with the piece of code below. It is used for
|
||||
# populating resource plurals and registering resources with the quota
|
||||
# engine, but the method it calls were not coinceived with this aim.
|
||||
# Therefore it only leverages side-effects from those methods. Moreover,
|
||||
# as it is really not advisable to load an instance of
|
||||
# neutron.api.v2.router.APIRouter just to register resources with the
|
||||
# quota engine, core resources are explicitly registered here.
|
||||
# TODO(salv-orlando): The Pecan WSGI support should provide its own
|
||||
# solution to manage resource plurals and registration of resources with
|
||||
# the quota engine
|
||||
for resource in router.RESOURCES.keys():
|
||||
resource_registry.register_resource_by_name(resource)
|
||||
for ext in ext_mgr.extensions.values():
|
||||
# make each extension populate its plurals
|
||||
if hasattr(ext, 'get_resources'):
|
||||
|
|
Loading…
Reference in New Issue