summaryrefslogtreecommitdiffstats
path: root/vio
diff options
context:
space:
mode:
authorzhang ab <zhanganbing@chinamobile.com>2018-03-23 09:39:24 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-23 09:39:24 +0000
commitc2a1813c93e8a4026290a5c2d7c5bf2d27b542e4 (patch)
treed2ef83bebdd3c4d9f0989f688b5b898774acbcc2 /vio
parentcc99758f801f1975fb72775d9141397d2659b7ef (diff)
parentdab42d91cc09da3b4193ee32853e15fbaef7b61b (diff)
Merge "image upload service will return detailed response"
Diffstat (limited to 'vio')
-rw-r--r--vio/vio/swagger/views/image/views.py48
1 files changed, 28 insertions, 20 deletions
diff --git a/vio/vio/swagger/views/image/views.py b/vio/vio/swagger/views/image/views.py
index f77ed85..52d14ef 100644
--- a/vio/vio/swagger/views/image/views.py
+++ b/vio/vio/swagger/views/image/views.py
@@ -150,34 +150,42 @@ class CreateImageFileView(APIView):
except VimDriverVioException as e:
return Response(data={'error': str(e)}, status=e.status_code)
+ vim_rsp = image_utils.vim_formatter(vim_info, tenantid)
image_instance = OperateImage.OperateImage(vim_info)
- image_file = request.FILES['file']
+ try:
+ image_file = request.FILES['file']
+
+ random_name = ''.join(random.sample(
+ string.ascii_letters
+ + string.digits, 4))
+ file_name = image_file.name[:image_file.name.rfind('.')]
+ + "_" + random_name
+ + image_file.name[image_file.name.find('.'):]
- random_name = ''.join(random.sample(
- string.ascii_letters
- + string.digits, 4))
- file_name = image_file.name[:image_file.name.rfind('.')]
- + "_" + random_name
- + image_file.name[image_file.name.find('.'):]
+ file_dest = sys.path[0] + '/images/' + file_name
+ with open(file_dest, 'wb+') as temp_file:
+ for chunk in image_file.chunks():
+ temp_file.write(chunk)
+ temp_file.close()
- file_dest = sys.path[0] + '/images/' + file_name
- with open(file_dest, 'wb+') as temp_file:
- for chunk in image_file.chunks():
- temp_file.write(chunk)
- temp_file.close()
+ image_type = image_file.name[image_file.name.find('.') + 1:]
- image_type = image_file.name[image_file.name.find('.') + 1:]
+ except Exception as e:
+ return Response(data={'error': str(e)},
+ status=status.HTTP_500_INTERNAL_SERVER_ERROR)
try:
- image_instance.create_vim_image_file(vimid, tenantid,
- file_name[:
- file_name.rfind(
- '.')],
- file_dest,
- image_type)
+ image = image_instance.create_vim_image_file(
+ vimid, tenantid,
+ file_name[:file_name.rfind('.')],
+ file_dest,
+ image_type)
+ rsp = image_utils.image_formatter(image)
+ rsp.update(vim_rsp)
+ rsp['returnCode'] = '1'
- return Response(data={'status': 'upload OK'},
+ return Response(data={'status': rsp},
status=status.HTTP_201_CREATED)
except Exception as e:
if hasattr(e, "http_status"):