Merge "Move Nova notification logic out of API controller"
This commit is contained in:
commit
080bf68895
@ -18,7 +18,6 @@ import copy
|
|||||||
|
|
||||||
import netaddr
|
import netaddr
|
||||||
from neutron_lib import exceptions
|
from neutron_lib import exceptions
|
||||||
from oslo_config import cfg
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
from oslo_policy import policy as oslo_policy
|
from oslo_policy import policy as oslo_policy
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
@ -90,9 +89,6 @@ class Controller(object):
|
|||||||
self._policy_attrs = [name for (name, info) in self._attr_info.items()
|
self._policy_attrs = [name for (name, info) in self._attr_info.items()
|
||||||
if info.get('required_by_policy')]
|
if info.get('required_by_policy')]
|
||||||
self._notifier = n_rpc.get_notifier('network')
|
self._notifier = n_rpc.get_notifier('network')
|
||||||
if cfg.CONF.notify_nova_on_port_data_changes:
|
|
||||||
from neutron.notifiers import nova
|
|
||||||
self._nova_notifier = nova.Notifier()
|
|
||||||
self._member_actions = member_actions
|
self._member_actions = member_actions
|
||||||
self._primary_key = self._get_primary_key()
|
self._primary_key = self._get_primary_key()
|
||||||
if self._allow_pagination and self._native_pagination:
|
if self._allow_pagination and self._native_pagination:
|
||||||
@ -327,10 +323,6 @@ class Controller(object):
|
|||||||
pluralized=self._collection)
|
pluralized=self._collection)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def _send_nova_notification(self, action, orig, returned):
|
|
||||||
if hasattr(self, '_nova_notifier'):
|
|
||||||
self._nova_notifier.send_network_change(action, orig, returned)
|
|
||||||
|
|
||||||
@db_api.retry_db_errors
|
@db_api.retry_db_errors
|
||||||
def index(self, request, **kwargs):
|
def index(self, request, **kwargs):
|
||||||
"""Returns a list of the requested entity."""
|
"""Returns a list of the requested entity."""
|
||||||
@ -473,7 +465,8 @@ class Controller(object):
|
|||||||
registry.notify(self._resource, events.BEFORE_RESPONSE, self,
|
registry.notify(self._resource, events.BEFORE_RESPONSE, self,
|
||||||
context=request.context, data=create_result,
|
context=request.context, data=create_result,
|
||||||
method_name=notifier_method,
|
method_name=notifier_method,
|
||||||
collection=self._collection)
|
collection=self._collection,
|
||||||
|
action=action, original={})
|
||||||
return create_result
|
return create_result
|
||||||
|
|
||||||
def do_create(body, bulk=False, emulated=False):
|
def do_create(body, bulk=False, emulated=False):
|
||||||
@ -519,8 +512,6 @@ class Controller(object):
|
|||||||
return notify({self._collection: objs})
|
return notify({self._collection: objs})
|
||||||
else:
|
else:
|
||||||
obj = do_create(body)
|
obj = do_create(body)
|
||||||
self._send_nova_notification(action, {},
|
|
||||||
{self._resource: obj})
|
|
||||||
return notify({self._resource: self._view(request.context,
|
return notify({self._resource: self._view(request.context,
|
||||||
obj)})
|
obj)})
|
||||||
|
|
||||||
@ -563,10 +554,10 @@ class Controller(object):
|
|||||||
notifier_method,
|
notifier_method,
|
||||||
{self._resource + '_id': id})
|
{self._resource + '_id': id})
|
||||||
result = {self._resource: self._view(request.context, obj)}
|
result = {self._resource: self._view(request.context, obj)}
|
||||||
self._send_nova_notification(action, {}, result)
|
|
||||||
registry.notify(self._resource, events.BEFORE_RESPONSE, self,
|
registry.notify(self._resource, events.BEFORE_RESPONSE, self,
|
||||||
context=request.context, data=result,
|
context=request.context, data=result,
|
||||||
method_name=notifier_method)
|
method_name=notifier_method, action=action,
|
||||||
|
original={})
|
||||||
|
|
||||||
def update(self, request, id, body=None, **kwargs):
|
def update(self, request, id, body=None, **kwargs):
|
||||||
"""Updates the specified entity's attributes."""
|
"""Updates the specified entity's attributes."""
|
||||||
@ -637,8 +628,8 @@ class Controller(object):
|
|||||||
self._notifier.info(request.context, notifier_method, result)
|
self._notifier.info(request.context, notifier_method, result)
|
||||||
registry.notify(self._resource, events.BEFORE_RESPONSE, self,
|
registry.notify(self._resource, events.BEFORE_RESPONSE, self,
|
||||||
context=request.context, data=result,
|
context=request.context, data=result,
|
||||||
method_name=notifier_method)
|
method_name=notifier_method, action=action,
|
||||||
self._send_nova_notification(action, orig_object_copy, result)
|
original=orig_object_copy)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -23,6 +23,9 @@ from oslo_utils import uuidutils
|
|||||||
from sqlalchemy.orm import attributes as sql_attr
|
from sqlalchemy.orm import attributes as sql_attr
|
||||||
|
|
||||||
from neutron._i18n import _LE, _LI, _LW
|
from neutron._i18n import _LE, _LI, _LW
|
||||||
|
from neutron.callbacks import events
|
||||||
|
from neutron.callbacks import registry
|
||||||
|
from neutron.callbacks import resources
|
||||||
from neutron import context
|
from neutron import context
|
||||||
from neutron import manager
|
from neutron import manager
|
||||||
from neutron.notifiers import batch_notifier
|
from neutron.notifiers import batch_notifier
|
||||||
@ -68,6 +71,15 @@ class Notifier(object):
|
|||||||
self.batch_notifier = batch_notifier.BatchNotifier(
|
self.batch_notifier = batch_notifier.BatchNotifier(
|
||||||
cfg.CONF.send_events_interval, self.send_events)
|
cfg.CONF.send_events_interval, self.send_events)
|
||||||
|
|
||||||
|
# register callbacks for events pertaining resources affecting Nova
|
||||||
|
callback_resources = (
|
||||||
|
resources.FLOATING_IP,
|
||||||
|
resources.PORT,
|
||||||
|
)
|
||||||
|
for resource in callback_resources:
|
||||||
|
registry.subscribe(self._send_nova_notification,
|
||||||
|
resource, events.BEFORE_RESPONSE)
|
||||||
|
|
||||||
def _is_compute_port(self, port):
|
def _is_compute_port(self, port):
|
||||||
try:
|
try:
|
||||||
if (port['device_id'] and uuidutils.is_uuid_like(port['device_id'])
|
if (port['device_id'] and uuidutils.is_uuid_like(port['device_id'])
|
||||||
@ -96,6 +108,11 @@ class Notifier(object):
|
|||||||
self._plugin_ref = manager.NeutronManager.get_plugin()
|
self._plugin_ref = manager.NeutronManager.get_plugin()
|
||||||
return self._plugin_ref
|
return self._plugin_ref
|
||||||
|
|
||||||
|
def _send_nova_notification(self, resource, event, trigger,
|
||||||
|
action=None, original=None, data=None,
|
||||||
|
**kwargs):
|
||||||
|
self.send_network_change(action, original, data)
|
||||||
|
|
||||||
def send_network_change(self, action, original_obj,
|
def send_network_change(self, action, original_obj,
|
||||||
returned_obj):
|
returned_obj):
|
||||||
"""Called when a network change is made that nova cares about.
|
"""Called when a network change is made that nova cares about.
|
||||||
|
Loading…
Reference in New Issue
Block a user