Make cloud provider plugin configurable 85/26285/4
authorEthan Lynn <ethanlynnl@vmware.com>
Thu, 14 Dec 2017 03:10:13 +0000 (11:10 +0800)
committerEthan Lynn <ethanlynnl@vmware.com>
Thu, 14 Dec 2017 08:08:24 +0000 (16:08 +0800)
The cloud provider plugin info stores in
pub/config/provider-plugin.json, by editing this file other
plugin provider can easily add a new plugin.

Change-Id: I499fb05758e76eb2bda6bb4e9fafd302e810dddc
Issue-ID: MULTICLOUD-132
Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
multivimbroker/multivimbroker/forwarder/views.py
multivimbroker/multivimbroker/pub/config/provider-plugin.json [new file with mode: 0644]
multivimbroker/multivimbroker/pub/utils/syscomm.py

index 59c566b..e098065 100644 (file)
@@ -12,6 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
+import json
+
 from rest_framework.views import APIView
 from rest_framework.views import Response
 from rest_framework.views import status
@@ -79,33 +82,11 @@ class VIMTypes(BaseServer):
 
     def get(self, request):
         # Fix here unless we have plugin registry
-        data = {
-            "vim_types": [
-                {
-                    "vim_type": "openstack",
-                    "versions": [
-                        {
-                            "version": "titanium_cloud",
-                            "extra_info_hint": ""
-                        },
-                        {
-                            "version": "ocata",
-                            "extra_info_hint": ""
-                        }
-                    ]
-                },
-                {
-                    "vim_type": "vmware",
-                    "versions": [
-                        {
-                            "version": "4.0",
-                            "extra_info_hint": ""
-                        }
-                    ]
-                }
-            ]
-        }
-
+        json_file = os.path.join(os.path.dirname(__file__),
+                                 '../pub/config/provider-plugin.json')
+        with open(json_file, "r") as f:
+            plugins = json.load(f)
+        data = {"vim_types": plugins}
         return Response(data=data, status=status.HTTP_200_OK)
 
 
diff --git a/multivimbroker/multivimbroker/pub/config/provider-plugin.json b/multivimbroker/multivimbroker/pub/config/provider-plugin.json
new file mode 100644 (file)
index 0000000..0ac4701
--- /dev/null
@@ -0,0 +1,29 @@
+{
+    "openstack": {
+        "vim_type": "openstack",
+        "versions": {
+            "titanium_cloud": {
+                "version": "titanium_cloud",
+                "extra_info_hint": "",
+                "provider_plugin": "multicloud-titanium_cloud"
+            },
+            "ocata": {
+                "version": "ocata",
+                "extra_info_hint": "",
+                "provider_plugin": "multicloud-ocata"
+            }
+        },
+        "provider_plugin": "multicloud-ocata"
+    },
+    "vmware": {
+        "vim_type": "vmware",
+        "versions": {
+            "4.0": {
+                "version": "4.0",
+                "extra_info_hint": "",
+                "provider_plugin": "multicloud-vio"
+            }
+        },
+        "provider_plugin": "multicloud-vio"
+    }
+}
\ No newline at end of file
index 7c5d94e..65039ae 100644 (file)
@@ -10,6 +10,8 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
 import inspect
+import json
+import os
 import re
 
 import multivimbroker.pub.exceptions as exceptions
@@ -34,20 +36,16 @@ def getHeadersKeys(response):
 
 
 def findMultivimDriver(vim=None):
-
-    if vim and vim["type"] == "openstack":
-        if vim["version"] == "ocata":
-            multivimdriver = "multicloud-ocata"
-        elif vim["version"] == "titanium_cloud":
-            multivimdriver = "multicloud-titanium_cloud"
-        else:
-            # if vim type is openstack, use "ocata" version as default
-            multivimdriver = "multicloud-ocata"
-    elif vim and vim["type"] == "vmware":
-            multivimdriver = "multicloud-vio"
-    else:
+    json_file = os.path.join(os.path.dirname(__file__),
+                             '../config/provider-plugin.json')
+    with open(json_file, "r") as f:
+        plugins = json.load(f)
+    if not vim or vim.get("type") not in plugins.keys():
         raise exceptions.NotFound("Not support VIM type")
-    return multivimdriver
+    plugin = plugins[vim["type"]]
+    if vim.get("version") in plugin["versions"].keys():
+        return plugin["versions"][vim["version"]]["provider_plugin"]
+    return plugin["provider_plugin"]
 
 
 def getMultivimDriver(vimid, full_path=""):