From: ying.yunlong Date: Fri, 24 Feb 2017 07:13:30 +0000 (+0800) Subject: Optimized code structure of vnflcm X-Git-Tag: release/mercury~40 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=vfc%2Fgvnfm%2Fvnflcm.git;a=commitdiff_plain;h=e73dc27b8c20b39454a6da64cfc6cc55538b11e8 Optimized code structure of vnflcm Change-Id: If1a07c283b29774534f95955505a9e495e19615d Issue-Id: GVNFM-12 Signed-off-by: ying.yunlong --- diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py index ef997f05..8b026e5c 100644 --- a/lcm/lcm/nf/vnfs/views.py +++ b/lcm/lcm/nf/vnfs/views.py @@ -61,8 +61,8 @@ class CreateVnfAndQueryVnfs(APIView): class InstantiateVnf(APIView): def post(self, request, instanceid): + logger.debug("InstantiateVnf--post::> %s" % request.data) try: - logger.debug("InstantiateVnf--post::> %s" % request.data) job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceid) JobUtil.add_job_status(job_id, 0, "INST_VNF_READY") InstVnf(request.data, instanceid, job_id).start() @@ -106,19 +106,20 @@ class DeleteVnfAndQueryVnf(APIView): class TerminateVnf(APIView): def post(self, request, instanceid): logger.debug("TerminateVnf--post::> %s" % request.data) - job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid) - JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY") - TermVnf(request.data, instanceid, job_id).start() + try: + job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid) + JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY") + TermVnf(request.data, instanceid, job_id).start() + except NFLCMException as e: + logger.error(e.message) + return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + except Exception: + logger.error(traceback.format_exc()) + return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) rsp = {"jobId": job_id} return Response(data=rsp, status=status.HTTP_202_ACCEPTED) -class QueryMultipleVnf(APIView): - def get(self, request): - logger.debug("QueryMultipleVnf--get::> %s" % request.data) - return Response(data='', status=status.HTTP_202_ACCEPTED) - - class SwaggerJsonView(APIView): def get(self, request): json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')