]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove hard dependency on novaclient
authorTerry Wilson <twilson@redhat.com>
Tue, 20 May 2014 15:58:32 +0000 (10:58 -0500)
committerTerry Wilson <twilson@redhat.com>
Tue, 20 May 2014 17:28:59 +0000 (12:28 -0500)
The nova notification patch introduces a hard dependency on
novaclient when it is a runtime-configurable dependency. The
import from novaclient should be conditional on the
appropriate nova notification options being enabled in the
config.

Change-Id: I2ef4bfa4d53afc7e8c800ad8e2a8737e117af238
Closes-Bug: #1321352

neutron/api/v2/base.py
neutron/db/db_base_plugin_v2.py

index c9df5d3fb0375691410f5d4c02d5fe6b88278a97..5692df01b9cd2fc2102ff4ba50b8dd49bf3cdeb4 100644 (file)
@@ -27,7 +27,6 @@ from neutron.api.v2 import attributes
 from neutron.api.v2 import resource as wsgi_resource
 from neutron.common import constants as const
 from neutron.common import exceptions
-from neutron.notifiers import nova
 from neutron.openstack.common import log as logging
 from neutron.openstack.common.notifier import api as notifier_api
 from neutron import policy
@@ -77,7 +76,9 @@ class Controller(object):
             agent_notifiers.get(const.AGENT_TYPE_DHCP) or
             dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
         )
-        self._nova_notifier = nova.Notifier()
+        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._primary_key = self._get_primary_key()
         if self._allow_pagination and self._native_pagination:
@@ -296,6 +297,10 @@ class Controller(object):
             else:
                 self._dhcp_agent_notifier.notify(context, data, methodname)
 
+    def _send_nova_notification(self, action, orig, returned):
+        if hasattr(self, '_nova_notifier'):
+            self._nova_notifier.send_network_change(action, orig, returned)
+
     def index(self, request, **kwargs):
         """Returns a list of the requested entity."""
         parent_id = kwargs.get(self._parent_id_name)
@@ -446,11 +451,10 @@ class Controller(object):
             else:
                 kwargs.update({self._resource: body})
                 obj = obj_creator(request.context, **kwargs)
-
-                self._nova_notifier.send_network_change(
-                    action, {}, {self._resource: obj})
-                return notify({self._resource: self._view(
-                    request.context, obj)})
+                self._send_nova_notification(action, {},
+                                             {self._resource: obj})
+                return notify({self._resource: self._view(request.context,
+                                                          obj)})
 
     def delete(self, request, id, **kwargs):
         """Deletes the specified entity."""
@@ -484,7 +488,7 @@ class Controller(object):
                             notifier_api.CONF.default_notification_level,
                             {self._resource + '_id': id})
         result = {self._resource: self._view(request.context, obj)}
-        self._nova_notifier.send_network_change(action, {}, result)
+        self._send_nova_notification(action, {}, result)
         self._send_dhcp_notification(request.context,
                                      result,
                                      notifier_method)
@@ -545,8 +549,7 @@ class Controller(object):
         self._send_dhcp_notification(request.context,
                                      result,
                                      notifier_method)
-        self._nova_notifier.send_network_change(
-            action, orig_object_copy, result)
+        self._send_nova_notification(action, orig_object_copy, result)
         return result
 
     @staticmethod
index 7cfda75fa7bf2de0310c0707182d18a9b6686370..cf65c954bfb69b63f04a62477e543a23e7378b20 100644 (file)
@@ -33,7 +33,6 @@ from neutron.db import sqlalchemyutils
 from neutron.extensions import l3
 from neutron import manager
 from neutron import neutron_plugin_base_v2
-from neutron.notifiers import nova
 from neutron.openstack.common import excutils
 from neutron.openstack.common import log as logging
 from neutron.openstack.common import uuidutils
@@ -238,6 +237,7 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
     def __init__(self):
         db.configure_db()
         if cfg.CONF.notify_nova_on_port_status_changes:
+            from neutron.notifiers import nova
             # NOTE(arosen) These event listners are here to hook into when
             # port status changes and notify nova about their change.
             self.nova_notifier = nova.Notifier()