Migrate get vim_types to new framework
[multicloud/framework.git] / multivimbroker / multivimbroker / pub / utils / syscomm.py
index 65039ae..337a1bd 100644 (file)
@@ -1,4 +1,5 @@
 # Copyright (c) 2017 Wind River Systems, Inc.
+# Copyright (c) 2017-2018 VMware, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -35,6 +36,14 @@ def getHeadersKeys(response):
     return [header for header in response.keys() if header not in hopbyhop]
 
 
+# trim out 'HTTP_' prefix part and replace "_" wiht "-".
+def originHeaders(request):
+    regex = re.compile('^HTTP_')
+    return dict((regex.sub('', header).replace("_", "-"), value)
+                for (header, value) in request.META.items()
+                if header.startswith('HTTP_'))
+
+
 def findMultivimDriver(vim=None):
     json_file = os.path.join(os.path.dirname(__file__),
                              '../config/provider-plugin.json')
@@ -53,3 +62,19 @@ def getMultivimDriver(vimid, full_path=""):
     vim = get_vim_by_id(vimid)
     multclouddriver = findMultivimDriver(vim=vim)
     return re.sub(multcloud, multclouddriver, full_path)
+
+
+def getVIMTypes():
+        # Fix here unless we have plugin registry
+        json_file = os.path.join(os.path.dirname(__file__),
+                                 '../config/provider-plugin.json')
+        with open(json_file, "r") as f:
+            plugins = json.load(f)
+        ret = []
+        for k, v in plugins.items():
+            item = {}
+            item["vim_type"] = v.get("vim_type")
+            item["versions"] = [k for k in v.get('versions', {})]
+            ret.append(item)
+
+        return ret