X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=nfvo.py;h=dd3eb55bc2edda1661f6baf315eccc417ca84d98;hb=60f4d2287e906417f151f8b41f07493eb1bf5af4;hp=7dbd51d939804800f552d7ab009628de92d8e735;hpb=3ae39742402e1cf92cffc98a72a84bc8dac0de24;p=osm%2FRO.git diff --git a/nfvo.py b/nfvo.py index 7dbd51d9..dd3eb55b 100644 --- a/nfvo.py +++ b/nfvo.py @@ -41,10 +41,11 @@ from db_base import db_base_Exception global global_config global vimconn_imported +global logger vimconn_imported={} #dictionary with VIM type as key, loaded module as value -logger = logging.getLogger('mano.nfvo') +logger = logging.getLogger('openmano.nfvo') class NfvoException(Exception): def __init__(self, message, http_code): @@ -952,6 +953,7 @@ def new_scenario(mydb, tenant_id, topo): #1.4 get list of connections conections = topo['topology']['connections'] conections_list = [] + conections_list_name = [] for k in conections.keys(): if type(conections[k]['nodes'])==dict: #dict with node:iface pairs ifaces_list = conections[k]['nodes'].items() @@ -980,7 +982,7 @@ def new_scenario(mydb, tenant_id, topo): if con_type == "dataplane_net" or con_type == "bridge_net": other_nets[k]["model"] = con_type - + conections_list_name.append(k) conections_list.append(set(ifaces_list)) #from list to set to operate as a set (this conversion removes elements that are repeated in a list) #print set(ifaces_list) #check valid VNF and iface names @@ -1000,6 +1002,7 @@ def new_scenario(mydb, tenant_id, topo): if len(conections_list[index] & conections_list[index2])>0: #common interface, join nets conections_list[index] |= conections_list[index2] del conections_list[index2] + del conections_list_name[index2] else: index2 += 1 conections_list[index] = list(conections_list[index]) # from set to list again @@ -1106,7 +1109,8 @@ def new_scenario(mydb, tenant_id, topo): net_type_bridge=False net_type_data=False net_target = "__-__net"+str(net_nb) - net_list[net_target] = {'name': "net-"+str(net_nb), 'description':"net-%s in scenario %s" %(net_nb,topo['name']), + net_list[net_target] = {'name': conections_list_name[net_nb], #"net-"+str(net_nb), + 'description':"net-%s in scenario %s" %(net_nb,topo['name']), 'external':False} for iface in con: vnfs[ iface[0] ]['ifaces'][ iface[1] ]['net_key'] = net_target @@ -1182,7 +1186,7 @@ def new_scenario_v02(mydb, tenant_id, scenario_dict): where={} where_or={"tenant_id": tenant_id, 'public': "true"} error_text = "" - error_pos = "'topology':'nodes':'" + name + "'" + error_pos = "'scenario':'vnfs':'" + name + "'" if 'vnf_id' in vnf: error_text += " 'vnf_id' " + vnf['vnf_id'] where['uuid'] = vnf['vnf_id'] @@ -1190,7 +1194,7 @@ def new_scenario_v02(mydb, tenant_id, scenario_dict): error_text += " 'vnf_name' " + vnf['vnf_name'] where['name'] = vnf['vnf_name'] if len(where) == 0: - raise NfvoException("Needed a 'vnf_id' or 'VNF model' at " + error_pos, HTTP_Bad_Request) + raise NfvoException("Needed a 'vnf_id' or 'vnf_name' at " + error_pos, HTTP_Bad_Request) vnf_db = mydb.get_rows(SELECT=('uuid','name','description'), FROM='vnfs', WHERE=where, @@ -1316,6 +1320,7 @@ def start_scenario(mydb, tenant_id, scenario_id, instance_scenario_name, instanc sce_net['vim_id'] = network_id auxNetDict['scenario'][sce_net['uuid']] = network_id rollbackList.append({'what':'network','where':'vim','vim_id':datacenter_id,'uuid':network_id}) + sce_net["created"] = True else: if sce_net['vim_id'] == None: error_text = "Error, datacenter '%s' does not have external network '%s'." % (datacenter_name, sce_net['name']) @@ -1349,6 +1354,7 @@ def start_scenario(mydb, tenant_id, scenario_id, instance_scenario_name, instanc auxNetDict[sce_vnf['uuid']] = {} auxNetDict[sce_vnf['uuid']][net['uuid']] = network_id rollbackList.append({'what':'network','where':'vim','vim_id':datacenter_id,'uuid':network_id}) + net["created"] = True #print "auxNetDict:" #print yaml.safe_dump(auxNetDict, indent=4, default_flow_style=False) @@ -1521,7 +1527,7 @@ def new_scenario_v03(mydb, tenant_id, scenario_dict): where={} where_or={"tenant_id": tenant_id, 'public': "true"} error_text = "" - error_pos = "'topology':'nodes':'" + name + "'" + error_pos = "'scenario':'vnfs':'" + name + "'" if 'vnf_id' in vnf: error_text += " 'vnf_id' " + vnf['vnf_id'] where['uuid'] = vnf['vnf_id'] @@ -1529,7 +1535,7 @@ def new_scenario_v03(mydb, tenant_id, scenario_dict): error_text += " 'vnf_name' " + vnf['vnf_name'] where['name'] = vnf['vnf_name'] if len(where) == 0: - raise NfvoException("Needed a 'vnf_id' or 'VNF model' at " + error_pos, HTTP_Bad_Request) + raise NfvoException("Needed a 'vnf_id' or 'vnf_name' at " + error_pos, HTTP_Bad_Request) vnf_db = mydb.get_rows(SELECT=('uuid','name','description'), FROM='vnfs', WHERE=where, @@ -1726,7 +1732,7 @@ def create_instance(mydb, tenant_id, instance_dict): ipprofile['dhcp_count'] = ipprofile['dhcp'].get('count',None) del ipprofile['dhcp'] update(scenario_net['ip_profile'],ipprofile) - for interface in net_instance_desc['interfaces']: + for interface in net_instance_desc.get('interfaces', () ): if 'ip_address' in interface: for vnf in scenarioDict['vnfs']: if interface['vnf'] == vnf['name']: @@ -1816,6 +1822,7 @@ def create_instance(mydb, tenant_id, instance_dict): sce_net["vim_id_sites"][datacenter_id] = network_id auxNetDict['scenario'][sce_net['uuid']][datacenter_id] = network_id rollbackList.append({'what':'network', 'where':'vim', 'vim_id':datacenter_id, 'uuid':network_id}) + sce_net["created"] = True #2. Creating new nets (vnf internal nets) in the VIM" #For each vnf net, we create it and we add it to instanceNetlist. @@ -1839,6 +1846,8 @@ def create_instance(mydb, tenant_id, instance_dict): auxNetDict[sce_vnf['uuid']] = {} auxNetDict[sce_vnf['uuid']][net['uuid']] = network_id rollbackList.append({'what':'network','where':'vim','vim_id':datacenter_id,'uuid':network_id}) + net["created"] = True + #print "auxNetDict:" #print yaml.safe_dump(auxNetDict, indent=4, default_flow_style=False) @@ -2010,7 +2019,7 @@ def delete_instance(mydb, tenant_id, instance_id): #2.2 deleting NETS #net_fail_list=[] for net in instanceDict['nets']: - if net['external']: + if not net['created']: continue #skip not created nets if not myvim: continue @@ -2076,7 +2085,7 @@ def refresh_instance(mydb, nfvo_tenant, instanceDict, datacenter=None, vim_tenan if iface["type"]=="mgmt": has_mgmt_iface = True if vm_dict[vm_id]['status'] == "ACTIVE:NoMgmtIP" and not has_mgmt_iface: - vm_dict[vm_id]['status'] = "ACTIVE" + vm_dict[vm_id]['status'] = "ACTIVE" if vm['status'] != vm_dict[vm_id]['status'] or vm.get('error_msg')!=vm_dict[vm_id].get('error_msg') or vm.get('vim_info')!=vm_dict[vm_id].get('vim_info'): vm['status'] = vm_dict[vm_id]['status'] vm['error_msg'] = vm_dict[vm_id].get('error_msg') @@ -2092,16 +2101,16 @@ def refresh_instance(mydb, nfvo_tenant, instanceDict, datacenter=None, vim_tenan # 2.2. Update in openmano DB the interface VMs for interface in interfaces: #translate from vim_net_id to instance_net_id - network_id=None + network_id_list=[] for net in instanceDict['nets']: if net["vim_net_id"] == interface["vim_net_id"]: - network_id = net["uuid"] - break - if not network_id: + network_id_list.append(net["uuid"]) + if not network_id_list: continue del interface["vim_net_id"] - try: - mydb.update_rows('instance_interfaces', UPDATE=interface, WHERE={'instance_vm_id':vm["uuid"], "instance_net_id":network_id}) + try: + for network_id in network_id_list: + mydb.update_rows('instance_interfaces', UPDATE=interface, WHERE={'instance_vm_id':vm["uuid"], "instance_net_id":network_id}) except db_base_Exception as e: logger.error( "nfvo.refresh_instance error with vm=%s, interface_net_id=%s", vm["uuid"], network_id)