Implement instantiation related interface
[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 uuid
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.pub.database.models import VnfInstModel
23 from lcm.pub.utils.jobutil import JobUtil
24 from lcm.pub.utils.timeutil import now_time
25 from lcm.pub.utils.values import ignore_case_get
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         self.vnfd_id = ignore_case_get(request.data, "vnfdId")
34         self.vnf_instance_mame = ignore_case_get(request.data, "vnfInstanceName")
35         self.description = ignore_case_get(request.data, "vnfInstanceDescription")
36         self.nf_inst_id = str(uuid.uuid4())
37         VnfInstModel(id=self.nf_inst_id, name=self.vnf_instance_mame, vnfd_id=self.vnfd_id,
38                      description=self.description, status='empty', create_time=now_time(), lastuptime=now_time()).save()
39         vnf_inst = VnfInstModel.objects.get(id=self.nf_inst_id)
40         logger.debug('id is [%s],name is [%s],vnfd_id is [%s],description is [%s],create_time is [%s],lastuptime is [%s],' %
41                      (vnf_inst.id, vnf_inst.name, vnf_inst.vnfd_id, vnf_inst.description, vnf_inst.create_time, vnf_inst.lastuptime))
42         rsp = {"vnfInstanceId": self.nf_inst_id}
43         return Response(data=rsp, status=status.HTTP_201_CREATED)
44
45
46 class InstantiateVnf(APIView):
47     def post(self, request, instanceId):
48         logger.debug("InstantiateVnf--post::> %s" % request.data)
49         data = {'flavourId': ignore_case_get(request.data, 'flavourId'),
50                 'instantiationLevelId': ignore_case_get(request.data, 'instantiationLevelId'),
51                 'extVirtualLinks': ignore_case_get(request.data, 'extVirtualLinks'),
52                 'localizationLanguage': ignore_case_get(request.data, 'localizationLanguage'),
53                 'additionalParams': ignore_case_get(request.data, 'additionalParams')}
54         nf_inst_id = instanceId
55         job_id = JobUtil.create_job('NF', 'CREATE', nf_inst_id)
56         JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
57
58         # CreateVnfs(data, nf_inst_id, job_id).start()
59         rsp = {"jobId": job_id}
60         return Response(data=rsp, status=status.HTTP_202_ACCEPTED)
61
62
63 class DeleteVnfIdentifier(APIView):
64     def delete(self, request):
65         logger.debug("DeleteVnfIdentifier--delete::> %s" % request.data)
66         return Response(data='', status=status.HTTP_202_ACCEPTED)
67
68
69 class TerminateVnf(APIView):
70     def post(self, request):
71         logger.debug("TerminateVnf--post::> %s" % request.data)
72         return Response(data='', status=status.HTTP_202_ACCEPTED)
73
74
75 class QueryMultipleVnf(APIView):
76     def get(self, request):
77         logger.debug("QueryMultipleVnf--get::> %s" % request.data)
78         return Response(data='', status=status.HTTP_202_ACCEPTED)
79
80
81 class QuerySingleVnf(APIView):
82     def get(self, request):
83         logger.debug("QuerySingleVnf--get::> %s" % request.data)
84         return Response(data='', status=status.HTTP_202_ACCEPTED)
85
86
87 class GetOperationStatus(APIView):
88     def get(self, request):
89         logger.debug("GetOperationStatus--get::> %s" % request.data)
90         return Response(data='', status=status.HTTP_202_ACCEPTED)