Merge "Use RBAC_POLICY callback constant from neutron-lib"
This commit is contained in:
commit
29323bd87b
@ -168,9 +168,9 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
db_api.sqla_listen(models_v2.Port.status, 'set',
|
||||
self.nova_notifier.record_port_status_changed)
|
||||
|
||||
@registry.receives(rbac_mixin.RBAC_POLICY, [events.BEFORE_CREATE,
|
||||
events.BEFORE_UPDATE,
|
||||
events.BEFORE_DELETE])
|
||||
@registry.receives(resources.RBAC_POLICY, [events.BEFORE_CREATE,
|
||||
events.BEFORE_UPDATE,
|
||||
events.BEFORE_DELETE])
|
||||
@db_api.retry_if_session_inactive()
|
||||
def validate_network_rbac_policy_change(self, resource, event, trigger,
|
||||
context, object_type, policy,
|
||||
|
@ -152,7 +152,7 @@ class External_net_db_mixin(object):
|
||||
else:
|
||||
return nets[0]['id'] if nets else None
|
||||
|
||||
@registry.receives('rbac-policy', [events.BEFORE_CREATE])
|
||||
@registry.receives(resources.RBAC_POLICY, [events.BEFORE_CREATE])
|
||||
def _process_ext_policy_create(self, resource, event, trigger, context,
|
||||
object_type, policy, **kwargs):
|
||||
if (object_type != 'network' or
|
||||
@ -169,7 +169,7 @@ class External_net_db_mixin(object):
|
||||
{extnet_apidef.EXTERNAL: True},
|
||||
allow_all=False)
|
||||
|
||||
@registry.receives('rbac-policy', [events.AFTER_DELETE])
|
||||
@registry.receives(resources.RBAC_POLICY, [events.AFTER_DELETE])
|
||||
def _process_ext_policy_delete(self, resource, event, trigger, context,
|
||||
object_type, policy, **kwargs):
|
||||
if (object_type != 'network' or
|
||||
@ -186,8 +186,8 @@ class External_net_db_mixin(object):
|
||||
self._process_l3_update(context, net,
|
||||
{extnet_apidef.EXTERNAL: False})
|
||||
|
||||
@registry.receives('rbac-policy', (events.BEFORE_UPDATE,
|
||||
events.BEFORE_DELETE))
|
||||
@registry.receives(resources.RBAC_POLICY, (events.BEFORE_UPDATE,
|
||||
events.BEFORE_DELETE))
|
||||
def _validate_ext_not_in_use_by_tenant(self, resource, event, trigger,
|
||||
context, object_type, policy,
|
||||
**kwargs):
|
||||
|
@ -16,6 +16,7 @@
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import exceptions as c_exc
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import exceptions as n_exc
|
||||
from oslo_db import exception as db_exc
|
||||
from sqlalchemy.orm import exc
|
||||
@ -27,9 +28,6 @@ from neutron.db import common_db_mixin
|
||||
from neutron.db import rbac_db_models as models
|
||||
from neutron.extensions import rbac as ext_rbac
|
||||
|
||||
# resource name using in callbacks
|
||||
RBAC_POLICY = 'rbac-policy'
|
||||
|
||||
|
||||
class RbacPluginMixin(common_db_mixin.CommonDbMixin):
|
||||
"""Plugin mixin that implements the RBAC DB operations."""
|
||||
@ -41,7 +39,7 @@ class RbacPluginMixin(common_db_mixin.CommonDbMixin):
|
||||
def create_rbac_policy(self, context, rbac_policy):
|
||||
e = rbac_policy['rbac_policy']
|
||||
try:
|
||||
registry.notify(RBAC_POLICY, events.BEFORE_CREATE, self,
|
||||
registry.notify(resources.RBAC_POLICY, events.BEFORE_CREATE, self,
|
||||
context=context, object_type=e['object_type'],
|
||||
policy=e)
|
||||
except c_exc.CallbackFailure as e:
|
||||
@ -71,7 +69,7 @@ class RbacPluginMixin(common_db_mixin.CommonDbMixin):
|
||||
entry = self._get_rbac_policy(context, id)
|
||||
object_type = entry['object_type']
|
||||
try:
|
||||
registry.notify(RBAC_POLICY, events.BEFORE_UPDATE, self,
|
||||
registry.notify(resources.RBAC_POLICY, events.BEFORE_UPDATE, self,
|
||||
context=context, policy=entry,
|
||||
object_type=object_type, policy_update=pol)
|
||||
except c_exc.CallbackFailure as ex:
|
||||
@ -86,7 +84,7 @@ class RbacPluginMixin(common_db_mixin.CommonDbMixin):
|
||||
entry = self._get_rbac_policy(context, id)
|
||||
object_type = entry['object_type']
|
||||
try:
|
||||
registry.notify(RBAC_POLICY, events.BEFORE_DELETE, self,
|
||||
registry.notify(resources.RBAC_POLICY, events.BEFORE_DELETE, self,
|
||||
context=context, object_type=object_type,
|
||||
policy=entry)
|
||||
except c_exc.CallbackFailure as ex:
|
||||
@ -94,7 +92,7 @@ class RbacPluginMixin(common_db_mixin.CommonDbMixin):
|
||||
details=ex)
|
||||
with context.session.begin(subtransactions=True):
|
||||
context.session.delete(entry)
|
||||
registry.notify(RBAC_POLICY, events.AFTER_DELETE, self,
|
||||
registry.notify(resources.RBAC_POLICY, events.AFTER_DELETE, self,
|
||||
context=context, object_type=object_type,
|
||||
policy=entry)
|
||||
self.object_type_cache.pop(id, None)
|
||||
|
@ -17,6 +17,7 @@ import itertools
|
||||
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import exceptions as lib_exc
|
||||
from six import add_metaclass
|
||||
from six import with_metaclass
|
||||
@ -299,7 +300,7 @@ class RbacNeutronMetaclass(type):
|
||||
for e in (events.BEFORE_CREATE, events.BEFORE_UPDATE,
|
||||
events.BEFORE_DELETE):
|
||||
registry.subscribe(class_instance.validate_rbac_policy_change,
|
||||
rbac_db_mixin.RBAC_POLICY, e)
|
||||
resources.RBAC_POLICY, e)
|
||||
|
||||
@staticmethod
|
||||
def validate_existing_attrs(cls_name, dct):
|
||||
|
Loading…
x
Reference in New Issue
Block a user