code of applay grant
[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
17 from rest_framework import status
18 from rest_framework.response import Response
19 from rest_framework.views import APIView
20
21 from lcm.nf.vnfs.vnf_create.create_vnf_identifier import CreateVnf
22 from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf
23 from lcm.pub.utils.jobutil import JobUtil
24 from lcm.pub.utils.values import ignore_case_get
25
26 logger = logging.getLogger(__name__)
27
28
29 class CreateVnfIdentifier(APIView):
30     def post(self, request):
31         logger.debug("CreateVnfIdentifier--post::> %s" % request.data)
32         data = {}
33         data["vnfdId"] = ignore_case_get(request.data, "vnfdId")
34         data["vnfInstanceName"] = ignore_case_get(request.data, "vnfInstanceName")
35         data["vnfInstanceDescription"] = ignore_case_get(request.data, "vnfInstanceDescription")
36         try:
37             self.nf_inst_id = CreateVnf(data).do_biz()
38         except Exception as e:
39             return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
40         rsp = {"vnfInstanceId": self.nf_inst_id}
41         return Response(data=rsp, status=status.HTTP_201_CREATED)
42
43
44 class InstantiateVnf(APIView):
45     def post(self, request, instanceId):
46         logger.debug("InstantiateVnf--post::> %s" % request.data)
47         data = {'flavourId': ignore_case_get(request.data, 'flavourId'),
48                 'instantiationLevelId': ignore_case_get(request.data, 'instantiationLevelId'),
49                 'extVirtualLinks': ignore_case_get(request.data, 'extVirtualLinks'),
50                 'localizationLanguage': ignore_case_get(request.data, 'localizationLanguage'),
51                 'additionalParams': ignore_case_get(request.data, 'additionalParams')}
52         nf_inst_id = instanceId
53         job_id = JobUtil.create_job('NF', 'INSTANTIATE', nf_inst_id)
54         JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
55
56         InstVnf(data, nf_inst_id, job_id).start()
57         rsp = {"jobId": job_id}
58         return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
59
60
61 class DeleteVnfIdentifier(APIView):
62     def delete(self, request):
63         logger.debug("DeleteVnfIdentifier--delete::> %s" % request.data)
64         return Response(data='', status=status.HTTP_202_ACCEPTED)
65
66
67 class TerminateVnf(APIView):
68     def post(self, request):
69         logger.debug("TerminateVnf--post::> %s" % request.data)
70         return Response(data='', status=status.HTTP_202_ACCEPTED)
71
72
73 class QueryMultipleVnf(APIView):
74     def get(self, request):
75         logger.debug("QueryMultipleVnf--get::> %s" % request.data)
76         return Response(data='', status=status.HTTP_202_ACCEPTED)
77
78
79 class QuerySingleVnf(APIView):
80     def get(self, request):
81         logger.debug("QuerySingleVnf--get::> %s" % request.data)
82         return Response(data='', status=status.HTTP_202_ACCEPTED)
83
84
85 class GetOperationStatus(APIView):
86     def get(self, request):
87         logger.debug("GetOperationStatus--get::> %s" % request.data)
88         return Response(data='', status=status.HTTP_202_ACCEPTED)