X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fnfvo.py;h=5c0fefed27bbc11fd2f99c94f65e0733c8285b52;hb=354ead997790f4347c6256c1e703f49a6b412512;hp=494a01d696d83bbdd408a4cff5d98e226dfdfb87;hpb=d9f2b88a86bb04c44f40008c719f6ff6cd7aea2f;p=osm%2FRO.git diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 494a01d6..5c0fefed 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -392,7 +392,7 @@ def rollback(mydb, vims, rollback_list): mydb.delete_row(FROM="datacenters_images", WHERE={"datacenter_vim_id": vim["id"], "vim_id":item["uuid"]}) elif item["what"]=="flavor": vim.delete_flavor(item["uuid"]) - mydb.delete_row(FROM="datacenters_flavors", WHERE={"datacenter_id": vim["id"], "vim_id":item["uuid"]}) + mydb.delete_row(FROM="datacenters_flavors", WHERE={"datacenter_vim_id": vim["id"], "vim_id":item["uuid"]}) elif item["what"]=="network": vim.delete_network(item["uuid"]) elif item["what"]=="vm": @@ -621,7 +621,7 @@ def create_or_use_image(mydb, vims, image_dict, rollback_list, only_create_at_vi def create_or_use_flavor(mydb, vims, flavor_dict, rollback_list, only_create_at_vim=False, return_on_error = None): - temp_flavor_dict= {'disk':flavor_dict.get('disk',1), + temp_flavor_dict= {'disk':flavor_dict.get('disk',0), 'ram':flavor_dict.get('ram'), 'vcpus':flavor_dict.get('vcpus'), } @@ -828,7 +828,7 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): try: myvnfd = vnfd_catalog.vnfd() try: - pybindJSONDecoder.load_ietf_json(vnf_descriptor, None, None, obj=myvnfd) + pybindJSONDecoder.load_ietf_json(vnf_descriptor, None, None, obj=myvnfd, path_helper=True) except Exception as e: raise NfvoException("Error. Invalid VNF descriptor format " + str(e), HTTP_Bad_Request) db_vnfs = [] @@ -1071,7 +1071,7 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): "name": get_str(vdu, "name", 250) + "-flv", "vcpus": int(vdu["vm-flavor"].get("vcpu-count", 1)), "ram": int(vdu["vm-flavor"].get("memory-mb", 1)), - "disk": int(vdu["vm-flavor"].get("storage-gb", 1)), + "disk": int(vdu["vm-flavor"].get("storage-gb", 0)), } # TODO revise the case of several numa-node-policy node extended = {} @@ -1120,7 +1120,7 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): extended_text = yaml.safe_dump(extended, default_flow_style=True, width=256) db_flavor["extended"] = extended_text # look if flavor exist - temp_flavor_dict = {'disk': db_flavor.get('disk', 1), + temp_flavor_dict = {'disk': db_flavor.get('disk', 0), 'ram': db_flavor.get('ram'), 'vcpus': db_flavor.get('vcpus'), 'extended': db_flavor.get('extended') @@ -1262,7 +1262,7 @@ def new_vnf(mydb, tenant_id, vnf_descriptor): myflavorDict["description"] = VNFCitem["description"] myflavorDict["ram"] = vnfc.get("ram", 0) myflavorDict["vcpus"] = vnfc.get("vcpus", 0) - myflavorDict["disk"] = vnfc.get("disk", 1) + myflavorDict["disk"] = vnfc.get("disk", 0) myflavorDict["extended"] = {} devices = vnfc.get("devices") @@ -1398,7 +1398,7 @@ def new_vnf_v02(mydb, tenant_id, vnf_descriptor): myflavorDict["description"] = VNFCitem["description"] myflavorDict["ram"] = vnfc.get("ram", 0) myflavorDict["vcpus"] = vnfc.get("vcpus", 0) - myflavorDict["disk"] = vnfc.get("disk", 1) + myflavorDict["disk"] = vnfc.get("disk", 0) myflavorDict["extended"] = {} devices = vnfc.get("devices") @@ -1585,26 +1585,33 @@ def delete_vnf(mydb,tenant_id,vnf_id,datacenter=None,vim_tenant=None): continue #flavor not used, must be deleted #delelte at VIM - c = mydb.get_rows(FROM='datacenters_flavors', WHERE={'flavor_id':flavor}) + c = mydb.get_rows(FROM='datacenters_flavors', WHERE={'flavor_id': flavor}) for flavor_vim in c: - if flavor_vim["datacenter_vim_id"] not in vims: # TODO change to datacenter_tenant_id + if not flavor_vim['created']: # skip this flavor because not created by openmano continue - if flavor_vim['created']=='false': #skip this flavor because not created by openmano + # look for vim + myvim = None + for vim in vims.values(): + if vim["config"]["datacenter_tenant_id"] == flavor_vim["datacenter_vim_id"]: + myvim = vim + break + if not myvim: continue - myvim=vims[ flavor_vim["datacenter_id"] ] try: myvim.delete_flavor(flavor_vim["vim_id"]) - except vimconn.vimconnNotFoundException as e: - logger.warn("VIM flavor %s not exist at datacenter %s", flavor_vim["vim_id"], flavor_vim["datacenter_id"] ) + except vimconn.vimconnNotFoundException: + logger.warn("VIM flavor %s not exist at datacenter %s", flavor_vim["vim_id"], + flavor_vim["datacenter_vim_id"] ) except vimconn.vimconnException as e: logger.error("Not possible to delete VIM flavor %s from datacenter %s: %s %s", - flavor_vim["vim_id"], flavor_vim["datacenter_id"], type(e).__name__, str(e)) - undeletedItems.append("flavor {} from VIM {}".format(flavor_vim["vim_id"], flavor_vim["datacenter_id"] )) - #delete flavor from Database, using table flavors and with cascade foreign key also at datacenters_flavors + flavor_vim["vim_id"], flavor_vim["datacenter_vim_id"], type(e).__name__, str(e)) + undeletedItems.append("flavor {} from VIM {}".format(flavor_vim["vim_id"], + flavor_vim["datacenter_vim_id"])) + # delete flavor from Database, using table flavors and with cascade foreign key also at datacenters_flavors mydb.delete_row_by_id('flavors', flavor) except db_base_Exception as e: logger.error("delete_vnf_error. Not possible to get flavor details and delete '%s'. %s", flavor, str(e)) - undeletedItems.append("flavor %s" % flavor) + undeletedItems.append("flavor {}".format(flavor)) for image in imageList: @@ -2784,10 +2791,6 @@ def create_instance(mydb, tenant_id, instance_dict): # 0.1 parse cloud-config parameters cloud_config = unify_cloud_config(instance_dict.get("cloud-config"), scenarioDict.get("cloud-config")) - # We add the RO key to cloud_config - if tenant[0].get('RO_pub_key'): - RO_key = {"key-pairs": [tenant[0]['RO_pub_key']]} - cloud_config = unify_cloud_config(cloud_config, RO_key) # 0.2 merge instance information into scenario # Ideally, the operation should be as simple as: update(scenarioDict,instance_dict) @@ -3014,6 +3017,9 @@ def create_instance(mydb, tenant_id, instance_dict): # myvim.new_vminstance(self,vimURI,tenant_id,name,description,image_id,flavor_id,net_dict) sce_vnf_list = sorted(scenarioDict['vnfs'], key=lambda k: k['name']) for sce_vnf in sce_vnf_list: + ssh_access = None + if sce_vnf.get('mgmt_access'): + ssh_access = sce_vnf['mgmt_access'].get('config-access', {}).get('ssh-access') vnf_availability_zones = [] for vm in sce_vnf['vms']: vm_av = vm.get('availability_zone') @@ -3163,10 +3169,15 @@ def create_instance(mydb, tenant_id, instance_dict): # print "networks", yaml.safe_dump(myVMDict['networks'], indent=4, default_flow_style=False) # print "interfaces", yaml.safe_dump(vm['interfaces'], indent=4, default_flow_style=False) # print ">>>>>>>>>>>>>>>>>>>>>>>>>>>" + + # We add the RO key to cloud_config if vnf will need ssh access + cloud_config_vm = cloud_config + if ssh_access and ssh_access['required'] and ssh_access['default-user'] and tenant[0].get('RO_pub_key'): + RO_key = {"key-pairs": [tenant[0]['RO_pub_key']]} + cloud_config_vm = unify_cloud_config(cloud_config_vm, RO_key) if vm.get("boot_data"): - cloud_config_vm = unify_cloud_config(vm["boot_data"], cloud_config) - else: - cloud_config_vm = cloud_config + cloud_config_vm = unify_cloud_config(vm["boot_data"], cloud_config_vm) + if myVMDict.get('availability_zone'): av_index = vnf_availability_zones.index(myVMDict['availability_zone']) else: @@ -3754,7 +3765,7 @@ def new_datacenter(mydb, datacenter_descriptor): except (IOError, ImportError): # if module_info and module_info[0]: # file.close(module_info[0]) - raise NfvoException("Incorrect datacenter type '{}'. Plugin '{}'.py not installed".format(datacenter_type, module), HTTP_Bad_Request) + raise NfvoException("Incorrect datacenter type '{}'. Plugin '{}.py' not installed".format(datacenter_type, module), HTTP_Bad_Request) datacenter_id = mydb.new_row("datacenters", datacenter_descriptor, add_uuid=True, confidential_data=True) return datacenter_id