1 # Copyright 2017 ZTE Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 from lcm.pub.database.models import NfInstModel
19 from lcm.pub.exceptions import NFLCMException
20 from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get
21 from lcm.pub.utils.timeutil import now_time
22 from lcm.pub.utils.values import ignore_case_get
24 logger = logging.getLogger(__name__)
28 def __init__(self, data):
30 self.vnfd_id = ignore_case_get(self.data, "vnfdId")
31 self.vnf_instance_mame = ignore_case_get(self.data, "vnfInstanceName")
32 self.description = ignore_case_get(self.data, "vnfInstanceDescription")
35 logger.debug("CreateVnfIdentifier--CreateVnf::> %s" % self.data)
36 is_exist = NfInstModel.objects.filter(nf_name=self.vnf_instance_mame).exists()
37 logger.debug("check_inst_name_exist::is_exist=%s" % is_exist)
39 raise NFLCMException('VNF is already exist.')
41 ret = vnfd_rawdata_get(self.vnfd_id)
43 raise NFLCMException('Get vnfd data failed.')
44 vnfd_info = json.JSONDecoder().decode(ret[1])
45 vnfd_version = vnfd_info['metadata']['vnfd_version']
46 vendor = vnfd_info['metadata']['vendor']
47 producttype = vnfd_info['metadata']['domain_type']
48 netype = vnfd_info['metadata']['vnf_type']
49 vnfd_model = vnfd_info
50 vnfsoftwareversion = vnfd_info['metadata']['version']
52 nf_inst_id = str(uuid.uuid4())
53 NfInstModel.objects.create(nfinstid=nf_inst_id, mnfinstid=nf_inst_id, nf_name=self.vnf_instance_mame,
54 package_id='todo', vnfm_inst_id='todo', version=vnfd_version, vendor=vendor,
55 producttype=producttype, netype=netype, vnfd_model=vnfd_model,
56 instantiationState='NOT_INSTANTIATED', nf_desc=self.description, vnfdid=self.vnfd_id,
57 vnfSoftwareVersion=vnfsoftwareversion, vnfConfigurableProperties='todo',
58 localizationLanguage='EN_US', create_time=now_time())
59 vnf_inst = NfInstModel.objects.get(nfinstid=nf_inst_id)
60 logger.debug('id is [%s],name is [%s],vnfd_id is [%s],description is [%s],create_time is [%s]' %
61 (vnf_inst.nfinstid, vnf_inst.nf_name, vnf_inst.vnfdid, vnf_inst.nf_desc, vnf_inst.create_time))