X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=nfvo.py;h=e8032064266026f8affce1445b97191e6375512d;hb=1f3a67138592443a8bd68ab936e071cb5bccda55;hp=dd3eb55bc2edda1661f6baf315eccc417ca84d98;hpb=2fce5f131d75100f7b753b9c05726ef972d7220c;p=osm%2FRO.git diff --git a/nfvo.py b/nfvo.py index dd3eb55b..e8032064 100644 --- a/nfvo.py +++ b/nfvo.py @@ -257,13 +257,17 @@ def create_or_use_image(mydb, vims, image_dict, rollback_list, only_create_at_vi if only_create_at_vim: image_mano_id = image_dict['uuid'] else: - images = mydb.get_rows(FROM="images", WHERE={'location':image_dict['location'], 'metadata':image_dict['metadata']}) + if image_dict['location'] is not None: + images = mydb.get_rows(FROM="images", WHERE={'location':image_dict['location'], 'metadata':image_dict['metadata']}) + else: + images = mydb.get_rows(FROM="images", WHERE={'universal_name':image_dict['universal_name'], 'checksum':image_dict['checksum']}) if len(images)>=1: image_mano_id = images[0]['uuid'] else: #create image temp_image_dict={'name':image_dict['name'], 'description':image_dict.get('description',None), - 'location':image_dict['location'], 'metadata':image_dict.get('metadata',None) + 'location':image_dict['location'], 'metadata':image_dict.get('metadata',None), + 'universal_name':image_dict['universal_name'] , 'checksum':image_dict['checksum'] } image_mano_id = mydb.new_row('images', temp_image_dict, add_uuid=True) rollback_list.append({"where":"mano", "what":"image","uuid":image_mano_id}) @@ -274,7 +278,21 @@ def create_or_use_image(mydb, vims, image_dict, rollback_list, only_create_at_vi image_db = mydb.get_rows(FROM="datacenters_images", WHERE={'datacenter_id':vim_id, 'image_id':image_mano_id}) #look at VIM if this image exist try: - image_vim_id = vim.get_image_id_from_path(image_dict['location']) + if image_dict['location'] is not None: + image_vim_id = vim.get_image_id_from_path(image_dict['location']) + else: + filter_dict={} + filter_dict['name']=image_dict['universal_name'] + filter_dict['checksum']=image_dict['checksum'] + #logger.debug('>>>>>>>> Filter dict: %s', str(filter_dict)) + vim_images = vim.get_image_list(filter_dict) + if len(vim_images) > 1: + raise NfvoException("More than one candidate VIM image found for filter: " + str(filter_dict), HTTP_Conflict) + elif len(vim_images) == 0: + raise NfvoException("Image not found at VIM with filter: '%s'", str(filter_dict)) + else: + image_vim_id = vim_images[0].id + except vimconn.vimconnNotFoundException as e: #Create the image in VIM try: @@ -289,10 +307,10 @@ def create_or_use_image(mydb, vims, image_dict, rollback_list, only_create_at_vi logger.warn("Error creating image at VIM: %s", str(e)) continue except vimconn.vimconnException as e: - logger.warn("Error contacting VIM to know if the image exist at VIM: %s", str(e)) + logger.warn("Error contacting VIM to know if the image exists at VIM: %s", str(e)) image_vim_id = str(e) continue - #if reach here the image has been create or exist + #if we reach here, the image has been created or existed if len(image_db)==0: #add new vim_id at datacenters_images mydb.new_row('datacenters_images', {'datacenter_id':vim_id, 'image_id':image_mano_id, 'vim_id': image_vim_id, 'created':image_created}) @@ -326,9 +344,14 @@ def create_or_use_flavor(mydb, vims, flavor_dict, rollback_list, only_create_at_ if 'extended' in flavor_dict and flavor_dict['extended']!=None: dev_nb=0 for device in flavor_dict['extended'].get('devices',[]): - if "image" not in device: + if "image" not in device or "image name" not in device: continue - image_dict={'location':device['image'], 'name':flavor_dict['name']+str(dev_nb)+"-img", 'description':flavor_dict.get('description')} + image_dict={} + image_dict['name']=device.get('image name',flavor_dict['name']+str(dev_nb)+"-img") + image_dict['universal_name']=device.get('image name') + image_dict['description']=flavor_dict['name']+str(dev_nb)+"-img" + image_dict['location']=device.get('image') + image_dict['checksum']=device.get('image checksum') image_metadata_dict = device.get('image metadata', None) image_metadata_str = None if image_metadata_dict != None: @@ -374,9 +397,14 @@ def create_or_use_flavor(mydb, vims, flavor_dict, rollback_list, only_create_at_ dev_nb=0 for index in range(0,len(devices_original)) : device=devices_original[index] - if "image" not in device: + if "image" not in device or "image name" not in device: continue - image_dict={'location':device['image'], 'name':flavor_dict['name']+str(dev_nb)+"-img", 'description':flavor_dict.get('description')} + image_dict={} + image_dict['name']=device.get('image name',flavor_dict['name']+str(dev_nb)+"-img") + image_dict['universal_name']=device.get('image name') + image_dict['description']=flavor_dict['name']+str(dev_nb)+"-img" + image_dict['location']=device.get('image') + image_dict['checksum']=device.get('image checksum') image_metadata_dict = device.get('image metadata', None) image_metadata_str = None if image_metadata_dict != None: @@ -472,7 +500,7 @@ def new_vnf(mydb, tenant_id, vnf_descriptor): #print "Flavor name: %s. Description: %s" % (VNFCitem["name"]+"-flv", VNFCitem["description"]) myflavorDict = {} - myflavorDict["name"] = vnfc['name']+"-flv" + myflavorDict["name"] = vnfc['name']+"-flv" #Maybe we could rename the flavor by using the field "image name" if exists myflavorDict["description"] = VNFCitem["description"] myflavorDict["ram"] = vnfc.get("ram", 0) myflavorDict["vcpus"] = vnfc.get("vcpus", 0) @@ -520,7 +548,12 @@ def new_vnf(mydb, tenant_id, vnf_descriptor): #In case this integration is made, the VNFCDict might become a VNFClist. for vnfc in vnf_descriptor['vnf']['VNFC']: #print "Image name: %s. Description: %s" % (vnfc['name']+"-img", VNFCDict[vnfc['name']]['description']) - image_dict={'location':vnfc['VNFC image'], 'name':vnfc['name']+"-img", 'description':VNFCDict[vnfc['name']]['description']} + image_dict={} + image_dict['name']=vnfc.get('image name',vnf_name+"-"+vnfc['name']+"-img") + image_dict['universal_name']=vnfc.get('image name') + image_dict['description']=vnfc.get('image name', VNFCDict[vnfc['name']]['description']) + image_dict['location']=vnfc.get('VNFC image') + image_dict['checksum']=vnfc.get('image checksum') image_metadata_dict = vnfc.get('image metadata', None) image_metadata_str = None if image_metadata_dict is not None: @@ -530,7 +563,7 @@ def new_vnf(mydb, tenant_id, vnf_descriptor): image_id = create_or_use_image(mydb, vims, image_dict, rollback_list) #print "Image id for VNFC %s: %s" % (vnfc['name'],image_id) VNFCDict[vnfc['name']]["image_id"] = image_id - VNFCDict[vnfc['name']]["image_path"] = vnfc['VNFC image'] + VNFCDict[vnfc['name']]["image_path"] = vnfc.get('VNFC image') # Step 7. Storing the VNF descriptor in the repository @@ -605,7 +638,7 @@ def new_vnf_v02(mydb, tenant_id, vnf_descriptor): #print "Flavor name: %s. Description: %s" % (VNFCitem["name"]+"-flv", VNFCitem["description"]) myflavorDict = {} - myflavorDict["name"] = vnfc['name']+"-flv" + myflavorDict["name"] = vnfc['name']+"-flv" #Maybe we could rename the flavor by using the field "image name" if exists myflavorDict["description"] = VNFCitem["description"] myflavorDict["ram"] = vnfc.get("ram", 0) myflavorDict["vcpus"] = vnfc.get("vcpus", 0) @@ -653,7 +686,12 @@ def new_vnf_v02(mydb, tenant_id, vnf_descriptor): #In case this integration is made, the VNFCDict might become a VNFClist. for vnfc in vnf_descriptor['vnf']['VNFC']: #print "Image name: %s. Description: %s" % (vnfc['name']+"-img", VNFCDict[vnfc['name']]['description']) - image_dict={'location':vnfc['VNFC image'], 'name':vnfc['name']+"-img", 'description':VNFCDict[vnfc['name']]['description']} + image_dict={} + image_dict['name']=vnfc.get('image name',vnf_name+"-"+vnfc['name']+"-img") + image_dict['universal_name']=vnfc.get('image name') + image_dict['description']=vnfc.get('image name', VNFCDict[vnfc['name']]['description']) + image_dict['location']=vnfc.get('VNFC image') + image_dict['checksum']=vnfc.get('image checksum') image_metadata_dict = vnfc.get('image metadata', None) image_metadata_str = None if image_metadata_dict is not None: @@ -663,7 +701,7 @@ def new_vnf_v02(mydb, tenant_id, vnf_descriptor): image_id = create_or_use_image(mydb, vims, image_dict, rollback_list) #print "Image id for VNFC %s: %s" % (vnfc['name'],image_id) VNFCDict[vnfc['name']]["image_id"] = image_id - VNFCDict[vnfc['name']]["image_path"] = vnfc['VNFC image'] + VNFCDict[vnfc['name']]["image_path"] = vnfc.get('VNFC image') # Step 7. Storing the VNF descriptor in the repository @@ -1651,9 +1689,9 @@ def create_instance(mydb, tenant_id, instance_dict): #print "Checking that the scenario exists and getting the scenario dictionary" scenarioDict = mydb.get_scenario(scenario, tenant_id, default_datacenter_id) - #logger.debug("Dictionaries before merging") - #logger.debug("InstanceDict:\n{}".format(yaml.safe_dump(instance_dict,default_flow_style=False, width=256))) - #logger.debug("ScenarioDict:\n{}".format(yaml.safe_dump(scenarioDict,default_flow_style=False, width=256))) + #logger.debug(">>>>>>> Dictionaries before merging") + #logger.debug(">>>>>>> InstanceDict:\n{}".format(yaml.safe_dump(instance_dict,default_flow_style=False, width=256))) + #logger.debug(">>>>>>> ScenarioDict:\n{}".format(yaml.safe_dump(scenarioDict,default_flow_style=False, width=256))) scenarioDict['datacenter_tenant_id'] = default_datacenter_tenant_id scenarioDict['datacenter_id'] = default_datacenter_id @@ -1731,7 +1769,10 @@ def create_instance(mydb, tenant_id, instance_dict): ipprofile['dhcp_enabled'] = ipprofile['dhcp'].get('enabled',True) ipprofile['dhcp_count'] = ipprofile['dhcp'].get('count',None) del ipprofile['dhcp'] - update(scenario_net['ip_profile'],ipprofile) + if 'ip_profile' not in scenario_net: + scenario_net['ip_profile'] = ipprofile + else: + update(scenario_net['ip_profile'],ipprofile) for interface in net_instance_desc.get('interfaces', () ): if 'ip_address' in interface: for vnf in scenarioDict['vnfs']: @@ -1740,7 +1781,7 @@ def create_instance(mydb, tenant_id, instance_dict): if interface['vnf_interface'] == vnf_interface['external_name']: vnf_interface['ip_address']=interface['ip_address'] - #logger.debug("Merged dictionary") + #logger.debug(">>>>>>>> Merged dictionary") logger.debug("Creating instance scenario-dict MERGED:\n%s", yaml.safe_dump(scenarioDict, indent=4, default_flow_style=False))