summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSudhakar Reddy <Sudhakar.Reddy@amdocs.com>2018-09-29 14:12:05 +0530
committerSudhakar Reddy <Sudhakar.Reddy@amdocs.com>2018-09-29 14:46:37 +0530
commit0f7184f697298eaabe56b3960e6bc59197b7793e (patch)
treed15a5069e8ad6f9b1d2ed99a9c5ae59188a1954c
parentadd37e10f956227f4a8db29829daf12f029e9d8e (diff)
Merge Multipart API with InfraWorkload
This also include: 1.Config Json change to support Azure plugin 2.URL position change to call Proper view Currently,Infra API is calling Forwarder view Change-Id: I682788b837782e32007529ca3033c2ef206250da Issue-ID: MULTICLOUD-370 Signed-off-by: Sudhakar Reddy <Sudhakar.Reddy@amdocs.com>
-rw-r--r--multivimbroker/multivimbroker/forwarder/base.py12
-rw-r--r--multivimbroker/multivimbroker/forwarder/urls.py11
-rw-r--r--multivimbroker/multivimbroker/forwarder/views.py81
-rw-r--r--multivimbroker/multivimbroker/pub/config/provider-plugin.json11
-rw-r--r--multivimbroker/multivimbroker/tests/test_syscomm.py1
-rw-r--r--multivimbroker/multivimbroker/tests/test_vim_types.py2
6 files changed, 58 insertions, 60 deletions
diff --git a/multivimbroker/multivimbroker/forwarder/base.py b/multivimbroker/multivimbroker/forwarder/base.py
index 6d45014..f5d3734 100644
--- a/multivimbroker/multivimbroker/forwarder/base.py
+++ b/multivimbroker/multivimbroker/forwarder/base.py
@@ -27,10 +27,11 @@ logger = logging.getLogger(__name__)
class BaseHandler(object):
- def _request(self, route_uri, method, body="", headers=None):
+ def _request(self, route_uri, method, body="", headers=None,
+ multipart=False):
try:
- if "multipart" in route_uri:
+ if multipart:
return self._multipart_req(route_uri, method, body, headers)
retcode, content, status_code, resp = \
req_by_msb(route_uri, method, body, headers)
@@ -74,7 +75,8 @@ class BaseHandler(object):
response = HttpResponse(content, status=status_code)
return response
- def send(self, vimid, full_path, body, method, headers=None):
+ def send(self, vimid, full_path, body, method, headers=None,
+ multipart=False):
try:
url = getMultivimDriver(vimid, full_path=full_path)
@@ -85,5 +87,5 @@ class BaseHandler(object):
logging.exception("unkown exception: %s" % e)
return HttpResponse(str(e),
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-
- return self._request(url, method, body=body, headers=headers)
+ return self._request(url, method, body=body, headers=headers,
+ multipart=multipart)
diff --git a/multivimbroker/multivimbroker/forwarder/urls.py b/multivimbroker/multivimbroker/forwarder/urls.py
index b14333f..75dde71 100644
--- a/multivimbroker/multivimbroker/forwarder/urls.py
+++ b/multivimbroker/multivimbroker/forwarder/urls.py
@@ -24,7 +24,6 @@ from multivimbroker.forwarder.views import Identity
from multivimbroker.forwarder.views import Registry
from multivimbroker.forwarder.views import UnRegistry
from multivimbroker.forwarder.views import VIMTypes
-from multivimbroker.forwarder.views import MultiPartView
# API v1
from multivimbroker.forwarder.views import APIv1CheckCapacity
@@ -34,7 +33,6 @@ from multivimbroker.forwarder.views import APIv1Identity
from multivimbroker.forwarder.views import APIv1Registry
from multivimbroker.forwarder.views import APIv1UnRegistry
from multivimbroker.forwarder.views import APIv1VIMTypes
-from multivimbroker.forwarder.views import APIv1MultiPartView
from multivimbroker.forwarder.views import APIv1InfraWorkload
urlpatterns = [
@@ -53,8 +51,6 @@ urlpatterns = [
UnRegistry.as_view()),
url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)/extensions$',
Extension.as_view()),
- url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)/multipart',
- MultiPartView.as_view()),
url(r'^api/multicloud/v0/(?P<vimid>[0-9a-zA-Z_-]+)',
Forward.as_view()),
@@ -79,14 +75,11 @@ urlpatterns = [
r'/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/extensions$',
APIv1Extension.as_view()),
url(r'^api/multicloud/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)'
- r'/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/multipart',
- APIv1MultiPartView.as_view()),
+ r'/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/infra_workload',
+ APIv1InfraWorkload.as_view()),
url(r'^api/multicloud/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)'
r'/(?P<cloud_region_id>[0-9a-zA-Z_-]+)',
APIv1Forward.as_view()),
- url(r'^api/multicloud/v1/(?P<cloud_owner>[0-9a-zA-Z_-]+)'
- r'/(?P<cloud_region_id>[0-9a-zA-Z_-]+)/infra_workload',
- APIv1InfraWorkload.as_view()),
]
urlpatterns = format_suffix_patterns(urlpatterns)
diff --git a/multivimbroker/multivimbroker/forwarder/views.py b/multivimbroker/multivimbroker/forwarder/views.py
index 264692e..7b9000c 100644
--- a/multivimbroker/multivimbroker/forwarder/views.py
+++ b/multivimbroker/multivimbroker/forwarder/views.py
@@ -17,6 +17,7 @@ import os
import json
import re
import tempfile
+from django.core.files.uploadedfile import InMemoryUploadedFile
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
@@ -26,7 +27,6 @@ from rest_framework.views import status
from multivimbroker.forwarder.base import BaseHandler
from multivimbroker.pub.utils.syscomm import originHeaders
from multivimbroker.pub.utils import syscomm
-from rest_framework.parsers import MultiPartParser
from multivimbroker.pub.msapi import extsys
@@ -161,41 +161,6 @@ class Forward(BaseServer):
headers=originHeaders(request))
-# Multipart view
-class MultiPartView(BaseServer):
-
- parser_classes = (MultiPartParser, )
-
- def post(self, request, vimid):
- try:
- register_openers()
- fileDict = dict(request.FILES.iterlists())
- params = {}
- for key in fileDict.keys():
- fileObj = fileDict[key][0]
- f = tempfile.NamedTemporaryFile(prefix="django_",
- suffix=fileObj._name,
- delete=False)
- f.write(fileObj.file.read())
- f.seek(fileObj.file.tell(), 0)
- fileObj.file.close()
- params[key] = open(f.name, 'rb')
- datagen, headers = multipart_encode(params)
- regex = re.compile('^HTTP_')
- for key, value in request.META.iteritems():
- if key.startswith("HTTP_"):
- headers[regex.sub('', key).replace('_', '-')] = value
- resp = self.send(vimid, request.path, datagen, "POST",
- headers=headers)
- finally:
- for key in params:
- fileRef = params[key]
- if fileRef.closed is False:
- fileRef.close()
- os.remove(fileRef.name)
- return resp
-
-
# API v1
# proxy handler
class APIv1Identity(Identity):
@@ -300,19 +265,12 @@ class APIv1Forward(Forward):
return super(APIv1Forward, self).put(request, vimid)
-# Multipart view
-class APIv1MultiPartView(MultiPartView):
-
- def post(self, request, cloud_owner, cloud_region_id):
-
- vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
- return super(APIv1MultiPartView, self).post(request, vimid)
-
-
class APIv1InfraWorkload(BaseServer):
def post(self, request, cloud_owner, cloud_region_id):
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
+ if len(request.FILES) != 0:
+ return self.__process_multipart(request, vimid)
return self.send(vimid, request.get_full_path(), request.body, "POST",
headers=originHeaders(request))
@@ -325,3 +283,36 @@ class APIv1InfraWorkload(BaseServer):
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
return self.send(vimid, request.get_full_path(), request.body,
"DELETE", headers=originHeaders(request))
+
+ def __process_multipart(self, request, vimid):
+ try:
+ register_openers()
+ dataDict = dict(request.data.iterlists())
+ params = {}
+ for key in dataDict.keys():
+ dataObj = dataDict[key][0]
+ if isinstance(dataObj, InMemoryUploadedFile):
+ f = tempfile.NamedTemporaryFile(prefix="django_",
+ suffix=dataObj._name,
+ delete=False)
+ f.write(dataObj.file.read())
+ f.seek(dataObj.file.tell(), 0)
+ dataObj.file.close()
+ params[key] = open(f.name, 'rb')
+ else:
+ params[key] = dataObj
+ datagen, headers = multipart_encode(params)
+ regex = re.compile('^HTTP_')
+ for key, value in request.META.iteritems():
+ if key.startswith("HTTP_"):
+ headers[regex.sub('', key).replace('_', '-')] = value
+ resp = self.send(vimid, request.path, datagen, "POST",
+ headers=headers, multipart=True)
+ finally:
+ for key in params:
+ refobj = params[key]
+ if type(refobj) is not unicode:
+ if refobj.closed is False:
+ print refobj.close()
+ os.remove(refobj.name)
+ return resp
diff --git a/multivimbroker/multivimbroker/pub/config/provider-plugin.json b/multivimbroker/multivimbroker/pub/config/provider-plugin.json
index a6d7478..1103a24 100644
--- a/multivimbroker/multivimbroker/pub/config/provider-plugin.json
+++ b/multivimbroker/multivimbroker/pub/config/provider-plugin.json
@@ -25,5 +25,16 @@
}
},
"provider_plugin": "multicloud-vio"
+ },
+ "azure": {
+ "vim_type": "azure",
+ "versions": {
+ "1.0": {
+ "version": "1.0",
+ "extra_info_hint": "",
+ "provider_plugin": "multicloud-azure"
+ }
+ },
+ "provider_plugin": "multicloud-azure"
}
} \ No newline at end of file
diff --git a/multivimbroker/multivimbroker/tests/test_syscomm.py b/multivimbroker/multivimbroker/tests/test_syscomm.py
index 1f3d71d..beed0b9 100644
--- a/multivimbroker/multivimbroker/tests/test_syscomm.py
+++ b/multivimbroker/multivimbroker/tests/test_syscomm.py
@@ -22,6 +22,7 @@ class TestSyscomm(unittest.TestCase):
expected_body = {
"openstack": ["titanium_cloud", "ocata"],
"vmware": ["4.0"],
+ "azure": ["1.0"]
}
ret = syscomm.getVIMTypes()
for item in ret:
diff --git a/multivimbroker/multivimbroker/tests/test_vim_types.py b/multivimbroker/multivimbroker/tests/test_vim_types.py
index b8a5080..b0148b5 100644
--- a/multivimbroker/multivimbroker/tests/test_vim_types.py
+++ b/multivimbroker/multivimbroker/tests/test_vim_types.py
@@ -23,4 +23,4 @@ class TestUrls(unittest.TestCase):
def test_vim_types_success(self):
resp = self.view.get(mock.Mock())
self.assertEqual(status.HTTP_200_OK, resp.status_code)
- self.assertEqual(2, len(resp.data))
+ self.assertEqual(3, len(resp.data))