From 6b4d59475fb8f4c3cd74632672665ae0c3ed12e2 Mon Sep 17 00:00:00 2001 From: Ethan Lynn Date: Thu, 14 Dec 2017 11:10:13 +0800 Subject: Make cloud provider plugin configurable 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 (cherry picked from commit 1ab719d0d310b0c0640eeeb4d1cf87dcae4c3168) --- multivimbroker/multivimbroker/forwarder/views.py | 35 +++++----------------- .../multivimbroker/pub/config/provider-plugin.json | 29 ++++++++++++++++++ multivimbroker/multivimbroker/pub/utils/syscomm.py | 24 +++++++-------- 3 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 multivimbroker/multivimbroker/pub/config/provider-plugin.json (limited to 'multivimbroker') diff --git a/multivimbroker/multivimbroker/forwarder/views.py b/multivimbroker/multivimbroker/forwarder/views.py index 59c566b..e098065 100644 --- a/multivimbroker/multivimbroker/forwarder/views.py +++ b/multivimbroker/multivimbroker/forwarder/views.py @@ -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 index 0000000..0ac4701 --- /dev/null +++ b/multivimbroker/multivimbroker/pub/config/provider-plugin.json @@ -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 diff --git a/multivimbroker/multivimbroker/pub/utils/syscomm.py b/multivimbroker/multivimbroker/pub/utils/syscomm.py index 7c5d94e..65039ae 100644 --- a/multivimbroker/multivimbroker/pub/utils/syscomm.py +++ b/multivimbroker/multivimbroker/pub/utils/syscomm.py @@ -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=""): -- cgit 1.2.3-korg