diff options
-rw-r--r-- | lcm/lcm/nf/vnf_create/inst_vnf.py | 246 |
1 files changed, 127 insertions, 119 deletions
diff --git a/lcm/lcm/nf/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnf_create/inst_vnf.py index 3c102bda..c94bfee0 100644 --- a/lcm/lcm/nf/vnf_create/inst_vnf.py +++ b/lcm/lcm/nf/vnf_create/inst_vnf.py @@ -225,125 +225,8 @@ class InstVnf(Thread): def do_notify(self, res_type, ret): logger.info('Creating [%s] resource' % res_type) - if res_type == adaptor.RES_VOLUME: - logger.info('Create vloumns') - JobUtil.add_job_status(self.job_id, 25, 'Create vloumns!') - StorageInstModel.objects.create( - storageid=str(uuid.uuid4()), - vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), - name=ignore_case_get(ret, "name"), - tenant=ignore_case_get(ret, "tenantId"), - create_time=ignore_case_get(ret, "createTime"), - storagetype=get_none(ignore_case_get(ret, "type")), - size=ignore_case_get(ret, "size"), - insttype=0, - is_predefined=ignore_case_get(ret, "returnCode"), - nodeId=ignore_case_get(ret, "nodeId"), - instid=self.nf_inst_id) - elif res_type == adaptor.RES_NETWORK: - logger.info('Create networks') - JobUtil.add_job_status(self.job_id, 35, 'Create networks!') - NetworkInstModel.objects.create( - networkid=str(uuid.uuid4()), - name=ignore_case_get(ret, "name"), - vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), - tenant=ignore_case_get(ret, "tenantId"), - segmentid=str(ignore_case_get(ret, "segmentationId")), - network_type=ignore_case_get(ret, "networkType"), - physicalNetwork=ignore_case_get(ret, "physicalNetwork"), - vlantrans=get_boolean(ignore_case_get(ret, "vlanTransparent")), - is_shared=get_boolean(ignore_case_get(ret, "shared")), - routerExternal=get_boolean(ignore_case_get(ret, "routerExternal")), - insttype=0, - is_predefined=ignore_case_get(ret, "returnCode"), - nodeId=ignore_case_get(ret, "nodeId"), - instid=self.nf_inst_id) - elif res_type == adaptor.RES_SUBNET: - logger.info('Create subnets') - JobUtil.add_job_status(self.job_id, 40, 'Create subnets!') - SubNetworkInstModel.objects.create( - subnetworkid=str(uuid.uuid4()), - name=ignore_case_get(ret, "name"), - vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), - tenant=ignore_case_get(ret, "tenantId"), - networkid=ignore_case_get(ret, "networkId"), - cidr=ignore_case_get(ret, "cidr"), - ipversion=ignore_case_get(ret, "ipversion"), - isdhcpenabled=ignore_case_get(ret, "enableDhcp"), - gatewayip=ignore_case_get(ret, "gatewayIp"), - dnsNameservers=ignore_case_get(ret, "dnsNameservers"), - hostRoutes=ignore_case_get(ret, "hostRoutes"), - allocationPools=ignore_case_get(ret, "allocationPools"), - insttype=0, - is_predefined=ignore_case_get(ret, "returnCode"), - instid=self.nf_inst_id) - elif res_type == adaptor.RES_PORT: - logger.info('Create ports') - JobUtil.add_job_status(self.job_id, 50, 'Create ports!') - PortInstModel.objects.create( - portid=str(uuid.uuid4()), - networkid=ignore_case_get(ret, "networkId"), - subnetworkid=ignore_case_get(ret, "subnetId"), - name=ignore_case_get(ret, "name"), - vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), - tenant=ignore_case_get(ret, "tenantId"), - macaddress=ignore_case_get(ret, "macAddress"), - ipaddress=ignore_case_get(ret, "ip"), - typevirtualnic=ignore_case_get(ret, "vnicType"), - securityGroups=ignore_case_get(ret, "securityGroups"), - insttype=0, - is_predefined=ignore_case_get(ret, "returnCode"), - nodeId=ignore_case_get(ret, "nodeId"), - instid=self.nf_inst_id) - elif res_type == adaptor.RES_FLAVOR: - logger.info('Create flavors') - JobUtil.add_job_status(self.job_id, 60, 'Create flavors!') - FlavourInstModel.objects.create( - flavourid=str(uuid.uuid4()), - name=ignore_case_get(ret, "name"), - vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), - tenant=ignore_case_get(ret, "tenantId"), - vcpu=get_integer(ignore_case_get(ret, "vcpu")), - memory=get_integer(ignore_case_get(ret, "memory")), - disk=get_integer(ignore_case_get(ret, "disk")), - ephemeral=get_integer(ignore_case_get(ret, "ephemeral")), - swap=get_integer(ignore_case_get(ret, "swap")), - isPublic=get_boolean(ignore_case_get(ret, "isPublic")), - extraspecs=ignore_case_get(ret, "extraSpecs"), - is_predefined=ignore_case_get(ret, "returnCode"), - instid=self.nf_inst_id) - elif res_type == adaptor.RES_VM: - logger.info('Create vms') - JobUtil.add_job_status(self.job_id, 70, 'Create vms!') - vm_id = str(uuid.uuid4()) - VmInstModel.objects.create( - vmid=vm_id, - vmname=ignore_case_get(ret, "name"), - vimid=ignore_case_get(ret, "vimId"), - resouceid=ignore_case_get(ret, "id"), - tenant=ignore_case_get(ret, "tenantId"), - nic_array=ignore_case_get(ret, "nicArray"), - metadata=ignore_case_get(ret, "metadata"), - volume_array=ignore_case_get(ret, "volumeArray"), - server_group=ignore_case_get(ret, "serverGroup"), - availability_zone=str(ignore_case_get(ret, "availabilityZone", "undefined")), - flavor_id=ignore_case_get(ret, "flavorId"), - security_groups=ignore_case_get(ret, "securityGroups"), - operationalstate=ignore_case_get(ret, "status"), - insttype=0, - is_predefined=ignore_case_get(ret, "returnCode"), - instid=self.nf_inst_id) - VNFCInstModel.objects.create( - vnfcinstanceid=str(uuid.uuid4()), - vduid=ignore_case_get(ret, "id"), - is_predefined=ignore_case_get(ret, "returnCode"), - instid=self.nf_inst_id, - vmid=vm_id) + resource_save_method = globals().get(res_type + '_save') + resource_save_method(self.job_id, self.nf_inst_id, ret) def update_cps(self): for extlink in ignore_case_get(self.data, "extVirtualLinks"): @@ -364,3 +247,128 @@ class InstVnf(Thread): resource["properties"]["location_info"] = { "vimid": ignore_case_get(apply_result, "vimid"), "tenant": ignore_case_get(apply_result, "tenant")} + + +def volume_save(job_id, nf_inst_id, ret): + JobUtil.add_job_status(job_id, 25, 'Create vloumns!') + StorageInstModel.objects.create( + storageid=str(uuid.uuid4()), + vimid=ignore_case_get(ret, "vimId"), + resouceid=ignore_case_get(ret, "id"), + name=ignore_case_get(ret, "name"), + tenant=ignore_case_get(ret, "tenantId"), + create_time=ignore_case_get(ret, "createTime"), + storagetype=get_none(ignore_case_get(ret, "type")), + size=ignore_case_get(ret, "size"), + insttype=0, + is_predefined=ignore_case_get(ret, "returnCode"), + nodeId=ignore_case_get(ret, "nodeId"), + instid=nf_inst_id) + + +def network_save(job_id, nf_inst_id, ret): + JobUtil.add_job_status(job_id, 35, 'Create networks!') + NetworkInstModel.objects.create( + networkid=str(uuid.uuid4()), + name=ignore_case_get(ret, "name"), + vimid=ignore_case_get(ret, "vimId"), + resouceid=ignore_case_get(ret, "id"), + tenant=ignore_case_get(ret, "tenantId"), + segmentid=str(ignore_case_get(ret, "segmentationId")), + network_type=ignore_case_get(ret, "networkType"), + physicalNetwork=ignore_case_get(ret, "physicalNetwork"), + vlantrans=get_boolean(ignore_case_get(ret, "vlanTransparent")), + is_shared=get_boolean(ignore_case_get(ret, "shared")), + routerExternal=get_boolean(ignore_case_get(ret, "routerExternal")), + insttype=0, + is_predefined=ignore_case_get(ret, "returnCode"), + nodeId=ignore_case_get(ret, "nodeId"), + instid=nf_inst_id) + + +def subnet_save(job_id, nf_inst_id, ret): + JobUtil.add_job_status(job_id, 40, 'Create subnets!') + SubNetworkInstModel.objects.create( + subnetworkid=str(uuid.uuid4()), + name=ignore_case_get(ret, "name"), + vimid=ignore_case_get(ret, "vimId"), + resouceid=ignore_case_get(ret, "id"), + tenant=ignore_case_get(ret, "tenantId"), + networkid=ignore_case_get(ret, "networkId"), + cidr=ignore_case_get(ret, "cidr"), + ipversion=ignore_case_get(ret, "ipversion"), + isdhcpenabled=ignore_case_get(ret, "enableDhcp"), + gatewayip=ignore_case_get(ret, "gatewayIp"), + dnsNameservers=ignore_case_get(ret, "dnsNameservers"), + hostRoutes=ignore_case_get(ret, "hostRoutes"), + allocationPools=ignore_case_get(ret, "allocationPools"), + insttype=0, + is_predefined=ignore_case_get(ret, "returnCode"), + instid=nf_inst_id) + + +def port_save(job_id, nf_inst_id, ret): + JobUtil.add_job_status(job_id, 50, 'Create ports!') + PortInstModel.objects.create( + portid=str(uuid.uuid4()), + networkid=ignore_case_get(ret, "networkId"), + subnetworkid=ignore_case_get(ret, "subnetId"), + name=ignore_case_get(ret, "name"), + vimid=ignore_case_get(ret, "vimId"), + resouceid=ignore_case_get(ret, "id"), + tenant=ignore_case_get(ret, "tenantId"), + macaddress=ignore_case_get(ret, "macAddress"), + ipaddress=ignore_case_get(ret, "ip"), + typevirtualnic=ignore_case_get(ret, "vnicType"), + securityGroups=ignore_case_get(ret, "securityGroups"), + insttype=0, + is_predefined=ignore_case_get(ret, "returnCode"), + nodeId=ignore_case_get(ret, "nodeId"), + instid=nf_inst_id) + + +def flavor_save(job_id, nf_inst_id, ret): + JobUtil.add_job_status(job_id, 60, 'Create flavors!') + FlavourInstModel.objects.create( + flavourid=str(uuid.uuid4()), + name=ignore_case_get(ret, "name"), + vimid=ignore_case_get(ret, "vimId"), + resouceid=ignore_case_get(ret, "id"), + tenant=ignore_case_get(ret, "tenantId"), + vcpu=get_integer(ignore_case_get(ret, "vcpu")), + memory=get_integer(ignore_case_get(ret, "memory")), + disk=get_integer(ignore_case_get(ret, "disk")), + ephemeral=get_integer(ignore_case_get(ret, "ephemeral")), + swap=get_integer(ignore_case_get(ret, "swap")), + isPublic=get_boolean(ignore_case_get(ret, "isPublic")), + extraspecs=ignore_case_get(ret, "extraSpecs"), + is_predefined=ignore_case_get(ret, "returnCode"), + instid=nf_inst_id) + + +def vm_save(job_id, nf_inst_id, ret): + JobUtil.add_job_status(job_id, 70, 'Create vms!') + vm_id = str(uuid.uuid4()) + VmInstModel.objects.create( + vmid=vm_id, + vmname=ignore_case_get(ret, "name"), + vimid=ignore_case_get(ret, "vimId"), + resouceid=ignore_case_get(ret, "id"), + tenant=ignore_case_get(ret, "tenantId"), + nic_array=ignore_case_get(ret, "nicArray"), + metadata=ignore_case_get(ret, "metadata"), + volume_array=ignore_case_get(ret, "volumeArray"), + server_group=ignore_case_get(ret, "serverGroup"), + availability_zone=str(ignore_case_get(ret, "availabilityZone", "undefined")), + flavor_id=ignore_case_get(ret, "flavorId"), + security_groups=ignore_case_get(ret, "securityGroups"), + operationalstate=ignore_case_get(ret, "status"), + insttype=0, + is_predefined=ignore_case_get(ret, "returnCode"), + instid=nf_inst_id) + VNFCInstModel.objects.create( + vnfcinstanceid=str(uuid.uuid4()), + vduid=ignore_case_get(ret, "id"), + is_predefined=ignore_case_get(ret, "returnCode"), + instid=nf_inst_id, + vmid=vm_id) |