Create VNF instance,Create VNF Identifier
[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.timeutil import now_time
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         self.vnfd_id = ignore_case_get(request.data, "vnfdId")
33         self.vnf_instance_mame = ignore_case_get(request.data, "vnfInstanceName")
34         self.description = ignore_case_get(request.data, "vnfInstanceDescription")
35         self.nf_inst_id = str(uuid.uuid4())
36         VnfInstModel(id=self.nf_inst_id, name=self.vnf_instance_mame, vnfd_id=self.vnfd_id,
37                      description=self.description, status='empty', create_time=now_time(), lastuptime=now_time()).save()
38         vnf_inst = VnfInstModel.objects.get(id=self.nf_inst_id)
39         logger.debug('id is [%s],name is [%s],vnfd_id is [%s],description is [%s],create_time is [%s],lastuptime is [%s],' %
40                      (vnf_inst.id, vnf_inst.name, vnf_inst.vnfd_id, vnf_inst.description, vnf_inst.create_time, vnf_inst.lastuptime))
41         rsp = {"vnfInstanceId": self.nf_inst_id}
42         return Response(data=rsp, status=status.HTTP_201_CREATED)