diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2018-09-19 09:18:29 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2018-09-19 09:30:52 +0800 |
commit | 7da623c2e406835765f7082f541df6f8dab174c2 (patch) | |
tree | 1579194560a1e5621a905fff6490d8ed788ecad1 | |
parent | a2e8442ea7d120827566fbdc9ee2b842db1a123d (diff) |
Move create ns view as single
Change-Id: I7d43da84a832bd429e2de2cbce9bb747b55bca28
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/create_ns_view.py | 84 | ||||
-rw-r--r-- | lcm/ns/views/views.py | 57 |
3 files changed, 86 insertions, 58 deletions
diff --git a/lcm/ns/urls.py b/lcm/ns/urls.py index eff23ac7..d2d35b55 100644 --- a/lcm/ns/urls.py +++ b/lcm/ns/urls.py @@ -14,7 +14,8 @@ from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patterns -from lcm.ns.views.views import CreateNSView, NSInstView, TerminateNSView, NSDetailView, NSInstPostDealView, \ +from lcm.ns.views.create_ns_view import CreateNSView +from lcm.ns.views.views import NSInstView, TerminateNSView, NSDetailView, NSInstPostDealView, \ NSManualScaleView, NSHealView urlpatterns = [ diff --git a/lcm/ns/views/create_ns_view.py b/lcm/ns/views/create_ns_view.py new file mode 100644 index 00000000..14bd829d --- /dev/null +++ b/lcm/ns/views/create_ns_view.py @@ -0,0 +1,84 @@ +# Copyright 2018 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 +import traceback + +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_create import CreateNSService +from lcm.ns.biz.ns_get import GetNSInfoService +from lcm.ns.serializers.ns_serializers import CreateNsReqSerializer, CreateNsRespSerializer +from lcm.ns.serializers.ns_serializers import QueryNsRespSerializer +from lcm.pub.exceptions import NSLCMException +from lcm.pub.utils.values import ignore_case_get + +logger = logging.getLogger(__name__) + + +class CreateNSView(APIView): + @swagger_auto_schema( + request_body=None, + responses={ + status.HTTP_200_OK: QueryNsRespSerializer(help_text="NS instances", many=True), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" + } + ) + def get(self, request): + try: + logger.debug("CreateNSView::get") + ret = GetNSInfoService().get_ns_info() + logger.debug("CreateNSView::get::ret=%s", ret) + resp_serializer = QueryNsRespSerializer(data=ret, many=True) + if not resp_serializer.is_valid(): + raise NSLCMException(resp_serializer.errors) + return Response(data=resp_serializer.data, status=status.HTTP_200_OK) + except Exception as e: + logger.error(traceback.format_exc()) + logger.error("Exception in GetNS: %s", e.message) + return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + @swagger_auto_schema( + request_body=CreateNsReqSerializer(), + responses={ + status.HTTP_201_CREATED: CreateNsRespSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" + } + ) + def post(self, request): + logger.debug("Enter CreateNS: %s", request.data) + try: + req_serializer = CreateNsReqSerializer(data=request.data) + if not req_serializer.is_valid(): + raise NSLCMException(req_serializer.errors) + + if ignore_case_get(request.data, 'test') == "test": + return Response(data={'nsInstanceId': "test"}, status=status.HTTP_201_CREATED) + csar_id = ignore_case_get(request.data, 'csarId') + ns_name = ignore_case_get(request.data, 'nsName') + description = ignore_case_get(request.data, 'description') + context = ignore_case_get(request.data, 'context') + ns_inst_id = CreateNSService(csar_id, ns_name, description, context).do_biz() + + logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id) + resp_serializer = CreateNsRespSerializer(data={'nsInstanceId': ns_inst_id}) + if not resp_serializer.is_valid(): + raise NSLCMException(resp_serializer.errors) + return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED) + except Exception as e: + logger.error(traceback.format_exc()) + 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 f76aa2b8..eae489b9 100644 --- a/lcm/ns/views/views.py +++ b/lcm/ns/views/views.py @@ -16,7 +16,6 @@ import logging import traceback from drf_yasg.utils import swagger_auto_schema -from lcm.ns.biz.ns_create import CreateNSService from lcm.ns.biz.ns_get import GetNSInfoService from lcm.ns.biz.ns_heal import NSHealService from lcm.ns.biz.ns_instant import InstantNSService @@ -27,7 +26,6 @@ from rest_framework.response import Response from rest_framework.views import APIView from lcm.ns.biz.ns_delete import DeleteNsService -from lcm.ns.serializers.ns_serializers import CreateNsReqSerializer, CreateNsRespSerializer from lcm.ns.serializers.ns_serializers import HealNsReqSerializer from lcm.ns.serializers.ns_serializers import InstNsPostDealReqSerializer from lcm.ns.serializers.ns_serializers import InstantNsReqSerializer @@ -44,61 +42,6 @@ from lcm.pub.utils.values import ignore_case_get logger = logging.getLogger(__name__) -class CreateNSView(APIView): - @swagger_auto_schema( - request_body=None, - responses={ - status.HTTP_200_OK: QueryNsRespSerializer(help_text="NS instances", many=True), - status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" - } - ) - def get(self, request): - try: - logger.debug("CreateNSView::get") - ret = GetNSInfoService().get_ns_info() - logger.debug("CreateNSView::get::ret=%s", ret) - resp_serializer = QueryNsRespSerializer(data=ret, many=True) - if not resp_serializer.is_valid(): - raise NSLCMException(resp_serializer.errors) - return Response(data=resp_serializer.data, status=status.HTTP_200_OK) - except Exception as e: - logger.error(traceback.format_exc()) - logger.error("Exception in GetNS: %s", e.message) - return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - - @swagger_auto_schema( - request_body=CreateNsReqSerializer(), - responses={ - status.HTTP_201_CREATED: CreateNsRespSerializer(), - status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" - } - ) - def post(self, request): - logger.debug("Enter CreateNS: %s", request.data) - try: - req_serializer = CreateNsReqSerializer(data=request.data) - if not req_serializer.is_valid(): - raise NSLCMException(req_serializer.errors) - - if ignore_case_get(request.data, 'test') == "test": - return Response(data={'nsInstanceId': "test"}, status=status.HTTP_201_CREATED) - csar_id = ignore_case_get(request.data, 'csarId') - ns_name = ignore_case_get(request.data, 'nsName') - description = ignore_case_get(request.data, 'description') - context = ignore_case_get(request.data, 'context') - ns_inst_id = CreateNSService(csar_id, ns_name, description, context).do_biz() - - logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id) - resp_serializer = CreateNsRespSerializer(data={'nsInstanceId': ns_inst_id}) - if not resp_serializer.is_valid(): - raise NSLCMException(resp_serializer.errors) - return Response(data=resp_serializer.data, status=status.HTTP_201_CREATED) - except Exception as e: - logger.error(traceback.format_exc()) - logger.error("Exception in CreateNS: %s", e.message) - return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - - class NSInstView(APIView): @swagger_auto_schema( request_body=InstantNsReqSerializer(), |