summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-02-08 09:26:17 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-02-08 09:26:17 +0800
commit881fc75bb1f3770651331e3a6b2c57a3f1f9c8cd (patch)
tree5155c1a77b70184d8a724783ab22155d8777f6c5
parent9df5be00e5a73a26ab7eef8c8a4d81acd2629bb6 (diff)
Add ztevnfmdriver query job swagger
Change-Id: Ib6e4e9827b220d365db1b094afa8bb06cb640017 Issue-ID: VFC-736 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--zte/vmanager/driver/interfaces/urls.py2
-rw-r--r--zte/vmanager/driver/interfaces/views.py66
2 files changed, 36 insertions, 32 deletions
diff --git a/zte/vmanager/driver/interfaces/urls.py b/zte/vmanager/driver/interfaces/urls.py
index d8fb6f66..c912739e 100644
--- a/zte/vmanager/driver/interfaces/urls.py
+++ b/zte/vmanager/driver/interfaces/urls.py
@@ -23,7 +23,7 @@ urlpatterns = [
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$',
views.query_vnf, name='query_vnf'),
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/jobs/(?P<jobid>[0-9a-zA-Z\-\_]+)$',
- views.operation_status, name='operation_status'),
+ views.JobView.as_view(), name='operation_status'),
url(r'^api/ztevnfmdriver/v1/resource/grant$', views.GrantVnf.as_view(), name='grantvnf'),
url(r'^api/ztevnfmdriver/v1/vnfs/lifecyclechangesnotification$', views.Notify.as_view(), name='notify'),
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/scale$',
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 96470f36..89d8e48f 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -25,7 +25,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from driver.interfaces.serializers import HealReqSerializer, InstScaleHealRespSerializer, ScaleReqSerializer, \
- NotifyReqSerializer, GrantRespSerializer, GrantReqSerializer
+ NotifyReqSerializer, GrantRespSerializer, GrantReqSerializer, JobQueryRespSerializer
from driver.pub.config.config import VNF_FTP
from driver.pub.utils import restcall
from driver.pub.utils.restcall import req_by_msb
@@ -224,37 +224,41 @@ def query_vnf(request, *args, **kwargs):
return Response(data=resp_data, status=ret[2])
-@api_view(http_method_names=['GET'])
-def operation_status(request, *args, **kwargs):
- data = {}
- try:
- logger.debug("[%s] request.data=%s", fun_name(), request.data)
- vnfm_id = ignorcase_get(kwargs, "vnfmid")
- ret = get_vnfminfo_from_nslcm(vnfm_id)
- if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
- vnfm_info = json.JSONDecoder().decode(ret[1])
- logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
- operation_status_url = '/v1/jobs/{jobId}?NFVOID={nfvoId}&VNFMID={vnfmId}&ResponseID={responseId}'
- ret = restcall.call_req(
- base_url=ignorcase_get(vnfm_info, 'url'),
- user=ignorcase_get(vnfm_info, 'userName'),
- passwd=ignorcase_get(vnfm_info, 'password'),
- auth_type=restcall.rest_no_auth,
- resource=operation_status_url.format(jobId=ignorcase_get(kwargs, 'jobid'), nfvoId=1,
- vnfmId=ignorcase_get(kwargs, 'vnfmid'),
- responseId=ignorcase_get(request.GET, 'responseId')),
- method='get',
- content=json.JSONEncoder().encode(data))
+class JobView(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: JobQueryRespSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ }
+ )
+ def get(self, request, vnfmid, jobid):
+ try:
+ logger.debug("[%s] request.data=%s", fun_name(), request.data)
+ ret = get_vnfminfo_from_nslcm(vnfmid)
+ if ret[0] != 0:
+ return Response(data={'error': ret[1]}, status=ret[2])
+ vnfm_info = json.JSONDecoder().decode(ret[1])
+ logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
+ operation_status_url = '/v1/jobs/{jobId}?NFVOID={nfvoId}&VNFMID={vnfmId}&ResponseID={responseId}'
+ ret = restcall.call_req(
+ base_url=ignorcase_get(vnfm_info, 'url'),
+ user=ignorcase_get(vnfm_info, 'userName'),
+ passwd=ignorcase_get(vnfm_info, 'password'),
+ auth_type=restcall.rest_no_auth,
+ resource=operation_status_url.format(jobId=jobid, nfvoId=1, vnfmId=vnfmid,
+ responseId=ignorcase_get(request.GET, 'responseId')),
+ method='get',
+ content={})
- if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
- resp_data = json.JSONDecoder().decode(ret[1])
- logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
- except Exception as e:
- logger.error("Error occurred when getting operation status information.")
- raise e
- return Response(data=resp_data, status=ret[2])
+ if ret[0] != 0:
+ return Response(data={'error': ret[1]}, status=ret[2])
+ resp_data = json.JSONDecoder().decode(ret[1])
+ logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
+ return Response(data=resp_data, status=ret[2])
+ except Exception as e:
+ logger.error("Error occurred when getting operation status information,error:%s", e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'QueryJob expection'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class GrantVnf(APIView):