1 # Copyright 2017 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.
19 from rest_framework import status
20 from rest_framework.response import Response
21 from rest_framework.views import APIView
23 from lcm.nf.vnfs.vnf_cancel.delete_vnf_identifier import DeleteVnf
24 from lcm.nf.vnfs.vnf_create.create_vnf_identifier import CreateVnf
25 from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf
26 from lcm.pub.exceptions import NFLCMException
27 from lcm.pub.utils.jobutil import JobUtil
29 logger = logging.getLogger(__name__)
32 class CreateVnfIdentifier(APIView):
33 def post(self, request):
34 logger.debug("CreateVnfIdentifier--post::> %s" % request.data)
36 nf_inst_id = CreateVnf(request.data).do_biz()
37 except NFLCMException as e:
38 logger.error(e.message)
39 return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
41 logger.error(traceback.format_exc())
42 return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
43 rsp = {"vnfInstanceId": nf_inst_id}
44 return Response(data=rsp, status=status.HTTP_201_CREATED)
47 class InstantiateVnf(APIView):
48 def post(self, request, instanceid):
49 logger.debug("InstantiateVnf--post::> %s" % request.data)
50 job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceid)
51 JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
52 InstVnf(request.data, instanceid, job_id).start()
53 rsp = {"jobId": job_id}
54 return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
57 class DeleteVnfIdentifier(APIView):
58 def delete(self, request, instanceid):
59 logger.debug("DeleteVnfIdentifier--delete::> %s" % request.data)
61 DeleteVnf(request.data, instanceid).do_biz()
62 except NFLCMException as e:
63 logger.error(e.message)
64 return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
66 logger.error(traceback.format_exc())
67 return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
68 return Response(data=None, status=status.HTTP_204_NO_CONTENT)
71 class TerminateVnf(APIView):
72 def post(self, request):
73 logger.debug("TerminateVnf--post::> %s" % request.data)
74 return Response(data='', status=status.HTTP_202_ACCEPTED)
77 class QueryMultipleVnf(APIView):
78 def get(self, request):
79 logger.debug("QueryMultipleVnf--get::> %s" % request.data)
80 return Response(data='', status=status.HTTP_202_ACCEPTED)
83 class QuerySingleVnf(APIView):
84 def get(self, request):
85 logger.debug("QuerySingleVnf--get::> %s" % request.data)
86 return Response(data='', status=status.HTTP_202_ACCEPTED)
89 class GetOperationStatus(APIView):
90 def get(self, request):
91 logger.debug("GetOperationStatus--get::> %s" % request.data)
92 return Response(data='', status=status.HTTP_202_ACCEPTED)
95 class SwaggerJsonView(APIView):
96 def get(self, request):
97 json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')
99 json_data = json.JSONDecoder().decode(f.read())
101 return Response(json_data)