aboutsummaryrefslogtreecommitdiffstats
path: root/Testcases/cfgm_common/vnc_extensions.py
diff options
context:
space:
mode:
authorStuart Mackie <wsmackie@juniper.net>2016-01-29 16:00:57 -0800
committerStuart Mackie <wsmackie@juniper.net>2016-01-29 16:00:57 -0800
commit82f1a7eb5535b30a95b1e71ff18c315d40d1e6f0 (patch)
treef930c90f75846ec8d8e33cf27325ff8fafc85d5c /Testcases/cfgm_common/vnc_extensions.py
parent5c04f2e22eb6b5e7a671bc02ba53a438eb66e90d (diff)
OpenContrail test suitestable/colorado
Change-Id: I61168093a2a05d47377ef47c8638ae1554b1a999 Signed-off-by: Stuart Mackie <wsmackie@juniper.net>
Diffstat (limited to 'Testcases/cfgm_common/vnc_extensions.py')
-rw-r--r--Testcases/cfgm_common/vnc_extensions.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/Testcases/cfgm_common/vnc_extensions.py b/Testcases/cfgm_common/vnc_extensions.py
new file mode 100644
index 0000000..cebbe4d
--- /dev/null
+++ b/Testcases/cfgm_common/vnc_extensions.py
@@ -0,0 +1,65 @@
+#
+# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
+#
+
+import functools
+
+import stevedore
+
+
+class ApiHookManager(stevedore.hook.HookManager):
+ def __init__(self, namespace, hook_name):
+ super(ApiHookManager, self).__init__(namespace, hook_name,
+ invoke_on_load=True)
+ #end __init__
+
+ def run_pre(self, hook_name, args, kwargs):
+ for e in self.extensions:
+ obj = e.obj
+ pre = getattr(obj, 'pre', None)
+ if pre:
+ pre(*args, **kwargs)
+ #end run_pre
+
+ def run_post(self, hook_name, rv, args, kwargs):
+ for e in reversed(self.extensions):
+ obj = e.obj
+ post = getattr(obj, 'post', None)
+ if post:
+ post(rv, *args, **kwargs)
+ #end run_post
+#end class ApiHookManager
+
+
+def add_api_hook(hook_manager, hook_name):
+ def outer(f):
+ @functools.wraps(f)
+ def inner(*args, **kwargs):
+ hook_manager.run_pre(hook_name, args, kwargs)
+ rv = f(*args, **kwargs)
+ hook_manager.run_post(hook_name, rv, args, kwargs)
+
+ return rv
+
+ return inner
+ #end inner
+ #end outer
+
+ return outer
+#end add_api_hook
+
+
+class ExtensionManager(stevedore.extension.ExtensionManager):
+ def __init__(self, namespace, api_server_ip,
+ api_server_port, conf_sections, sandesh,
+ propagate_map_exceptions=False):
+ super(ExtensionManager, self).__init__(
+ namespace, invoke_on_load=True,
+ invoke_kwds={'api_server_ip': api_server_ip,
+ 'api_server_port': api_server_port,
+ 'conf_sections': conf_sections,
+ 'sandesh': sandesh },
+ propagate_map_exceptions=propagate_map_exceptions)
+ #end __init__
+
+#end class ExtensionManager