Merge "Extend address group notification data"

This commit is contained in:
Zuul 2021-01-19 03:02:41 +00:00 committed by Gerrit Code Review
commit d1d8c0f738
1 changed files with 24 additions and 10 deletions

View File

@ -96,6 +96,7 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
def add_addresses(self, context, address_group_id, addresses): def add_addresses(self, context, address_group_id, addresses):
ag = self._get_address_group(context, address_group_id) ag = self._get_address_group(context, address_group_id)
kwargs = {'original_address_group': self._make_address_group_dict(ag)}
addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses( addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses(
ag, addresses['addresses']) ag, addresses['addresses'])
if addrs_in_ag: if addrs_in_ag:
@ -108,16 +109,19 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
addr_assoc = ag_obj.AddressAssociation(context, **args) addr_assoc = ag_obj.AddressAssociation(context, **args)
addr_assoc.create() addr_assoc.create()
ag.update() # reload synthetic fields ag.update() # reload synthetic fields
ag_dict = {'address_group': self._make_address_group_dict(ag)}
kwargs.update(ag_dict)
# TODO(hangyang) this notification should be updated to publish when # TODO(hangyang) this notification should be updated to publish when
# the callback handler handle_event, class _ObjectChangeHandler in # the callback handler handle_event, class _ObjectChangeHandler in
# neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with
# new style payload objects as argument. # new style payload objects as argument.
registry.notify(ADDRESS_GROUP, events.AFTER_UPDATE, self, registry.notify(ADDRESS_GROUP, events.AFTER_UPDATE, self,
context=context, address_group_id=ag.id) context=context, **kwargs)
return {'address_group': self._make_address_group_dict(ag)} return ag_dict
def remove_addresses(self, context, address_group_id, addresses): def remove_addresses(self, context, address_group_id, addresses):
ag = self._get_address_group(context, address_group_id) ag = self._get_address_group(context, address_group_id)
kwargs = {'original_address_group': self._make_address_group_dict(ag)}
addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses( addrs_in_ag, addrs_not_in_ag = self._process_requested_addresses(
ag, addresses['addresses']) ag, addresses['addresses'])
if addrs_not_in_ag: if addrs_not_in_ag:
@ -127,13 +131,15 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
ag_obj.AddressAssociation.delete_objects( ag_obj.AddressAssociation.delete_objects(
context, address_group_id=address_group_id, address=addr) context, address_group_id=address_group_id, address=addr)
ag.update() # reload synthetic fields ag.update() # reload synthetic fields
ag_dict = {'address_group': self._make_address_group_dict(ag)}
kwargs.update(ag_dict)
# TODO(hangyang) this notification should be updated to publish when # TODO(hangyang) this notification should be updated to publish when
# the callback handler handle_event, class _ObjectChangeHandler in # the callback handler handle_event, class _ObjectChangeHandler in
# neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with
# new style payload objects as argument. # new style payload objects as argument.
registry.notify(ADDRESS_GROUP, events.AFTER_UPDATE, self, registry.notify(ADDRESS_GROUP, events.AFTER_UPDATE, self,
context=context, address_group_id=ag.id) context=context, **kwargs)
return {'address_group': self._make_address_group_dict(ag)} return ag_dict
def create_address_group(self, context, address_group): def create_address_group(self, context, address_group):
"""Create an address group.""" """Create an address group."""
@ -144,12 +150,15 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
'description': fields['description']} 'description': fields['description']}
ag = ag_obj.AddressGroup(context, **args) ag = ag_obj.AddressGroup(context, **args)
ag.create() ag.create()
kwargs = {'address_group': self._make_address_group_dict(ag)}
# TODO(mlavalle) this notification should be updated to publish when # TODO(mlavalle) this notification should be updated to publish when
# the callback handler handle_event, class _ObjectChangeHandler in # the callback handler handle_event, class _ObjectChangeHandler in
# neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with
# new style payload objects as argument. # new style payload objects as argument.
registry.notify(ADDRESS_GROUP, events.AFTER_CREATE, self, registry.notify(ADDRESS_GROUP, events.AFTER_CREATE, self,
context=context, address_group_id=ag.id) context=context, **kwargs)
# NOTE(hangyang): after sent the create notification we then handle
# adding addresses which will send another update notification
if fields.get('addresses') is not constants.ATTR_NOT_SPECIFIED: if fields.get('addresses') is not constants.ATTR_NOT_SPECIFIED:
self.add_addresses(context, ag.id, fields) self.add_addresses(context, ag.id, fields)
ag.update() # reload synthetic fields ag.update() # reload synthetic fields
@ -158,15 +167,18 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
def update_address_group(self, context, id, address_group): def update_address_group(self, context, id, address_group):
fields = address_group['address_group'] fields = address_group['address_group']
ag = self._get_address_group(context, id) ag = self._get_address_group(context, id)
kwargs = {'original_address_group': self._make_address_group_dict(ag)}
ag.update_fields(fields) ag.update_fields(fields)
ag.update() ag.update()
ag_dict = self._make_address_group_dict(ag)
kwargs['address_group'] = ag_dict
# TODO(mlavalle) this notification should be updated to publish when # TODO(mlavalle) this notification should be updated to publish when
# the callback handler handle_event, class _ObjectChangeHandler in # the callback handler handle_event, class _ObjectChangeHandler in
# neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with
# new style payload objects as argument. # new style payload objects as argument.
registry.notify(ADDRESS_GROUP, events.AFTER_UPDATE, self, registry.notify(ADDRESS_GROUP, events.AFTER_UPDATE, self,
context=context, address_group_id=ag.id) context=context, **kwargs)
return self._make_address_group_dict(ag) return ag_dict
def get_address_group(self, context, id, fields=None): def get_address_group(self, context, id, fields=None):
ag = self._get_address_group(context, id) ag = self._get_address_group(context, id)
@ -188,11 +200,13 @@ class AddressGroupDbMixin(ag_ext.AddressGroupPluginBase):
remote_address_group_id=id): remote_address_group_id=id):
# TODO(hangyang): use exception from neutron_lib # TODO(hangyang): use exception from neutron_lib
raise AddressGroupInUse(address_group_id=id) raise AddressGroupInUse(address_group_id=id)
address_group = self._get_address_group(context, id) ag = self._get_address_group(context, id)
address_group.delete() ag.delete()
kwargs = {'address_group_id': id, 'name': ag['name'],
'description': ag['description']}
# TODO(mlavalle) this notification should be updated to publish when # TODO(mlavalle) this notification should be updated to publish when
# the callback handler handle_event, class _ObjectChangeHandler in # the callback handler handle_event, class _ObjectChangeHandler in
# neutron.plugins.ml2.ovo_rpc is updated to receive notifications with # neutron.plugins.ml2.ovo_rpc is updated to receive notifications with
# new style payload objects as argument. # new style payload objects as argument.
registry.notify(ADDRESS_GROUP, events.AFTER_DELETE, self, registry.notify(ADDRESS_GROUP, events.AFTER_DELETE, self,
context=context, address_group_id=id) context=context, **kwargs)