import traceback
from threading import Thread
-from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel, VmInstModel, NetworkInstModel, \
+from lcm.pub.database.models import NfInstModel, NfvoRegInfoModel, VmInstModel, NetworkInstModel, \
SubNetworkInstModel, PortInstModel, StorageInstModel, FlavourInstModel, VNFCInstModel, VLInstModel, CPInstModel
from lcm.pub.exceptions import NFLCMException
-from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get, apply_grant_to_nfvo, notify_lcm_to_nfvo
+from lcm.pub.msapi.catalog import query_rawdata_from_catalog
+from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get, apply_grant_to_nfvo, notify_lcm_to_nfvo, get_packageinfo_by_vnfdid
+from lcm.pub.utils import toscautil
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get
self.job_id = job_id
self.nfvo_inst_id = ''
self.vnfm_inst_id = ''
+ self.csar_id = ''
self.vnfd_info = []
self.inst_resource = {'volumn': [], # [{"vim_id": ignore_case_get(ret, "vim_id")},{}]
'network': [],
self.inst_pre()
self.apply_grant()
self.create_res()
- # self.check_res_status()
- # self.wait_inst_finish(args)
self.lcm_notify()
JobUtil.add_job_status(self.job_id, 100, "Instantiate Vnf success.")
- is_exist = JobStatusModel.objects.filter(jobid=self.job_id).exists()
- logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist)
+ # is_exist = JobStatusModel.objects.filter(jobid=self.job_id).exists()
+ # logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist)
except NFLCMException as e:
self.vnf_inst_failed_handle(e.message)
# self.rollback(e.message)
raise NFLCMException('VNF nf_inst_id is not exist.')
# self.vnfm_inst_id = vnf_insts[0].vnfm_inst_id
- if vnf_insts[0].instantiationState != 'NOT_INSTANTIATED':
+ if vnf_insts[0].status != 'NOT_INSTANTIATED':
raise NFLCMException('VNF instantiationState is not NOT_INSTANTIATED.')
- # get rawdata by vnfd_id
- ret = vnfd_rawdata_get(vnf_insts[0].vnfdid)
- if ret[0] != 0:
- raise NFLCMException("Get vnfd_raw_data failed.")
- self.vnfd_info = json.JSONDecoder().decode(ret[1])
+ # get csar_id from nslcm by vnfd_id
+ self.package_info = get_packageinfo_by_vnfdid(vnf_insts[0].vnfdid)
+ self.package_id = ignore_case_get(self.package_info, "package_id")
+ self.csar_id = ignore_case_get(self.package_info, "csar_id")
+
+ #get rawdata from catalog by csar_id
+ raw_data = query_rawdata_from_catalog(self.csar_id, self.data)
+ self.vnfd = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json
+ self.vnfd = json.JSONDecoder().decode(self.vnfd)
+ self.vnfd_info = self.vnfd
+
# checkParameterExist
for cp in self.data:
if cp not in self.vnfd_info:
# # self.add_job(43, 'INST_DPLY_VM_PRGS')
# logger.info("[NF instantiation] confirm all vms are active end")
- # def wait_inst_finish(self, args):
- # try:
- # logger.info('wait_inst_finish, args=%s' % args)
- # # WaitInstFinishTask(args).do_biz()
- # return {'result': '100', 'msg': 'Nf instancing wait finish', 'context': {}}
- # except Exception as e:
- # logger.error('Nf instancing wait exception=%s' % e.message)
- # logger.error(traceback.format_exc())
- # return {'result': '255', 'msg': 'Nf instancing wait exception', 'context': {}}
-
def lcm_notify(self):
logger.info('[NF instantiation] send notify request to nfvo start')
reg_info = NfvoRegInfoModel.objects.filter(vnfminstid=self.vnfm_inst_id).first()
raise NFLCMException("send notify request to nfvo failed")
logger.info('[NF instantiation] send notify request to nfvo end')
- # def rollback(self, args):
- # try:
- # logger.info('inst_exception, args=%s' % args)
- # # InstExceptionTask(args).do_biz()
- # return {'result': '100', 'msg': 'Nf instancing exception process finish', 'context': {}}
- # except Exception as e:
- # logger.error('Nf instancing exception process exception=%s' % e.message)
- # logger.error(traceback.format_exc())
- # return {'result': '255', 'msg': 'Nf instancing exception process exception', 'context': {}}
-
def load_nfvo_config(self):
logger.info("[NF instantiation]get nfvo connection info start")
reg_info = NfvoRegInfoModel.objects.filter(vnfminstid='vnfm111').first()
name='40G',
tenant='admin',
insttype=0,
+ is_predefined=ret["returnCode"],
instid=self.nf_inst_id)
elif res_type == adaptor.OPT_CREATE_NETWORK:
logger.info('Create networks!')
name='pnet_network',
tenant='admin',
insttype=0,
+ is_predefined=ret["returnCode"],
instid=self.nf_inst_id)
elif res_type == adaptor.OPT_CREATE_SUBNET:
logger.info('Create subnets!')
name='sub_pnet',
tenant='admin',
insttype=0,
+ is_predefined=ret["returnCode"],
instid=self.nf_inst_id)
elif res_type == adaptor.OPT_CREATE_PORT:
logger.info('Create ports!')
name='aaa_pnet_cp',
tenant='admin',
insttype=0,
+ is_predefined=ret["returnCode"],
instid=self.nf_inst_id)
elif res_type == adaptor.OPT_CREATE_FLAVOR:
logger.info('Create flavors!')
name='1',
vcpu='1',
extraspecs='1',
+ is_predefined=ret["returnCode"],
instid=self.nf_inst_id)
elif res_type == adaptor.OPT_CREATE_VM:
logger.info('Create vms!')
insttype=0,
instid=self.nf_inst_id,
vmname="test_01",
+ is_predefined=ret["returnCode"],
operationalstate=1)
def do_rollback(self, args_=None):
def do_notify_delete(self, ret):
logger.error('Deleting [%s] resource' % ret)
+
+ def checkParameterExist(self, input_para, vnfd_info):
+ pass