diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2019-07-10 10:47:33 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2019-07-10 10:47:33 +0800 |
commit | 49736a7643e8d338116619f53bebb2906540f5c9 (patch) | |
tree | 623a97d7f09d2998458f0cad3c7ede7d0dc1ca06 | |
parent | 272d90ecd40e0795bdb42cb341de2143603ca6ff (diff) |
Refactor codes for term ns
Change-Id: I522f48817f682419739b6e74bfcac42936007b8d
Issue-ID: VFC-1429
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/ns/views/deprecated/term_ns_view.py | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/lcm/ns/views/deprecated/term_ns_view.py b/lcm/ns/views/deprecated/term_ns_view.py index 652b8db0..dd6e98a3 100644 --- a/lcm/ns/views/deprecated/term_ns_view.py +++ b/lcm/ns/views/deprecated/term_ns_view.py @@ -25,6 +25,7 @@ from lcm.pub.utils.jobutil import JobUtil from lcm.jobs.enum import JOB_TYPE, JOB_ACTION from lcm.ns.serializers.deprecated.ns_serializers import _TerminateNsReqSerializer from lcm.ns.serializers.deprecated.ns_serializers import _NsOperateJobSerializer +from .common import view_safe_call_with_log logger = logging.getLogger(__name__) @@ -38,23 +39,19 @@ class NSTerminateView(APIView): status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" } ) + @view_safe_call_with_log(logger=logger) def post(self, request, ns_instance_id): - try: - logger.debug("Enter TerminateNSView::post %s", request.data) - req_serializer = _TerminateNsReqSerializer(data=request.data) - if not req_serializer.is_valid(): - raise BadRequestException(req_serializer.errors) - - job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.TERMINATE, ns_instance_id) - TerminateNsService(ns_instance_id, job_id, request.data).start() - - resp_serializer = _NsOperateJobSerializer(data={'jobId': job_id}) - if not resp_serializer.is_valid(): - raise NSLCMException(resp_serializer.errors) - logger.debug("Leave TerminateNSView::post ret=%s", resp_serializer.data) - return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED) - except BadRequestException as e: - return Response(data={'error': e.args[0]}, status=status.HTTP_400_BAD_REQUEST) - except Exception as e: - logger.error("Exception in CreateNS: %s", e.args[0]) - return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + logger.debug("Enter TerminateNSView::post %s", request.data) + req_serializer = _TerminateNsReqSerializer(data=request.data) + if not req_serializer.is_valid(): + raise BadRequestException(req_serializer.errors) + + job_id = JobUtil.create_job(JOB_TYPE.NS, JOB_ACTION.TERMINATE, ns_instance_id) + TerminateNsService(ns_instance_id, job_id, request.data).start() + + resp_serializer = _NsOperateJobSerializer(data={'jobId': job_id}) + if not resp_serializer.is_valid(): + raise NSLCMException(resp_serializer.errors) + + logger.debug("Leave TerminateNSView::post ret=%s", resp_serializer.data) + return Response(data=resp_serializer.data, status=status.HTTP_202_ACCEPTED) |