From d490f5bfd727d0219eb4dd74235194e9712ebb9a Mon Sep 17 00:00:00 2001 From: maopengzhang Date: Wed, 20 Mar 2019 20:20:47 +0800 Subject: create NS create NS Change-Id: I51719db2213cac96afe9792a8eeb3400fad8dfcc Issue-ID: VFC-1211 Signed-off-by: maopengzhang --- lcm/ns/urls.py | 26 +++++---- lcm/ns/views/create_ns_view.py | 91 ------------------------------ lcm/ns/views/deprecated/__init__.py | 0 lcm/ns/views/deprecated/create_ns_view.py | 91 ++++++++++++++++++++++++++++++ lcm/ns/views/deprecated/get_del_ns_view.py | 71 +++++++++++++++++++++++ lcm/ns/views/deprecated/inst_ns_view.py | 46 +++++++++++++++ lcm/ns/views/deprecated/term_ns_view.py | 58 +++++++++++++++++++ lcm/ns/views/get_del_ns_view.py | 71 ----------------------- lcm/ns/views/inst_ns_view.py | 46 --------------- lcm/ns/views/sol/__init__.py | 0 lcm/ns/views/sol/ns_instances_views.py | 37 ++++++++++++ lcm/ns/views/sol/nslcm_op_views.py | 35 ++++++++++++ lcm/ns/views/term_ns_view.py | 58 ------------------- 13 files changed, 354 insertions(+), 276 deletions(-) delete mode 100644 lcm/ns/views/create_ns_view.py create mode 100644 lcm/ns/views/deprecated/__init__.py create mode 100644 lcm/ns/views/deprecated/create_ns_view.py create mode 100644 lcm/ns/views/deprecated/get_del_ns_view.py create mode 100644 lcm/ns/views/deprecated/inst_ns_view.py create mode 100644 lcm/ns/views/deprecated/term_ns_view.py delete mode 100644 lcm/ns/views/get_del_ns_view.py delete mode 100644 lcm/ns/views/inst_ns_view.py create mode 100644 lcm/ns/views/sol/__init__.py create mode 100644 lcm/ns/views/sol/ns_instances_views.py create mode 100644 lcm/ns/views/sol/nslcm_op_views.py delete mode 100644 lcm/ns/views/term_ns_view.py diff --git a/lcm/ns/urls.py b/lcm/ns/urls.py index d9efa614..0a12ed7e 100644 --- a/lcm/ns/urls.py +++ b/lcm/ns/urls.py @@ -14,20 +14,21 @@ from django.conf.urls import url 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.term_ns_view import TerminateNSView +from lcm.ns.views.deprecated.create_ns_view import CreateNSView +from lcm.ns.views.deprecated.get_del_ns_view import NSDetailView +from lcm.ns.views.deprecated.inst_ns_view import NSInstView +from lcm.ns.views.deprecated.term_ns_view import TerminateNSView +from lcm.ns.views.sol.ns_instances_views import NSInstancesView, IndividualNsInstanceView +from lcm.ns.views.sol.nslcm_op_views import InstantiateNsView, TerminateNsView from lcm.ns.views.heal_ns_view import NSHealView -from lcm.ns.views.update_ns_view import NSUpdateView -from lcm.ns.views.get_del_ns_view import NSDetailView from lcm.ns.views.inst_ns_post_deal_view import NSInstPostDealView +from lcm.ns.views.lcm_op_occs_view import QueryMultiNsLcmOpOccs, QuerySingleNsLcmOpOcc from lcm.ns.views.scale_ns_views import NSManualScaleView from lcm.ns.views.subscriptions_view import SubscriptionsView -from lcm.ns.views.lcm_op_occs_view import QueryMultiNsLcmOpOccs, QuerySingleNsLcmOpOcc +from lcm.ns.views.update_ns_view import NSUpdateView urlpatterns = [ # API will be deprecated in the future release - url(r'^api/nslcm/v1/subscriptions$', SubscriptionsView.as_view()), url(r'^api/nslcm/v1/ns$', CreateNSView.as_view()), url(r'^api/nslcm/v1/ns/(?P[0-9a-zA-Z_-]+)/instantiate$', NSInstView.as_view()), url(r'^api/nslcm/v1/ns/(?P[0-9a-zA-Z_-]+)/terminate$', TerminateNSView.as_view()), @@ -37,10 +38,15 @@ urlpatterns = [ url(r'^api/nslcm/v1/ns/(?P[0-9a-zA-Z_-]+)/heal$', NSHealView.as_view()), url(r'^api/nslcm/v1/ns_lcm_op_occs$', QueryMultiNsLcmOpOccs.as_view()), url(r'^api/nslcm/v1/ns_lcm_op_occs/(?P[0-9a-zA-Z_-]+)$', QuerySingleNsLcmOpOcc.as_view()), + url(r'^api/nslcm/v1/ns/(?P[0-9a-zA-Z_-]+)/update$', NSUpdateView.as_view()), + + # SOL005 URL API definition + url(r'^api/nslcm/v1/ns_instances$', NSInstancesView.as_view()), + url(r'^api/nslcm/v1/ns_instances$/(?P[0-9a-zA-Z_-]+)/instantiate$', InstantiateNsView.as_view()), + url(r'^api/nslcm/v1/ns_instances$/(?P[0-9a-zA-Z_-]+)/terminate$', TerminateNsView.as_view()), + url(r'^api/nslcm/v1/ns_instances$/(?P[0-9a-zA-Z_-]+)$', IndividualNsInstanceView.as_view()), + url(r'^api/nslcm/v1/subscriptions$', SubscriptionsView.as_view()), - # SOL005 URL API definition TODO - url(r'^api/nslcm/v1/ns/(?P[0-9a-zA-Z_-]+)/update$', - NSUpdateView.as_view()) ] urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/lcm/ns/views/create_ns_view.py b/lcm/ns/views/create_ns_view.py deleted file mode 100644 index e03ed959..00000000 --- a/lcm/ns/views/create_ns_view.py +++ /dev/null @@ -1,91 +0,0 @@ -# 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.create_ns_serializers import CreateNsReqSerializer, CreateNsRespSerializer -from lcm.ns.serializers.pub_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, - 'nsInstanceName': 'nsInstanceName', - 'nsInstanceDescription': 'nsInstanceDescription', - 'nsdId': 123, - 'nsdInfoId': 456, - 'nsState': 'NOT_INSTANTIATED', - '_links': {'self': {'href': 'href'}}}) - 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/deprecated/__init__.py b/lcm/ns/views/deprecated/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lcm/ns/views/deprecated/create_ns_view.py b/lcm/ns/views/deprecated/create_ns_view.py new file mode 100644 index 00000000..e03ed959 --- /dev/null +++ b/lcm/ns/views/deprecated/create_ns_view.py @@ -0,0 +1,91 @@ +# 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.create_ns_serializers import CreateNsReqSerializer, CreateNsRespSerializer +from lcm.ns.serializers.pub_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, + 'nsInstanceName': 'nsInstanceName', + 'nsInstanceDescription': 'nsInstanceDescription', + 'nsdId': 123, + 'nsdInfoId': 456, + 'nsState': 'NOT_INSTANTIATED', + '_links': {'self': {'href': 'href'}}}) + 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/deprecated/get_del_ns_view.py b/lcm/ns/views/deprecated/get_del_ns_view.py new file mode 100644 index 00000000..ce0692ec --- /dev/null +++ b/lcm/ns/views/deprecated/get_del_ns_view.py @@ -0,0 +1,71 @@ +# 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 +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_get import GetNSInfoService +from lcm.ns.biz.ns_delete import DeleteNsService +from lcm.ns.serializers.pub_serializers import QueryNsRespSerializer +from lcm.pub.exceptions import NSLCMException + +logger = logging.getLogger(__name__) + + +class NSDetailView(APIView): + @swagger_auto_schema( + request_body=None, + responses={ + status.HTTP_200_OK: QueryNsRespSerializer(help_text="NS instance", many=True), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error", + status.HTTP_404_NOT_FOUND: "Ns instance does not exist" + } + ) + def get(self, request, ns_instance_id): + try: + logger.debug("Enter NSDetailView::get ns(%s)", ns_instance_id) + ns_filter = {"ns_inst_id": ns_instance_id} + ret = GetNSInfoService(ns_filter).get_ns_info() + if not ret: + return Response(status=status.HTTP_404_NOT_FOUND) + logger.debug("Leave NSDetailView::get::ret=%s", ret) + resp_serializer = QueryNsRespSerializer(data=ret[0]) + 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 GetNSDetail: %s", e.message) + return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + @swagger_auto_schema( + request_body=None, + responses={ + status.HTTP_204_NO_CONTENT: 'successful', + status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" + } + ) + def delete(self, request, ns_instance_id): + try: + logger.debug("Enter NSDetailView::delete ns(%s)", ns_instance_id) + DeleteNsService(ns_instance_id).do_biz() + return Response(data={}, status=status.HTTP_204_NO_CONTENT) + except Exception as e: + logger.error(traceback.format_exc()) + logger.error("Exception in delete NS: %s", e.message) + return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/lcm/ns/views/deprecated/inst_ns_view.py b/lcm/ns/views/deprecated/inst_ns_view.py new file mode 100644 index 00000000..eddd9a97 --- /dev/null +++ b/lcm/ns/views/deprecated/inst_ns_view.py @@ -0,0 +1,46 @@ +# 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_instant import InstantNSService +from lcm.ns.serializers.inst_ns_serializers import InstantNsReqSerializer +from lcm.ns.serializers.pub_serializers import NsOperateJobSerializer + +logger = logging.getLogger(__name__) + + +class NSInstView(APIView): + @swagger_auto_schema( + request_body=InstantNsReqSerializer(), + responses={ + status.HTTP_200_OK: NsOperateJobSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" + } + ) + def post(self, request, ns_instance_id): + logger.debug("Enter NSInstView::post::ns_instance_id=%s", ns_instance_id) + logger.debug("request.data=%s", request.data) + req_serializer = InstantNsReqSerializer(data=request.data) + if not req_serializer.is_valid(): + logger.debug("request.data is not valid,error: %s" % req_serializer.errors) + return Response({'error': req_serializer.errors}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR) + ack = InstantNSService(ns_instance_id, request.data).do_biz() + logger.debug("Leave NSInstView::post::ack=%s", ack) + return Response(data=ack['data'], status=ack['status']) diff --git a/lcm/ns/views/deprecated/term_ns_view.py b/lcm/ns/views/deprecated/term_ns_view.py new file mode 100644 index 00000000..0ae655b6 --- /dev/null +++ b/lcm/ns/views/deprecated/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.pub_serializers import NsOperateJobSerializer +from lcm.ns.serializers.terminate_ns_serializer 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("NS", JOB_TYPE.TERMINATE_NS, 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/get_del_ns_view.py b/lcm/ns/views/get_del_ns_view.py deleted file mode 100644 index ce0692ec..00000000 --- a/lcm/ns/views/get_del_ns_view.py +++ /dev/null @@ -1,71 +0,0 @@ -# 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 -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_get import GetNSInfoService -from lcm.ns.biz.ns_delete import DeleteNsService -from lcm.ns.serializers.pub_serializers import QueryNsRespSerializer -from lcm.pub.exceptions import NSLCMException - -logger = logging.getLogger(__name__) - - -class NSDetailView(APIView): - @swagger_auto_schema( - request_body=None, - responses={ - status.HTTP_200_OK: QueryNsRespSerializer(help_text="NS instance", many=True), - status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error", - status.HTTP_404_NOT_FOUND: "Ns instance does not exist" - } - ) - def get(self, request, ns_instance_id): - try: - logger.debug("Enter NSDetailView::get ns(%s)", ns_instance_id) - ns_filter = {"ns_inst_id": ns_instance_id} - ret = GetNSInfoService(ns_filter).get_ns_info() - if not ret: - return Response(status=status.HTTP_404_NOT_FOUND) - logger.debug("Leave NSDetailView::get::ret=%s", ret) - resp_serializer = QueryNsRespSerializer(data=ret[0]) - 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 GetNSDetail: %s", e.message) - return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) - - @swagger_auto_schema( - request_body=None, - responses={ - status.HTTP_204_NO_CONTENT: 'successful', - status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" - } - ) - def delete(self, request, ns_instance_id): - try: - logger.debug("Enter NSDetailView::delete ns(%s)", ns_instance_id) - DeleteNsService(ns_instance_id).do_biz() - return Response(data={}, status=status.HTTP_204_NO_CONTENT) - except Exception as e: - logger.error(traceback.format_exc()) - logger.error("Exception in delete NS: %s", e.message) - return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/lcm/ns/views/inst_ns_view.py b/lcm/ns/views/inst_ns_view.py deleted file mode 100644 index eddd9a97..00000000 --- a/lcm/ns/views/inst_ns_view.py +++ /dev/null @@ -1,46 +0,0 @@ -# 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_instant import InstantNSService -from lcm.ns.serializers.inst_ns_serializers import InstantNsReqSerializer -from lcm.ns.serializers.pub_serializers import NsOperateJobSerializer - -logger = logging.getLogger(__name__) - - -class NSInstView(APIView): - @swagger_auto_schema( - request_body=InstantNsReqSerializer(), - responses={ - status.HTTP_200_OK: NsOperateJobSerializer(), - status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" - } - ) - def post(self, request, ns_instance_id): - logger.debug("Enter NSInstView::post::ns_instance_id=%s", ns_instance_id) - logger.debug("request.data=%s", request.data) - req_serializer = InstantNsReqSerializer(data=request.data) - if not req_serializer.is_valid(): - logger.debug("request.data is not valid,error: %s" % req_serializer.errors) - return Response({'error': req_serializer.errors}, - status=status.HTTP_500_INTERNAL_SERVER_ERROR) - ack = InstantNSService(ns_instance_id, request.data).do_biz() - logger.debug("Leave NSInstView::post::ack=%s", ack) - return Response(data=ack['data'], status=ack['status']) diff --git a/lcm/ns/views/sol/__init__.py b/lcm/ns/views/sol/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lcm/ns/views/sol/ns_instances_views.py b/lcm/ns/views/sol/ns_instances_views.py new file mode 100644 index 00000000..562df709 --- /dev/null +++ b/lcm/ns/views/sol/ns_instances_views.py @@ -0,0 +1,37 @@ +import logging + +from drf_yasg.utils import swagger_auto_schema +from rest_framework import status +from rest_framework.response import Response +from rest_framework.views import APIView + +logger = logging.getLogger(__name__) + + +class NSInstancesView(APIView): + def get(self, request): + logger.debug(request.query_params) + # todo + + def post(self, request): + logger.debug("Enter NSInstancesView::POST ns_instances %s", request.data) + # todo + return Response(data={}, status=status.HTTP_201_CREATED) + + +class IndividualNsInstanceView(APIView): + def get(self, request, id): + logger.debug("Enter IndividualNsInstanceView::get ns(%s)", id) + # todo + return Response(data={}, status=status.HTTP_200_OK) + + @swagger_auto_schema( + request_body=None, + responses={ + status.HTTP_204_NO_CONTENT: None + } + ) + def delete(self, request, id): + logger.debug("Enter IndividualNsInstanceView::DELETE ns_instance(%s)", id) + # todo + return Response(data={}, status=status.HTTP_204_NO_CONTENT) diff --git a/lcm/ns/views/sol/nslcm_op_views.py b/lcm/ns/views/sol/nslcm_op_views.py new file mode 100644 index 00000000..ed4945a1 --- /dev/null +++ b/lcm/ns/views/sol/nslcm_op_views.py @@ -0,0 +1,35 @@ +import logging +from rest_framework.views import APIView + +logger = logging.getLogger(__name__) + + +class InstantiateNsView(APIView): + def post(self, request, id): + # todo + return + + +class HealNsView(APIView): + + def post(self, request, id): + # todo + return + + +class ScaleNsView(APIView): + def post(self, request, id): + # todo + return + + +class UpdateNsView(APIView): + def post(self, request, id): + # todo + return + + +class TerminateNsView(APIView): + def post(self, request, id): + # todo + return diff --git a/lcm/ns/views/term_ns_view.py b/lcm/ns/views/term_ns_view.py deleted file mode 100644 index 0ae655b6..00000000 --- a/lcm/ns/views/term_ns_view.py +++ /dev/null @@ -1,58 +0,0 @@ -# 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.pub_serializers import NsOperateJobSerializer -from lcm.ns.serializers.terminate_ns_serializer 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("NS", JOB_TYPE.TERMINATE_NS, 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) -- cgit 1.2.3-korg