diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2018-02-02 16:26:22 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2018-02-02 16:26:22 +0800 |
commit | beb1525524a093821c2edda3e88c670a84abde82 (patch) | |
tree | 64f48461cd31bc142ef9265a6a2ce1771fb1e2e7 | |
parent | 1a6127cb99f577781ebb8b78fc3706b3c9ccb2e4 (diff) |
Refactor vfc-vfcmgr views.py file
Change-Id: I70fa3125deb12092fa504b6f3c62f75a2ec728d7
Issue-ID: VFC-670
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r-- | mgr/mgr/vnfreg/views.py | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/mgr/mgr/vnfreg/views.py b/mgr/mgr/vnfreg/views.py index abfe858..006ce77 100644 --- a/mgr/mgr/vnfreg/views.py +++ b/mgr/mgr/vnfreg/views.py @@ -39,10 +39,9 @@ class vnfmgr_addvnf(APIView): status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'}) def post(self, request): logger.info("Enter %s, data is %s", fun_name(), request.data) - request_serializer = VnfInfoSerializer(data=request.data) - request_isvalid = request_serializer.is_valid() try: - if not request_isvalid: + request_serializer = VnfInfoSerializer(data=request.data) + if not request_serializer.is_valid(): raise Exception(request_serializer.errors) requestData = request_serializer.data @@ -57,8 +56,7 @@ class vnfmgr_addvnf(APIView): password=ignore_case_get(requestData, "password")).save() response_serializer = ResponseSerializer(data={"vnfInstId": vnf_inst_id}) - resp_isvalid = response_serializer.is_valid() - if not resp_isvalid: + if not response_serializer.is_valid(): raise Exception(response_serializer.errors) return Response(data=response_serializer.data, status=status.HTTP_201_CREATED) @@ -109,13 +107,10 @@ def access_vnf(request, *args, **kwargs): if not response_serializer.is_valid(): raise Exception(response_serializer.errors) - ret = response_serializer.data - normal_status = status.HTTP_200_OK + return Response(data=response_serializer.data, status=status.HTTP_200_OK) elif request.method == 'PUT': request_serializer = VnfInfoSerializer(data=request.data) - request_isvalid = request_serializer.is_valid() - - if not request_isvalid: + if not request_serializer.is_valid(): raise Exception(request_serializer.errors) requestData = request_serializer.data @@ -132,14 +127,11 @@ def access_vnf(request, *args, **kwargs): if password: vnf[0].password = password vnf[0].save() - ret = {} - normal_status = status.HTTP_202_ACCEPTED + return Response(data={}, status=status.HTTP_202_ACCEPTED) else: vnf.delete() - ret = {} - normal_status = status.HTTP_204_NO_CONTENT + return Response(data={}, status=status.HTTP_204_NO_CONTENT) - return Response(data=ret, status=normal_status) except Exception as e: logger.error(e.message) logger.error(traceback.format_exc()) @@ -156,8 +148,7 @@ def vnf_config(request, *args, **kwargs): logger.info("Enter %s, data is %s", fun_name(), request.data) try: request_serializer = VnfConfigSerializer(data=request.data) - request_isvalid = request_serializer.is_valid() - if not request_isvalid: + if not request_serializer.is_valid(): raise Exception(request_serializer.errors) requestData = request_serializer.data |