Upload the contribution of vstf as bottleneck network framework.
[bottlenecks.git] / vstf / vstf / agent / env / vswitch_plugins / manager.py
1 """
2 Created on 2015-9-15
3
4 @author: y00228926
5 """
6 import stevedore
7
8
9 class VswitchPluginManager(object):
10     def __init__(self):
11         self.plugin = None
12         self.mgr = stevedore.extension.ExtensionManager(namespace="vswitch.plugins", invoke_on_load=True)
13
14     def clean(self):
15         if self.plugin:
16             self.plugin.clean()
17             self.plugin = None
18         for plugin in self.mgr.names():
19             self.mgr[plugin].obj.clean()
20         return True
21
22     def get_vs_plugin(self, plugin):
23         if plugin in self.mgr.names():
24             ext = self.mgr[plugin]
25             self.plugin = ext.obj
26             return self.plugin
27         else:
28             raise Exception("unsupported vswitch plugin: %s" % plugin)
29
30     def get_supported_plugins(self):
31         return self.mgr.names()