X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Fnfvo.py;h=281b8f9693235dd4f5e63aa1a9ec8b111d97b1b6;hb=4491ba91e3e2aab34e815113e33ec77d3c49f224;hp=4b7ecc415ae12c9139bc90c5dbbd80b95c70bfae;hpb=5751ab9862f721c76b132bdb84a9759ef0cbe659;p=osm%2FRO.git diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 4b7ecc41..281b8f96 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -151,14 +151,12 @@ def get_non_used_wim_name(wim_name, wim_id, tenant_name, tenant_id): def start_service(mydb, persistence=None, wim=None): global db, global_config - db = nfvo_db.nfvo_db() + db = nfvo_db.nfvo_db(lock=db_lock) + mydb.lock = db_lock db.connect(global_config['db_host'], global_config['db_user'], global_config['db_passwd'], global_config['db_name']) global ovim - if persistence: - persistence.lock = db_lock - else: - persistence = WimPersistence(db, lock=db_lock) + persistence = persistence or WimPersistence(db) # Initialize openvim for SDN control # TODO: Avoid static configuration by adding new parameters to openmanod.cfg @@ -2410,7 +2408,7 @@ def new_nsd_v3(mydb, tenant_id, nsd_descriptor): str(iface.get("vnfd-id-ref"))[:255]), httperrors.Bad_Request) interface_uuid = existing_ifaces[0]["uuid"] - if existing_ifaces[0]["iface_type"] == "data" and not db_sce_net["type"]: + if existing_ifaces[0]["iface_type"] == "data": db_sce_net["type"] = "data" sce_interface_uuid = str(uuid4()) uuid_list.append(sce_net_uuid) @@ -2442,7 +2440,6 @@ def new_nsd_v3(mydb, tenant_id, nsd_descriptor): db_sce_vnffgs.append(db_sce_vnffg) # deal with rsps - db_sce_rsps = [] for rsp in vnffg.get("rsp").itervalues(): sce_rsp_uuid = str(uuid4()) uuid_list.append(sce_rsp_uuid) @@ -2453,7 +2450,6 @@ def new_nsd_v3(mydb, tenant_id, nsd_descriptor): "id": get_str(rsp, "id", 255), # only useful to link with classifiers; will be removed later in the code } db_sce_rsps.append(db_sce_rsp) - db_sce_rsp_hops = [] for iface in rsp.get("vnfd-connection-point-ref").itervalues(): vnf_index = str(iface['member-vnf-index-ref']) if_order = int(iface['order']) @@ -2506,7 +2502,6 @@ def new_nsd_v3(mydb, tenant_id, nsd_descriptor): db_sce_rsp_hops.append(db_sce_rsp_hop) # deal with classifiers - db_sce_classifiers = [] for classifier in vnffg.get("classifier").itervalues(): sce_classifier_uuid = str(uuid4()) uuid_list.append(sce_classifier_uuid) @@ -2545,7 +2540,6 @@ def new_nsd_v3(mydb, tenant_id, nsd_descriptor): db_sce_classifier["sce_rsp_id"] = rsp["uuid"] db_sce_classifiers.append(db_sce_classifier) - db_sce_classifier_matches = [] for match in classifier.get("match-attributes").itervalues(): sce_classifier_match_uuid = str(uuid4()) uuid_list.append(sce_classifier_match_uuid) @@ -2636,7 +2630,7 @@ def start_scenario(mydb, tenant_id, scenario_id, instance_scenario_name, instanc #We should use the dictionary as input parameter for new_network #print myNetDict if not sce_net["external"]: - network_id = myvim.new_network(myNetName, myNetType, myNetIPProfile) + network_id, _ = myvim.new_network(myNetName, myNetType, myNetIPProfile) #print "New VIM network created for scenario %s. Network id: %s" % (scenarioDict['name'],network_id) sce_net['vim_id'] = network_id auxNetDict['scenario'][sce_net['uuid']] = network_id @@ -2669,7 +2663,7 @@ def start_scenario(mydb, tenant_id, scenario_id, instance_scenario_name, instanc #print myNetDict #TODO: #We should use the dictionary as input parameter for new_network - network_id = myvim.new_network(myNetName, myNetType, myNetIPProfile) + network_id, _ = myvim.new_network(myNetName, myNetType, myNetIPProfile) #print "VIM network id for scenario %s: %s" % (scenarioDict['name'],network_id) net['vim_id'] = network_id if sce_vnf['uuid'] not in auxNetDict: @@ -3000,6 +2994,7 @@ def create_instance(mydb, tenant_id, instance_dict): myvims = {} myvim_threads_id = {} datacenter = instance_dict.get("datacenter") + default_wim_account = instance_dict.get("wim_account") default_datacenter_id, vim = get_datacenter_by_name_uuid(mydb, tenant_id, datacenter) myvims[default_datacenter_id] = vim myvim_threads_id[default_datacenter_id], _ = get_vim_thread(mydb, tenant_id, default_datacenter_id) @@ -3165,7 +3160,9 @@ def create_instance(mydb, tenant_id, instance_dict): # However, this is not possible yet. for net_name, net_instance_desc in instance_dict.get("networks", {}).iteritems(): for scenario_net in scenarioDict['nets']: - if net_name == scenario_net["name"]: + if net_name == scenario_net.get("name") or net_name == scenario_net.get("osm_id") or net_name == scenario_net.get("uuid"): + if "wim_account" in net_instance_desc and net_instance_desc["wim_account"] is not None: + scenario_net["wim_account"] = net_instance_desc["wim_account"] if 'ip-profile' in net_instance_desc: ipprofile_db = ip_profile_IM2RO(net_instance_desc['ip-profile']) if 'ip_profile' not in scenario_net: @@ -3202,19 +3199,28 @@ def create_instance(mydb, tenant_id, instance_dict): break if not involved_datacenters: involved_datacenters.append(default_datacenter_id) + target_wim_account = sce_net.get("wim_account", default_wim_account) # --> WIM # TODO: use this information during network creation wim_account_id = wim_account_name = None if len(involved_datacenters) > 1 and 'uuid' in sce_net: - # OBS: sce_net without uuid are used internally to VNFs - # and the assumption is that VNFs will not be split among - # different datacenters - wim_account = wim_engine.find_suitable_wim_account( - involved_datacenters, tenant_id) - wim_account_id = wim_account['uuid'] - wim_account_name = wim_account['name'] - wim_usage[sce_net['uuid']] = wim_account_id + if target_wim_account is None or target_wim_account is True: # automatic selection of WIM + # OBS: sce_net without uuid are used internally to VNFs + # and the assumption is that VNFs will not be split among + # different datacenters + wim_account = wim_engine.find_suitable_wim_account( + involved_datacenters, tenant_id) + wim_account_id = wim_account['uuid'] + wim_account_name = wim_account['name'] + wim_usage[sce_net['uuid']] = wim_account_id + elif isinstance(target_wim_account, str): # manual selection of WIM + wim_account.persist.get_wim_account_by(target_wim_account, tenant_id) + wim_account_id = wim_account['uuid'] + wim_account_name = wim_account['name'] + wim_usage[sce_net['uuid']] = wim_account_id + else: # not WIM usage + wim_usage[sce_net['uuid']] = False # <-- WIM descriptor_net = {} @@ -3582,12 +3588,14 @@ def create_instance(mydb, tenant_id, instance_dict): returned_instance = mydb.get_instance_scenario(instance_uuid) returned_instance["action_id"] = instance_action_id return returned_instance - except (NfvoException, vimconn.vimconnException, db_base_Exception) as e: + except (NfvoException, vimconn.vimconnException, wimconn.WimConnectorError, db_base_Exception) as e: message = rollback(mydb, myvims, rollbackList) if isinstance(e, db_base_Exception): error_text = "database Exception" elif isinstance(e, vimconn.vimconnException): error_text = "VIM Exception" + elif isinstance(e, wimconn.WimConnectorError): + error_text = "WIM Exception" else: error_text = "Exception" error_text += " {} {}. {}".format(type(e).__name__, str(e), message) @@ -5452,7 +5460,7 @@ def vim_action_create(mydb, tenant_id, datacenter, item, descriptor): net_public = net.pop("shared", False) net_ipprofile = net.pop("ip_profile", None) net_vlan = net.pop("vlan", None) - content = myvim.new_network(net_name, net_type, net_ipprofile, shared=net_public, vlan=net_vlan) #, **net) + content, _ = myvim.new_network(net_name, net_type, net_ipprofile, shared=net_public, vlan=net_vlan) #, **net) #If the datacenter has a SDN controller defined and the network is of dataplane type, then create the sdn network if get_sdn_controller_id(mydb, datacenter) != None and (net_type == 'data' or net_type == 'ptp'): @@ -5466,7 +5474,7 @@ def vim_action_create(mydb, tenant_id, datacenter, item, descriptor): sdn_network['type'] = net_type sdn_network['name'] = net_name sdn_network['region'] = datacenter_tenant_id - ovim_content = ovim.new_network(sdn_network) + ovim_content = ovim.new_network(sdn_network) except ovimException as e: logger.error("ovimException creating SDN network={} ".format( sdn_network) + str(e), exc_info=True)