Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / 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
15     def __init__(self):
16         self.plugin = None
17         self.mgr = stevedore.extension.ExtensionManager(
18             namespace="vswitch.plugins", invoke_on_load=True)
19
20     def clean(self):
21         if self.plugin:
22             self.plugin.clean()
23             self.plugin = None
24         for plugin in self.mgr.names():
25             self.mgr[plugin].obj.clean()
26         return True
27
28     def get_vs_plugin(self, plugin):
29         if plugin in self.mgr.names():
30             ext = self.mgr[plugin]
31             self.plugin = ext.obj
32             return self.plugin
33         else:
34             raise Exception("unsupported vswitch plugin: %s" % plugin)
35
36     def get_supported_plugins(self):
37         return self.mgr.names()