summaryrefslogtreecommitdiffstats
path: root/openstack/common/plugin/callbackplugin.py
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2013-06-19 07:14:43 +0100
committerMark McLoughlin <markmc@redhat.com>2013-06-19 08:47:52 +0100
commit4b78868f4e062e3fd77ef14de3dcba4e2f864f7f (patch)
tree4db6436cb2e637ce8e2b7f9198ff8869e13d5d42 /openstack/common/plugin/callbackplugin.py
parent688832fd379776bf12f21f76c884caa42a48d2c5 (diff)
downloadoslo-4b78868f4e062e3fd77ef14de3dcba4e2f864f7f.tar.gz
oslo-4b78868f4e062e3fd77ef14de3dcba4e2f864f7f.tar.xz
oslo-4b78868f4e062e3fd77ef14de3dcba4e2f864f7f.zip
Remove the unused plugins framework
This framework was merged a year ago and AFAICT hasn't seen use beyond the two initial wikimedia extensions for Nova. The framework basically allows a way for a single plugin to register API extensions and notification hooks. Both of these can be done by directly using config opts like osapi_compute_extension and notification_driver so this framework really only helps if we expected to (and wanted to) lots of these plugins in the wild. Nova is the only project using this and we don't have an active maintainer listed in the MAINTAINERS file, so it seems like it's time to remove it from the incubator. Change-Id: I5552b5625e26f4821464807743545ec6f5117f2b
Diffstat (limited to 'openstack/common/plugin/callbackplugin.py')
-rw-r--r--openstack/common/plugin/callbackplugin.py93
1 files changed, 0 insertions, 93 deletions
diff --git a/openstack/common/plugin/callbackplugin.py b/openstack/common/plugin/callbackplugin.py
deleted file mode 100644
index 2de7fb0..0000000
--- a/openstack/common/plugin/callbackplugin.py
+++ /dev/null
@@ -1,93 +0,0 @@
-# Copyright 2012 OpenStack Foundation.
-# All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-
-from openstack.common import log as logging
-from openstack.common.plugin import plugin
-
-
-LOG = logging.getLogger(__name__)
-
-
-class _CallbackNotifier(object):
- """Manages plugin-defined notification callbacks.
-
- For each Plugin, a CallbackNotifier will be added to the
- notification driver list. Calls to notify() with appropriate
- messages will be hooked and prompt callbacks.
-
- A callback should look like this:
- def callback(context, message, user_data)
- """
-
- def __init__(self):
- self._callback_dict = {}
-
- def _add_callback(self, event_type, callback, user_data):
- callback_list = self._callback_dict.get(event_type, [])
- callback_list.append({'function': callback,
- 'user_data': user_data})
- self._callback_dict[event_type] = callback_list
-
- def _remove_callback(self, callback):
- for callback_list in self._callback_dict.values():
- for entry in callback_list:
- if entry['function'] == callback:
- callback_list.remove(entry)
-
- def notify(self, context, message):
- if message.get('event_type') not in self._callback_dict:
- return
-
- for entry in self._callback_dict[message.get('event_type')]:
- entry['function'](context, message, entry.get('user_data'))
-
- def callbacks(self):
- return self._callback_dict
-
-
-class CallbackPlugin(plugin.Plugin):
- """Plugin with a simple callback interface.
-
- This class is provided as a convenience for producing a simple
- plugin that only watches a couple of events. For example, here's
- a subclass which prints a line the first time an instance is created.
-
- class HookInstanceCreation(CallbackPlugin):
-
- def __init__(self, _service_name):
- super(HookInstanceCreation, self).__init__()
- self._add_callback(self.magic, 'compute.instance.create.start')
-
- def magic(self):
- print "An instance was created!"
- self._remove_callback(self, self.magic)
- """
-
- def __init__(self, service_name):
- super(CallbackPlugin, self).__init__(service_name)
- self._callback_notifier = _CallbackNotifier()
- self._add_notifier(self._callback_notifier)
-
- def _add_callback(self, callback, event_type, user_data=None):
- """Add callback for a given event notification.
-
- Subclasses can call this as an alternative to implementing
- a fullblown notify notifier.
- """
- self._callback_notifier._add_callback(event_type, callback, user_data)
-
- def _remove_callback(self, callback):
- """Remove all notification callbacks to specified function."""
- self._callback_notifier._remove_callback(callback)