From 10815c65561e07b6d3dae0aeb04f43904116401c Mon Sep 17 00:00:00 2001 From: fujinhua Date: Fri, 5 Apr 2019 17:30:13 +0800 Subject: Refactor codes for inst vnf Change-Id: I619ff8d2bf6c8506079768c159448a10c6d05ca3 Issue-ID: VFC-1306 Signed-off-by: fujinhua --- lcm/lcm/nf/views/instantiate_vnf_view.py | 38 +++++++++++++------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/lcm/lcm/nf/views/instantiate_vnf_view.py b/lcm/lcm/nf/views/instantiate_vnf_view.py index 3b4a3bee..1a7905aa 100644 --- a/lcm/lcm/nf/views/instantiate_vnf_view.py +++ b/lcm/lcm/nf/views/instantiate_vnf_view.py @@ -13,7 +13,6 @@ # limitations under the License. import logging -import traceback from drf_yasg.utils import swagger_auto_schema from lcm.nf.biz.instantiate_vnf import InstantiateVnf @@ -39,25 +38,18 @@ class InstantiateVnfView(APIView): ) def post(self, request, instanceid): logger.debug("InstantiateVnf--post::> %s" % request.data) - try: - instantiate_vnf_request_serializer = InstantiateVnfRequestSerializer(data=request.data) - if not instantiate_vnf_request_serializer.is_valid(): - raise NFLCMException(instantiate_vnf_request_serializer.errors) - - job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceid) - JobUtil.add_job_status(job_id, 0, "INST_VNF_READY") - InstantiateVnf(instantiate_vnf_request_serializer.data, instanceid, job_id).start() - - job_identifier_serializer = JobIdentifierSerializer(data={"jobId": job_id}) - resp_isvalid = job_identifier_serializer.is_valid() - if not resp_isvalid: - raise NFLCMException(job_identifier_serializer.errors) - - return Response(data=job_identifier_serializer.data, status=status.HTTP_202_ACCEPTED) - except NFLCMException as e: - logger.error(e.message) - return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - except Exception as e: - logger.error(e.message) - logger.error(traceback.format_exc()) - return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + instantiate_vnf_request_serializer = InstantiateVnfRequestSerializer(data=request.data) + if not instantiate_vnf_request_serializer.is_valid(): + raise NFLCMException(instantiate_vnf_request_serializer.errors) + + job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceid) + JobUtil.add_job_status(job_id, 0, "INST_VNF_READY") + InstantiateVnf(instantiate_vnf_request_serializer.data, instanceid, job_id).start() + + job_identifier_serializer = JobIdentifierSerializer(data={"jobId": job_id}) + resp_isvalid = job_identifier_serializer.is_valid() + if not resp_isvalid: + raise NFLCMException(job_identifier_serializer.errors) + + return Response(data=job_identifier_serializer.data, status=status.HTTP_202_ACCEPTED) -- cgit 1.2.3-korg