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_create.create_vnf_identifier import CreateVnf
24 from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf
25 from lcm.pub.exceptions import NFLCMException
26 from lcm.pub.utils.jobutil import JobUtil
28 logger = logging.getLogger(__name__)
31 class CreateVnfIdentifier(APIView):
32 def post(self, request):
33 logger.debug("CreateVnfIdentifier--post::> %s" % request.data)
35 nf_inst_id = CreateVnf(request.data).do_biz()
36 except NFLCMException as e:
37 logger.error(e.message)
38 return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
40 logger.error(traceback.format_exc())
41 return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
42 rsp = {"vnfInstanceId": nf_inst_id}
43 return Response(data=rsp, status=status.HTTP_201_CREATED)
46 class InstantiateVnf(APIView):
47 def post(self, request, instanceId):
48 logger.debug("InstantiateVnf--post::> %s" % request.data)
49 job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceId)
50 JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
51 InstVnf(request.data, instanceId, job_id).start()
52 rsp = {"jobId": job_id}
53 return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
56 class DeleteVnfIdentifier(APIView):
57 def delete(self, request):
58 logger.debug("DeleteVnfIdentifier--delete::> %s" % request.data)
59 return Response(data='', status=status.HTTP_202_ACCEPTED)
62 class TerminateVnf(APIView):
63 def post(self, request):
64 logger.debug("TerminateVnf--post::> %s" % request.data)
65 return Response(data='', status=status.HTTP_202_ACCEPTED)
68 class QueryMultipleVnf(APIView):
69 def get(self, request):
70 logger.debug("QueryMultipleVnf--get::> %s" % request.data)
71 return Response(data='', status=status.HTTP_202_ACCEPTED)
74 class QuerySingleVnf(APIView):
75 def get(self, request):
76 logger.debug("QuerySingleVnf--get::> %s" % request.data)
77 return Response(data='', status=status.HTTP_202_ACCEPTED)
80 class GetOperationStatus(APIView):
81 def get(self, request):
82 logger.debug("GetOperationStatus--get::> %s" % request.data)
83 return Response(data='', status=status.HTTP_202_ACCEPTED)
86 class SwaggerJsonView(APIView):
87 def get(self, request):
88 json_file = os.path.join(os.path.dirname(__file__), 'swagger.json')
90 json_data = json.JSONDecoder().decode(f.read())
92 return Response(json_data)