Use singleton for Nova notifier
By adding a singleton getter method and using it in the places that use nova notifiers, we ensure that only one object exists so all callers share the same batching queues and the sqlalchemy events will only be fired once. Change-Id: I89752d9c69feb578f0294339aae1a5cf51ec124b Closes-Bug: #1622503
This commit is contained in:
parent
80c1a6b981
commit
dfbc809169
@ -130,7 +130,7 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
|
||||
from neutron.notifiers import nova
|
||||
# NOTE(arosen) These event listeners are here to hook into when
|
||||
# port status changes and notify nova about their change.
|
||||
self.nova_notifier = nova.Notifier()
|
||||
self.nova_notifier = nova.Notifier.get_instance()
|
||||
event.listen(models_v2.Port, 'after_insert',
|
||||
self.nova_notifier.send_port_status)
|
||||
event.listen(models_v2.Port, 'after_update',
|
||||
|
@ -45,14 +45,15 @@ NOVA_API_VERSION = "2"
|
||||
|
||||
class Notifier(object):
|
||||
|
||||
_instance = None
|
||||
|
||||
@classmethod
|
||||
def get_instance(cls):
|
||||
if cls._instance is None:
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
# FIXME(jamielennox): A notifier is being created for each Controller
|
||||
# and each Notifier is handling it's own auth. That means that we are
|
||||
# authenticating the exact same thing len(controllers) times. This
|
||||
# should be an easy thing to optimize.
|
||||
# FIXME(kevinbenton): remove this comment and the one above once the
|
||||
# switch to pecan is complete since only one notifier is constructed
|
||||
# in the pecan notification hook.
|
||||
auth = ks_loading.load_auth_from_conf_options(cfg.CONF, 'nova')
|
||||
|
||||
session = ks_loading.load_session_from_conf_options(
|
||||
|
@ -43,7 +43,7 @@ class NotifierHook(hooks.PecanHook):
|
||||
# this is scoped to avoid a dependency on nova client when nova
|
||||
# notifications aren't enabled
|
||||
from neutron.notifiers import nova
|
||||
self._nova_notifier = nova.Notifier()
|
||||
self._nova_notifier = nova.Notifier.get_instance()
|
||||
self._nova_notifier.send_network_change(action_resource, *args)
|
||||
|
||||
def _notify_dhcp_agent(self, context, resource_name, action, resources):
|
||||
|
Loading…
x
Reference in New Issue
Block a user