X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fnfvo.py;h=01ac0175e7fee65e3c2cfbf645d79dbd6aa31f91;hb=a43bd9eccf7ce23220a928273e1b16341eeb26b9;hp=f4a2d798bbd4b39bde3607368a6a3306f882302a;hpb=31e141b7336c646af63b674414f8c27cf6746bb3;p=osm%2FRO.git diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index f4a2d798..01ac0175 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -943,6 +943,7 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): cp_name2iface_uuid = {} cp_name2vm_uuid = {} cp_name2db_interface = {} + vdu_id2cp_name = {} # stored only when one external connection point is presented at this VDU # table vms (vdus) vdu_id2uuid = {} @@ -960,6 +961,7 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): "osm_id": vdu_id, "name": get_str(vdu, "name", 255), "description": get_str(vdu, "description", 255), + "pdu_type": get_str(vdu, "pdu-type", 255), "vnf_id": vnf_uuid, } vdu_id2uuid[db_vm["osm_id"]] = vm_uuid @@ -1049,7 +1051,6 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): # table interfaces (internal/external interfaces) flavor_epa_interfaces = [] - vdu_id2cp_name = {} # stored only when one external connection point is presented at this VDU # for iface in chain(vdu.get("internal-interface").itervalues(), vdu.get("external-interface").itervalues()): for iface in vdu.get("interface").itervalues(): flavor_epa_interface = {} @@ -1240,7 +1241,8 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): "'member-vdus':'{vdu}'. Reference to a non-existing vdu".format( vnf=vnfd_id, pg=pg_name, vdu=vdu_id), HTTP_Bad_Request) - db_vms[vdu_id2db_table_index[vdu_id]]["availability_zone"] = pg_name + if vdu_id2db_table_index[vdu_id]: + db_vms[vdu_id2db_table_index[vdu_id]]["availability_zone"] = pg_name # TODO consider the case of isolation and not colocation # if pg.get("strategy") == "ISOLATION": @@ -1256,20 +1258,22 @@ def new_vnfd_v3(mydb, tenant_id, vnf_descriptor): mgmt_access["vm_id"] = vdu_id2uuid[vnfd["mgmt-interface"]["vdu-id"]] # if only one cp is defined by this VDU, mark this interface as of type "mgmt" if vdu_id2cp_name.get(mgmt_vdu_id): - cp_name2db_interface[vdu_id2cp_name[mgmt_vdu_id]]["type"] = "mgmt" + if cp_name2db_interface[vdu_id2cp_name[mgmt_vdu_id]]: + cp_name2db_interface[vdu_id2cp_name[mgmt_vdu_id]]["type"] = "mgmt" if vnfd["mgmt-interface"].get("ip-address"): mgmt_access["ip-address"] = str(vnfd["mgmt-interface"].get("ip-address")) if vnfd["mgmt-interface"].get("cp"): if vnfd["mgmt-interface"]["cp"] not in cp_name2iface_uuid: - raise NfvoException("Error. Invalid VNF descriptor at 'vnfd[{vnf}]':'mgmt-interface':'cp':'{cp}'. " + raise NfvoException("Error. Invalid VNF descriptor at 'vnfd[{vnf}]':'mgmt-interface':'cp'['{cp}']. " "Reference to a non-existing connection-point".format( vnf=vnfd_id, cp=vnfd["mgmt-interface"]["cp"]), HTTP_Bad_Request) mgmt_access["vm_id"] = cp_name2vm_uuid[vnfd["mgmt-interface"]["cp"]] mgmt_access["interface_id"] = cp_name2iface_uuid[vnfd["mgmt-interface"]["cp"]] # mark this interface as of type mgmt - cp_name2db_interface[vnfd["mgmt-interface"]["cp"]]["type"] = "mgmt" + if cp_name2db_interface[vnfd["mgmt-interface"]["cp"]]: + cp_name2db_interface[vnfd["mgmt-interface"]["cp"]]["type"] = "mgmt" default_user = get_str(vnfd.get("vnf-configuration", {}).get("config-access", {}).get("ssh-access", {}), "default-user", 64) @@ -1600,15 +1604,15 @@ def get_vnf_id(mydb, tenant_id, vnf_id): SELECT=('vms.uuid as uuid', 'vms.osm_id as osm_id', 'vms.name as name', 'vms.description as description', 'boot_data'), WHERE={'vnfs.uuid': vnf_id} ) - if len(content)==0: - raise NfvoException("vnf '{}' not found".format(vnf_id), HTTP_Not_Found) + if len(content) != 0: + #raise NfvoException("vnf '{}' not found".format(vnf_id), HTTP_Not_Found) # change boot_data into boot-data - for vm in content: - if vm.get("boot_data"): - vm["boot-data"] = yaml.safe_load(vm["boot_data"]) - del vm["boot_data"] + for vm in content: + if vm.get("boot_data"): + vm["boot-data"] = yaml.safe_load(vm["boot_data"]) + del vm["boot_data"] - data['vnf']['VNFC'] = content + data['vnf']['VNFC'] = content #TODO: GET all the information from a VNFC and include it in the output. #GET NET @@ -3119,6 +3123,8 @@ def create_instance(mydb, tenant_id, instance_dict): if sce_vnf_ifaces.get("sce_net_id") == sce_net["uuid"]: involved_datacenters.append(vnf_datacenter) break + if not involved_datacenters: + involved_datacenters.append(default_datacenter_id) descriptor_net = {} if instance_dict.get("networks") and instance_dict["networks"].get(sce_net["name"]): @@ -3144,6 +3150,7 @@ def create_instance(mydb, tenant_id, instance_dict): myvim_thread_id = myvim_threads_id[datacenter_id] net_type = sce_net['type'] + net_vim_name = None lookfor_filter = {'admin_state_up': True, 'status': 'ACTIVE'} # 'shared': True if not net_name: @@ -3216,6 +3223,7 @@ def create_instance(mydb, tenant_id, instance_dict): db_net = { "uuid": net_uuid, 'vim_net_id': None, + "vim_name": net_vim_name, "instance_scenario_id": instance_uuid, "sce_net_id": sce_net["uuid"], "created": create_network, @@ -3276,7 +3284,7 @@ def create_instance(mydb, tenant_id, instance_dict): "sce_net2instance": sce_net2instance, } # sce_vnf_list = sorted(scenarioDict['vnfs'], key=lambda k: k['name']) - for sce_vnf in scenarioDict['vnfs']: # sce_vnf_list: + for sce_vnf in scenarioDict.get('vnfs'): # sce_vnf_list: instantiate_vnf(mydb, sce_vnf, vnf_params, vnf_params_out, rollbackList) task_index = vnf_params_out["task_index"] uuid_list = vnf_params_out["uuid_list"] @@ -3529,6 +3537,7 @@ def instantiate_vnf(mydb, sce_vnf, params, params_out, rollbackList): db_net = { "uuid": net_uuid, 'vim_net_id': None, + "vim_name": net_name, "instance_scenario_id": instance_uuid, "net_id": net["uuid"], "created": True, @@ -3580,7 +3589,7 @@ def instantiate_vnf(mydb, sce_vnf, params, params_out, rollbackList): 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']: + for vm in sce_vnf.get('vms'): vm_av = vm.get('availability_zone') if vm_av and vm_av not in vnf_availability_zones: vnf_availability_zones.append(vm_av) @@ -3614,6 +3623,10 @@ def instantiate_vnf(mydb, sce_vnf, params, params_out, rollbackList): db_instance_vnfs.append(db_instance_vnf) for vm in sce_vnf['vms']: + # skip PDUs + if vm.get("pdu_type"): + continue + myVMDict = {} sce_vnf_name = sce_vnf['member_vnf_index'] if sce_vnf['member_vnf_index'] else sce_vnf['name'] myVMDict['name'] = "{}-{}-{}".format(instance_name[:64], sce_vnf_name[:64], vm["name"][:64]) @@ -4019,7 +4032,7 @@ def delete_instance(mydb, tenant_id, instance_id): # 2.2 deleting VMs # vm_fail_list=[] - for sce_vnf in instanceDict['vnfs']: + for sce_vnf in instanceDict.get('vnfs', ()): datacenter_key = (sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"]) vimthread_affected[sce_vnf["datacenter_tenant_id"]] = None if datacenter_key not in myvims: @@ -4072,7 +4085,7 @@ def delete_instance(mydb, tenant_id, instance_id): datacenter_key = (net["datacenter_id"], net["datacenter_tenant_id"]) if datacenter_key not in myvims: try: - _,myvim_thread = get_vim_thread(mydb, tenant_id, sce_vnf["datacenter_id"], sce_vnf["datacenter_tenant_id"]) + _,myvim_thread = get_vim_thread(mydb, tenant_id, net["datacenter_id"], net["datacenter_tenant_id"]) except NfvoException as e: logger.error(str(e)) myvim_thread = None @@ -4361,13 +4374,14 @@ def instance_action(mydb,nfvo_tenant,instance_id, action_dict): raise NfvoException("Cannot find the vdu with id {}".format(vdu_id), HTTP_Not_Found) else: if not osm_vdu_id and not member_vnf_index: - raise NfvoException("Invalid imput vdu parameters. Must supply either 'vdu-id' of 'osm_vdu_id','member-vnf-index'") + raise NfvoException("Invalid input vdu parameters. Must supply either 'vdu-id' of 'osm_vdu_id','member-vnf-index'") target_vms = mydb.get_rows( # SELECT=("ivms.uuid", "ivnfs.datacenter_id", "ivnfs.datacenter_tenant_id"), FROM="instance_vms as ivms join instance_vnfs as ivnfs on ivms.instance_vnf_id=ivnfs.uuid"\ " join sce_vnfs as svnfs on ivnfs.sce_vnf_id=svnfs.uuid"\ " join vms on ivms.vm_id=vms.uuid", - WHERE={"vms.osm_id": osm_vdu_id, "svnfs.member_vnf_index": member_vnf_index}, + WHERE={"vms.osm_id": osm_vdu_id, "svnfs.member_vnf_index": member_vnf_index, + "ivnfs.instance_scenario_id": instance_id}, ORDER_BY="ivms.created_at" ) if not target_vms: