diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2018-09-19 10:02:20 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2018-09-19 10:02:20 +0800 |
commit | ae9e7301bbdf23ccf564d2d6f49eeb7042728905 (patch) | |
tree | b242ecf929a6a7d228eb5caad8c691668329af7b | |
parent | b03a30d541b972ac034baf4bd0e08d339ed3e78d (diff) |
Move term ns view as single
Change-Id: If69244392ca7e461ff4b0f8701cdd4e1f34a91c0
Issue-ID: VFC-1009
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/ns/urls.py | 3 | ||||
-rw-r--r-- | lcm/ns/views/term_ns_view.py | 58 | ||||
-rw-r--r-- | lcm/ns/views/views.py | 32 |
3 files changed, 60 insertions, 33 deletions
diff --git a/lcm/ns/urls.py b/lcm/ns/urls.py index 94070146..7c804875 100644 --- a/lcm/ns/urls.py +++ b/lcm/ns/urls.py @@ -16,7 +16,8 @@ from rest_framework.urlpatterns import format_suffix_patterns from lcm.ns.views.create_ns_view import CreateNSView from lcm.ns.views.inst_ns_view import NSInstView -from lcm.ns.views.views import TerminateNSView, NSDetailView, NSInstPostDealView, \ +from lcm.ns.views.term_ns_view import TerminateNSView +from lcm.ns.views.views import NSDetailView, NSInstPostDealView, \ NSManualScaleView, NSHealView urlpatterns = [ diff --git a/lcm/ns/views/term_ns_view.py b/lcm/ns/views/term_ns_view.py new file mode 100644 index 00000000..a8c9a42d --- /dev/null +++ b/lcm/ns/views/term_ns_view.py @@ -0,0 +1,58 @@ +# Copyright 2016-2017 ZTE Corporation. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import logging + +from rest_framework import status +from rest_framework.response import Response +from rest_framework.views import APIView +from drf_yasg.utils import swagger_auto_schema + +from lcm.ns.biz.ns_terminate import TerminateNsService +from lcm.ns.serializers.ns_serializers import NsOperateJobSerializer +from lcm.ns.serializers.ns_serializers import TerminateNsReqSerializer +from lcm.pub.exceptions import NSLCMException +from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE +from lcm.pub.utils.values import ignore_case_get + +logger = logging.getLogger(__name__) + + +class TerminateNSView(APIView): + @swagger_auto_schema( + request_body=TerminateNsReqSerializer(), + responses={ + status.HTTP_202_ACCEPTED: NsOperateJobSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" + } + ) + 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 NSLCMException(req_serializer.errors) + + termination_type = ignore_case_get(request.data, 'terminationType') + graceful_termination_timeout = ignore_case_get(request.data, 'gracefulTerminationTimeout') + job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, ns_instance_id) + TerminateNsService(ns_instance_id, termination_type, graceful_termination_timeout, job_id).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 Exception as e: + logger.error("Exception in CreateNS: %s", e.message) + return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/lcm/ns/views/views.py b/lcm/ns/views/views.py index 19ff8c01..7f6f70f7 100644 --- a/lcm/ns/views/views.py +++ b/lcm/ns/views/views.py @@ -19,7 +19,6 @@ from drf_yasg.utils import swagger_auto_schema from lcm.ns.biz.ns_get import GetNSInfoService from lcm.ns.biz.ns_heal import NSHealService from lcm.ns.biz.ns_manual_scale import NSManualScaleService -from lcm.ns.biz.ns_terminate import TerminateNsService from rest_framework import status from rest_framework.response import Response from rest_framework.views import APIView @@ -30,7 +29,6 @@ from lcm.ns.serializers.ns_serializers import InstNsPostDealReqSerializer from lcm.ns.serializers.ns_serializers import ManualScaleNsReqSerializer from lcm.ns.serializers.ns_serializers import NsOperateJobSerializer from lcm.ns.serializers.ns_serializers import QueryNsRespSerializer -from lcm.ns.serializers.ns_serializers import TerminateNsReqSerializer from lcm.pub.database.models import NSInstModel, ServiceBaseInfoModel from lcm.pub.exceptions import NSLCMException from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE @@ -40,36 +38,6 @@ from lcm.pub.utils.values import ignore_case_get logger = logging.getLogger(__name__) -class TerminateNSView(APIView): - @swagger_auto_schema( - request_body=TerminateNsReqSerializer(), - responses={ - status.HTTP_202_ACCEPTED: NsOperateJobSerializer(), - status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" - } - ) - 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 NSLCMException(req_serializer.errors) - - termination_type = ignore_case_get(request.data, 'terminationType') - graceful_termination_timeout = ignore_case_get(request.data, 'gracefulTerminationTimeout') - job_id = JobUtil.create_job("VNF", JOB_TYPE.TERMINATE_VNF, ns_instance_id) - TerminateNsService(ns_instance_id, termination_type, graceful_termination_timeout, job_id).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 Exception as e: - logger.error("Exception in CreateNS: %s", e.message) - return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - - class NSHealView(APIView): @swagger_auto_schema( request_body=HealNsReqSerializer(), |