summaryrefslogtreecommitdiffstats
path: root/multivimbroker
diff options
context:
space:
mode:
authorEthan Lynn <ethanlynnl@vmware.com>2017-12-14 11:10:13 +0800
committerEthan Lynn <ethanlynnl@vmware.com>2017-12-14 16:08:24 +0800
commit1ab719d0d310b0c0640eeeb4d1cf87dcae4c3168 (patch)
tree663a1c743d602ce81ff58d81c536fc6756dcb211 /multivimbroker
parent7ef4d9292529e9a3336368430361f9a63f48c54d (diff)
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 <ethanlynnl@vmware.com>
Diffstat (limited to 'multivimbroker')
-rw-r--r--multivimbroker/multivimbroker/forwarder/views.py35
-rw-r--r--multivimbroker/multivimbroker/pub/config/provider-plugin.json29
-rw-r--r--multivimbroker/multivimbroker/pub/utils/syscomm.py24
3 files changed, 48 insertions, 40 deletions
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=""):