JIRA: BOTTLENECKS-29
[bottlenecks.git] / vstf / vstf / agent / env / vswitch_plugins / manager.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 import stevedore
11
12
13 class VswitchPluginManager(object):
14     def __init__(self):
15         self.plugin = None
16         self.mgr = stevedore.extension.ExtensionManager(namespace="vswitch.plugins", invoke_on_load=True)
17
18     def clean(self):
19         if self.plugin:
20             self.plugin.clean()
21             self.plugin = None
22         for plugin in self.mgr.names():
23             self.mgr[plugin].obj.clean()
24         return True
25
26     def get_vs_plugin(self, plugin):
27         if plugin in self.mgr.names():
28             ext = self.mgr[plugin]
29             self.plugin = ext.obj
30             return self.plugin
31         else:
32             raise Exception("unsupported vswitch plugin: %s" % plugin)
33
34     def get_supported_plugins(self):
35         return self.mgr.names()