Optimized code of GVNFM
[vfc/gvnfm/vnflcm.git] / lcm / lcm / nf / vnfs / views.py
1 # Copyright 2017 ZTE Corporation.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import logging
16 import traceback
17
18 from rest_framework import status
19 from rest_framework.response import Response
20 from rest_framework.views import APIView
21
22 from lcm.nf.vnfs.vnf_create.create_vnf_identifier import CreateVnf
23 from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf
24 from lcm.pub.exceptions import NFLCMException
25 from lcm.pub.utils.jobutil import JobUtil
26
27 logger = logging.getLogger(__name__)
28
29
30 class CreateVnfIdentifier(APIView):
31     def post(self, request):
32         logger.debug("CreateVnfIdentifier--post::> %s" % request.data)
33         try:
34             nf_inst_id = CreateVnf(request.data).do_biz()
35         except NFLCMException as e:
36             logger.error(e.message)
37             return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
38         except Exception:
39             logger.error(traceback.format_exc())
40             return Response(data='unexpected exception', status=status.HTTP_500_INTERNAL_SERVER_ERROR)
41         rsp = {"vnfInstanceId": nf_inst_id}
42         return Response(data=rsp, status=status.HTTP_201_CREATED)
43
44
45 class InstantiateVnf(APIView):
46     def post(self, request, instanceId):
47         logger.debug("InstantiateVnf--post::> %s" % request.data)
48         job_id = JobUtil.create_job('NF', 'INSTANTIATE', instanceId)
49         JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
50         InstVnf(request.data, instanceId, job_id).start()
51         rsp = {"jobId": job_id}
52         return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
53
54
55 class DeleteVnfIdentifier(APIView):
56     def delete(self, request):
57         logger.debug("DeleteVnfIdentifier--delete::> %s" % request.data)
58         return Response(data='', status=status.HTTP_202_ACCEPTED)
59
60
61 class TerminateVnf(APIView):
62     def post(self, request):
63         logger.debug("TerminateVnf--post::> %s" % request.data)
64         return Response(data='', status=status.HTTP_202_ACCEPTED)
65
66
67 class QueryMultipleVnf(APIView):
68     def get(self, request):
69         logger.debug("QueryMultipleVnf--get::> %s" % request.data)
70         return Response(data='', status=status.HTTP_202_ACCEPTED)
71
72
73 class QuerySingleVnf(APIView):
74     def get(self, request):
75         logger.debug("QuerySingleVnf--get::> %s" % request.data)
76         return Response(data='', status=status.HTTP_202_ACCEPTED)
77
78
79 class GetOperationStatus(APIView):
80     def get(self, request):
81         logger.debug("GetOperationStatus--get::> %s" % request.data)
82         return Response(data='', status=status.HTTP_202_ACCEPTED)