summaryrefslogtreecommitdiffstats
path: root/zte/vmanager/driver/interfaces/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'zte/vmanager/driver/interfaces/views.py')
-rw-r--r--zte/vmanager/driver/interfaces/views.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 3fc6272d..7376d4d2 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -23,6 +23,7 @@ from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
+from django.http import StreamingHttpResponse
from driver.interfaces.serializers import HealReqSerializer, InstScaleHealRespSerializer, ScaleReqSerializer, \
NotifyReqSerializer, GrantRespSerializer, GrantReqSerializer, JobQueryRespSerializer, TerminateVnfRequestSerializer, \
@@ -31,6 +32,8 @@ from driver.pub.config.config import VNF_FTP
from driver.pub.utils import restcall
from driver.pub.utils.restcall import req_by_msb
+CHUNK_SIZE = 1024 * 8
+
logger = logging.getLogger(__name__)
@@ -42,6 +45,25 @@ def load_json_file(file_name):
return json_data
+def read(file_path, start, end):
+ fp = open(file_path, 'rb')
+ fp.seek(start)
+ pos = start
+ while pos + CHUNK_SIZE < end:
+ yield fp.read(CHUNK_SIZE)
+ pos = fp.tell()
+ yield fp.read(end - pos)
+
+
+def parse_file_range(file_path, file_range):
+ start, end = 0, os.path.getsize(file_path)
+ if file_range:
+ [start, end] = file_range.split('-')
+ start, end = start.strip(), end.strip()
+ start, end = int(start), int(end)
+ return start, end
+
+
def fun_name():
return "=================%s==================" % inspect.stack()[1][3]
@@ -662,3 +684,15 @@ class VnfPkgs(APIView):
}]
}
return Response(data=resp_data, status=status.HTTP_200_OK)
+
+
+class VnfPkg(APIView):
+ def get(self, request, packageId, fileName):
+ logger.debug("====VnfPkg get====%s, %s", packageId, fileName)
+ file_range = request.META.get('RANGE')
+ logger.debug('file_range: %s' % file_range)
+ # TODO: get filepath
+ local_file_path = fileName
+ start, end = parse_file_range(local_file_path, file_range)
+ file_iterator = read(local_file_path, start, end)
+ return StreamingHttpResponse(file_iterator, status=status.HTTP_200_OK)