X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=lcm%2Flcm%2Fnf%2Fvnfs%2Fvnf_create%2Fcreate_vnf_identifier.py;h=a91c8d02bf13c2f73e2a9a2235ab9fcb8bef0a57;hb=413288222272a379b87ff89aee95f2333e025da1;hp=bb7f80a729adcf6ae4e3b557df762fcec1366116;hpb=96b0c6d5c4b6ab583b4ac0081ac7c055651406d5;p=vfc%2Fgvnfm%2Fvnflcm.git diff --git a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py index bb7f80a7..a91c8d02 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py @@ -15,54 +15,77 @@ import json import logging import uuid +from lcm.pub.aaiapi.aai import create_vnf from lcm.pub.database.models import NfInstModel from lcm.pub.exceptions import NFLCMException -from lcm.pub.utils.restcall import req_by_msb +from lcm.pub.msapi.catalog import query_rawdata_from_catalog +from lcm.pub.msapi.gvnfmdriver import get_packageinfo_by_vnfdid +from lcm.pub.utils import toscautil from lcm.pub.utils.timeutil import now_time from lcm.pub.utils.values import ignore_case_get logger = logging.getLogger(__name__) -# Query vnfd_rawdata by vnfdid -def vnfd_rawdata_get(vnfdid): - ret = req_by_msb("openoapi/nslcm/v1/vnfpackage/%s" % vnfdid, "GET") - return ret + class CreateVnf: def __init__(self, data): self.data = data - - def do_biz(self): - logger.debug("CreateVnfIdentifier--CreateVnf::> %s" % self.data) self.vnfd_id = ignore_case_get(self.data, "vnfdId") self.vnf_instance_mame = ignore_case_get(self.data, "vnfInstanceName") self.description = ignore_case_get(self.data, "vnfInstanceDescription") + self.vnfd = None + self.package_info = '' + self.package_id = '' + self.csar_id = '' + + def do_biz(self): + logger.debug("CreateVnfIdentifier--CreateVnf::> %s" % self.data) is_exist = NfInstModel.objects.filter(nf_name=self.vnf_instance_mame).exists() - logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist) + logger.debug("check_inst_name_exist::is_exist=%s" % is_exist) if is_exist: raise NFLCMException('VNF is already exist.') - #get rawdata by vnfd_id - ret = vnfd_rawdata_get(self.vnfd_id) - if ret[0] != 0: - raise NFLCMException('Get vnfd_raw_data failed.') - dst_plan = json.JSONDecoder().decode(ret[1]) - self.vnfd_version = dst_plan['metadata']['vnfd_version'] - self.vendor = dst_plan['metadata']['vendor'] - self.producttype = dst_plan['metadata']['domain_type'] - self.netype = dst_plan['metadata']['vnf_type'] - self.vnfd_model = dst_plan - self.vnfSoftwareVersion = dst_plan['metadata']['version'] + nf_inst_id = str(uuid.uuid4()) + try: + self.package_info = get_packageinfo_by_vnfdid(self.vnfd_id) + for val in ignore_case_get(self.package_info, "csars"): + if self.vnfd_id == ignore_case_get(val, "vnfdId"): + self.package_id = ignore_case_get(val, "csarId") + break - self.nf_inst_id = str(uuid.uuid4()) - NfInstModel.objects.create(nfinstid=self.nf_inst_id, mnfinstid=self.nf_inst_id, nf_name=self.vnf_instance_mame, - package_id='todo', vnfm_inst_id='todo', version=self.vnfd_version, vendor=self.vendor, - producttype=self.producttype,netype=self.netype, vnfd_model=self.vnfd_model, - instantiationState='NOT_INSTANTIATED', nf_desc=self.description, vnfdid=self.vnfd_id, - vnfSoftwareVersion=self.vnfSoftwareVersion, vnfConfigurableProperties='todo', - localizationLanguage='EN_US',create_time=now_time()) - is_exist = NfInstModel.objects.filter(nf_name=self.vnf_instance_mame).exists() - logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist) - vnf_inst = NfInstModel.objects.get(nfinstid=self.nf_inst_id) - logger.debug('id is [%s],name is [%s],vnfd_id is [%s],description is [%s],create_time is [%s]' % - (vnf_inst.nfinstid, vnf_inst.nf_name, vnf_inst.vnfdid, vnf_inst.nf_desc, vnf_inst.create_time)) - return self.nf_inst_id \ No newline at end of file + raw_data = query_rawdata_from_catalog(self.package_id) + self.vnfd = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json + self.vnfd = json.JSONDecoder().decode(self.vnfd) + + metadata = ignore_case_get(self.vnfd, "metadata") + version = ignore_case_get(metadata, "vnfd_version") + vendor = ignore_case_get(metadata, "vendor") + netype = ignore_case_get(metadata, "vnf_type") + vnfsoftwareversion = ignore_case_get(metadata, "version") + vnfd_model = self.vnfd + NfInstModel.objects.create(nfinstid=nf_inst_id, nf_name=self.vnf_instance_mame, package_id=self.package_id, + version=version, vendor=vendor, netype=netype, vnfd_model=vnfd_model, + status='NOT_INSTANTIATED', nf_desc=self.description, vnfdid=self.vnfd_id, + vnfSoftwareVersion=vnfsoftwareversion, create_time=now_time()) + data = { + "vnf-id": nf_inst_id, + "vnf-name": self.vnf_instance_mame, + "vnf-type": "INFRA", + "in-maint": "true", + "is-closed-loop-disabled": "false" + } + create_vnf(nf_inst_id, data) + except NFLCMException as e: + logger.debug('Create VNF instance[%s] to AAI failed' % nf_inst_id) + except: + NfInstModel.objects.create(nfinstid=nf_inst_id, nf_name=self.vnf_instance_mame, package_id='', + version='', vendor='', netype='', vnfd_model='', + status='NOT_INSTANTIATED', nf_desc=self.description, vnfdid=self.vnfd_id, + vnfSoftwareVersion='', create_time=now_time()) + + vnf_inst = NfInstModel.objects.get(nfinstid=nf_inst_id) + logger.debug('id is [%s],name is [%s],vnfd_id is [%s],vnfd_model is [%s],' + 'description is [%s],create_time is [%s]' % + (vnf_inst.nfinstid, vnf_inst.nf_name, vnf_inst.vnfdid, + vnf_inst.vnfd_model, vnf_inst.nf_desc, vnf_inst.create_time)) + return nf_inst_id