Remove hard dependency on novaclient

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
This commit is contained in:
Terry Wilson 2014-05-20 10:58:32 -05:00
parent c28906c9e8
commit fb8f007243
2 changed files with 14 additions and 11 deletions

View File

@ -27,7 +27,6 @@ from neutron.api.v2 import attributes
from neutron.api.v2 import resource as wsgi_resource from neutron.api.v2 import resource as wsgi_resource
from neutron.common import constants as const from neutron.common import constants as const
from neutron.common import exceptions from neutron.common import exceptions
from neutron.notifiers import nova
from neutron.openstack.common import log as logging from neutron.openstack.common import log as logging
from neutron.openstack.common.notifier import api as notifier_api from neutron.openstack.common.notifier import api as notifier_api
from neutron import policy from neutron import policy
@ -77,6 +76,8 @@ class Controller(object):
agent_notifiers.get(const.AGENT_TYPE_DHCP) or agent_notifiers.get(const.AGENT_TYPE_DHCP) or
dhcp_rpc_agent_api.DhcpAgentNotifyAPI() dhcp_rpc_agent_api.DhcpAgentNotifyAPI()
) )
if cfg.CONF.notify_nova_on_port_data_changes:
from neutron.notifiers import nova
self._nova_notifier = nova.Notifier() 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()
@ -296,6 +297,10 @@ class Controller(object):
else: else:
self._dhcp_agent_notifier.notify(context, data, methodname) 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): def index(self, request, **kwargs):
"""Returns a list of the requested entity.""" """Returns a list of the requested entity."""
parent_id = kwargs.get(self._parent_id_name) parent_id = kwargs.get(self._parent_id_name)
@ -446,11 +451,10 @@ class Controller(object):
else: else:
kwargs.update({self._resource: body}) kwargs.update({self._resource: body})
obj = obj_creator(request.context, **kwargs) obj = obj_creator(request.context, **kwargs)
self._send_nova_notification(action, {},
self._nova_notifier.send_network_change( {self._resource: obj})
action, {}, {self._resource: obj}) return notify({self._resource: self._view(request.context,
return notify({self._resource: self._view( obj)})
request.context, obj)})
def delete(self, request, id, **kwargs): def delete(self, request, id, **kwargs):
"""Deletes the specified entity.""" """Deletes the specified entity."""
@ -484,7 +488,7 @@ class Controller(object):
notifier_api.CONF.default_notification_level, notifier_api.CONF.default_notification_level,
{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._nova_notifier.send_network_change(action, {}, result) self._send_nova_notification(action, {}, result)
self._send_dhcp_notification(request.context, self._send_dhcp_notification(request.context,
result, result,
notifier_method) notifier_method)
@ -545,8 +549,7 @@ class Controller(object):
self._send_dhcp_notification(request.context, self._send_dhcp_notification(request.context,
result, result,
notifier_method) notifier_method)
self._nova_notifier.send_network_change( self._send_nova_notification(action, orig_object_copy, result)
action, orig_object_copy, result)
return result return result
@staticmethod @staticmethod

View File

@ -33,7 +33,6 @@ from neutron.db import sqlalchemyutils
from neutron.extensions import l3 from neutron.extensions import l3
from neutron import manager from neutron import manager
from neutron import neutron_plugin_base_v2 from neutron import neutron_plugin_base_v2
from neutron.notifiers import nova
from neutron.openstack.common import excutils from neutron.openstack.common import excutils
from neutron.openstack.common import log as logging from neutron.openstack.common import log as logging
from neutron.openstack.common import uuidutils from neutron.openstack.common import uuidutils
@ -238,6 +237,7 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
def __init__(self): def __init__(self):
db.configure_db() db.configure_db()
if cfg.CONF.notify_nova_on_port_status_changes: 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 # NOTE(arosen) These event listners are here to hook into when
# port status changes and notify nova about their change. # port status changes and notify nova about their change.
self.nova_notifier = nova.Notifier() self.nova_notifier = nova.Notifier()