summaryrefslogtreecommitdiffstats
path: root/lcm/lcm/nf/vnfs/views.py
blob: 02f35cb2356c5088f14f26939e9119a31ab25214 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Copyright 2017 ZTE Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import uuid

from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView

from lcm.pub.database.models import VnfInstModel
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get

logger = logging.getLogger(__name__)


class CreateVnfIdentifier(APIView):
    def post(self, request):
        logger.debug("CreateVnfIdentifier--post::> %s" % request.data)
        self.vnfd_id = ignore_case_get(request.data, "vnfdId")
        self.vnf_instance_mame = ignore_case_get(request.data, "vnfInstanceName")
        self.description = ignore_case_get(request.data, "vnfInstanceDescription")
        self.nf_inst_id = str(uuid.uuid4())
        VnfInstModel(id=self.nf_inst_id, name=self.vnf_instance_mame, vnfd_id=self.vnfd_id,
                     description=self.description, status='empty', create_time=now_time(), lastuptime=now_time()).save()
        vnf_inst = VnfInstModel.objects.get(id=self.nf_inst_id)
        logger.debug('id is [%s],name is [%s],vnfd_id is [%s],description is [%s],create_time is [%s],lastuptime is [%s],' %
                     (vnf_inst.id, vnf_inst.name, vnf_inst.vnfd_id, vnf_inst.description, vnf_inst.create_time, vnf_inst.lastuptime))
        rsp = {"vnfInstanceId": self.nf_inst_id}
        return Response(data=rsp, status=status.HTTP_201_CREATED)