+ def do_notify(self, res_type, progress, ret):
+ logger.info('creating [%s] resource' % res_type)
+ progress = 20 + int(progress/2) # 20-70
+ if res_type == adaptor.OPT_CREATE_VOLUME:
+ logger.info('Create vloumns!')
+ if ret["returnCode"] == adaptor.RES_NEW: # new create
+ self.inst_resource['volumn'].append({"vim_id": ignore_case_get(ret, "vim_id"),
+ "res_id": ignore_case_get(ret, "res_id")})
+ JobUtil.add_job_status(self.job_id, progress, 'Create vloumns!')
+ StorageInstModel.objects.create(
+ storageid='1',
+ vimid='1',
+ resouceid='1',
+ 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!')
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['network'].append({"vim_id": ignore_case_get(ret, "vim_id"),
+ "res_id": ignore_case_get(ret, "res_id")})
+ # self.inst_resource['network'].append({"vim_id": "1"}, {"res_id": "2"})
+ JobUtil.add_job_status(self.job_id, progress, 'Create networks!')
+ NetworkInstModel.objects.create(
+ networkid='1',
+ vimid='1',
+ resouceid='1',
+ 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!')
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['subnet'].append({"vim_id": ignore_case_get(ret, "vim_id"),
+ "res_id": ignore_case_get(ret, "res_id")})
+ # self.inst_resource['subnet'].append({"vim_id": "1"}, {"res_id": "2"})
+ JobUtil.add_job_status(self.job_id, progress, 'Create subnets!')
+ SubNetworkInstModel.objects.create(
+ subnetworkid='1',
+ vimid='1',
+ resouceid='1',
+ networkid='1',
+ 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!')
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['port'].append({"vim_id": ignore_case_get(ret, "vim_id"),
+ "res_id": ignore_case_get(ret, "res_id")})
+ # self.inst_resource['port'].append({"vim_id": "1"}, {"res_id": "2"})
+ JobUtil.add_job_status(self.job_id, progress, 'Create ports!')
+ PortInstModel.objects.create(
+ portid='1',
+ networkid='1',
+ subnetworkid='1',
+ vimid='1',
+ resouceid='1',
+ 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!')
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['flavor'].append({"vim_id": ignore_case_get(ret, "vim_id"),
+ "res_id": ignore_case_get(ret, "res_id")})
+ # self.inst_resource['flavor'].append({"vim_id": "1"}, {"res_id": "2"})
+ JobUtil.add_job_status(self.job_id, progress, 'Create flavors!')
+ FlavourInstModel.objects.create(
+ falavourid='1',
+ 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!')
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['vm'].append({"vim_id": ignore_case_get(ret, "vim_id"),
+ "res_id": ignore_case_get(ret, "res_id")})
+ # self.inst_resource['vm'].append({"vim_id": "1"}, {"res_id": "2"})
+ JobUtil.add_job_status(self.job_id, progress, 'Create vms!')
+ VmInstModel.objects.create(
+ vmid="1",
+ vimid="1",
+ resouceid="11",
+ insttype=0,
+ instid=self.nf_inst_id,
+ vmname="test_01",
+ is_predefined=ret["returnCode"],
+ operationalstate=1)
+
+ def do_rollback(self, args_=None):
+ logger.error('error info : %s' % args_)
+ adaptor.delete_vim_res(self.inst_resource, self.do_notify_delete)
+ logger.error('rollback resource complete')
+
+ StorageInstModel.objects.filter(instid=self.nf_inst_id).delete()
+ NetworkInstModel.objects.filter(instid=self.nf_inst_id).delete()
+ SubNetworkInstModel.objects.filter(instid=self.nf_inst_id).delete()
+ PortInstModel.objects.filter(instid=self.nf_inst_id).delete()
+ FlavourInstModel.objects.filter(instid=self.nf_inst_id).delete()
+ VmInstModel.objects.filter(instid=self.nf_inst_id).delete()
+ logger.error('delete table complete')
+ raise NFLCMException("Create resource failed")
+
+ def do_notify_delete(self, ret):
+ logger.error('Deleting [%s] resource' % ret)
+
+ def checkParameterExist(self, input_para, vnfd_info):
+ pass