1 # Copyright 2016 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
16 from rest_framework import status
17 from rest_framework.response import Response
18 from rest_framework.views import APIView
19 from drf_yasg.utils import swagger_auto_schema
21 from lcm.ns.sfcs.delete_sfcs import DeleteSfcs
22 from lcm.ns.sfcs.get_sfcs import GetSfcs
23 from lcm.ns.sfcs.serializers import GetSfcRespSerializer
24 from lcm.ns.sfcs.serializers import DeleteSfcRespSerializer
26 logger = logging.getLogger(__name__)
29 class SfcDetailView(APIView):
33 status.HTTP_200_OK: GetSfcRespSerializer(),
34 status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error",
35 status.HTTP_404_NOT_FOUND: "SFC not found"
38 def get(self, request, sfc_inst_id):
39 logger.debug("SfcCreateView--get::> %s", sfc_inst_id)
40 sfc_inst_info = GetSfcs(sfc_inst_id).do()
42 return Response(status=status.HTTP_404_NOT_FOUND)
44 resp_data = {'sfcInstId': sfc_inst_id,
46 'sfcStatus': sfc_inst_info[0].status}
48 resp_serializer = GetSfcRespSerializer(data=resp_data)
49 if not resp_serializer.is_valid():
50 logger.error(resp_serializer.errors)
51 return Response(data={'error': resp_serializer.errors},
52 status=status.HTTP_500_INTERNAL_SERVER_ERROR)
54 return Response(status=status.HTTP_200_OK, data=resp_serializer.data)
59 status.HTTP_202_ACCEPTED: DeleteSfcRespSerializer()
62 def delete(self, request_paras, sfc_inst_id):
63 resp = DeleteSfcs(sfc_inst_id).do()
65 resp_serializer = DeleteSfcRespSerializer(data=resp)
66 if not resp_serializer.is_valid():
67 logger.error(resp_serializer.errors)
68 return Response(data={"result": 1, "detail": resp_serializer.errors},
69 status=status.HTTP_202_ACCEPTED)
71 return Response(data=resp, status=status.HTTP_202_ACCEPTED)