from PLC.Slices import Slice, Slices
from PLC.Persons import Person, Persons
from PLC.Auth import Auth
-from PLC.Plugins import PluginManager
class AddSliceToNodes(Method):
"""
'Slice': [slice['slice_id']]}
self.message = 'Slice %d added to nodes %s' % (slice['slice_id'], nodeids)
- PluginManager(self.api, auth).notify("slice.AddToNodes", self.event_objects)
-
return 1
from PLC.Nodes import Node, Nodes
from PLC.Slices import Slice, Slices
from PLC.Auth import Auth
-from PLC.Plugins import PluginManager
class DeleteSliceFromNodes(Method):
"""
self.event_objects = {'Node': [node['node_id'] for node in nodes],
'Slice': [slice['slice_id']]}
- PluginManager(self.api, auth).notify("slice.DeleteFromNodes", self.event_objects)
-
return 1
+++ /dev/null
-import sys
-import pkg_resources
-import traceback
-
-from PLC.Debug import log
-
-"""
-from PLC.Plugins import PluginManager
-pm = PluginManager(None, None)
-pm.dump()
-pm.notify("who", {"what": "this!"})
-"""
-
-class PluginManager:
- def __init__(self, api, auth):
- self.api = api
- self.auth = auth
- self.plugins = []
-
- for entrypoint in pkg_resources.iter_entry_points("plcapi.plugin","api_notify"):
- save = sys.path
- try:
- # pkg_resources looks for modules in sys.path. Make sure it can
- # find our plugins.
- sys.path.append("/usr/share/plc_api")
-
- try:
- pluginclass = entrypoint.load()
- plugin = pluginclass()
- self.plugins.append(plugin)
- except Exception, exc:
- print >>log, "WARNING: failed to load plugin %s" % str(entrypoint)
- traceback.print_exc(5,log)
- finally:
- sys.path = save
-
- def notify(self, action, info={}):
- for plugin in self.plugins:
- try:
- plugin.notify(self.api, self.auth, action, info)
- except Exception, exc:
- print >>log, "WARNING: failed to run plugin during action %s" % str(action)
- traceback.print_exc(5,log)
-
- def dump(self):
- for plugin in self.plugins:
- print plugin.__class__.__name__
-