X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Fnetslice.py;h=dc2903dd6493ac87d5200c04fc7abaa57dc11fae;hb=922c41753ffbb4b526f2135a23c39f480c58e2cb;hp=6f4e5479b9d62329f6838702e542dc2fedc039f8;hpb=5e98d466e635d8e246acb6bf80d4d4c2d08acca1;p=osm%2FLCM.git diff --git a/osm_lcm/netslice.py b/osm_lcm/netslice.py index 6f4e547..dc2903d 100644 --- a/osm_lcm/netslice.py +++ b/osm_lcm/netslice.py @@ -31,7 +31,7 @@ class NetsliceLcm(LcmBase): timeout_nsi_deploy = 2 * 3600 # default global timeout for deployment a nsi - def __init__(self, db, msg, fs, lcm_tasks, config, loop, ns): + def __init__(self, msg, lcm_tasks, config, loop, ns): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', @@ -45,7 +45,7 @@ class NetsliceLcm(LcmBase): self.ro_config = config["ro_config"] self.timeout = config["timeout"] - super().__init__(db, msg, fs, self.logger) + super().__init__(msg, self.logger) def nsi_update_nsir(self, nsi_update_nsir, db_nsir, nsir_desc_RO): """ @@ -87,6 +87,7 @@ class NetsliceLcm(LcmBase): nsilcmop_operation_state = None vim_2_RO = {} RO = ROclient.ROClient(self.loop, **self.ro_config) + nsi_vld_instantiationi_params = {} def ip_profile_2_RO(ip_profile): RO_ip_profile = deepcopy((ip_profile)) @@ -128,6 +129,7 @@ class NetsliceLcm(LcmBase): :param vld_id The VLD id inside nsir to be created :param nsir_id The nsir id """ + nonlocal nsi_vld_instantiationi_params ip_vld = None mgmt_network = False RO_vld_sites = [] @@ -157,110 +159,121 @@ class NetsliceLcm(LcmBase): else: # TODO: Check VDU type in all descriptors finding SRIOV / PT # Updating network names and datacenters from instantiation parameters for each VLD - RO_ns_params = {} - RO_ns_params["name"] = netslice_vld["name"] - RO_ns_params["datacenter"] = vim_account_2_RO(db_nsir["instantiation_parameters"]["vimAccountId"]) for instantiation_params_vld in get_iterable(db_nsir["instantiation_parameters"], "netslice-vld"): if instantiation_params_vld.get("name") == netslice_vld["name"]: ip_vld = deepcopy(instantiation_params_vld) + ip_vld.pop("name") + nsi_vld_instantiationi_params[netslice_vld["name"]] = ip_vld - if netslice_vld.get("mgmt-network"): - mgmt_network = True - - # Creating scenario if vim-network-name / vim-network-id are present as instantiation parameter - # Use vim-network-id instantiation parameter - vim_network_option = None - if ip_vld: - if ip_vld.get("vim-network-id"): - vim_network_option = "vim-network-id" - elif ip_vld.get("vim-network-name"): - vim_network_option = "vim-network-name" - if ip_vld.get("ip-profile"): - populate_dict(RO_ns_params, ("networks", netslice_vld["name"], "ip-profile"), - ip_profile_2_RO(ip_vld["ip-profile"])) - - if vim_network_option: - if ip_vld.get(vim_network_option): - if isinstance(ip_vld.get(vim_network_option), list): - for vim_net_id in ip_vld.get(vim_network_option): - for vim_account, vim_net in vim_net_id.items(): + db_nsir_update_RO = {} + db_nsir_update_RO["vld_id"] = netslice_vld["name"] + if self.ro_config["ng"]: + db_nsir_update_RO["netslice_scenario_id"] = vld_shared.get("instance_scenario_id") if vld_shared \ + else "nsir:{}:vld.{}".format(nsir_id, netslice_vld["name"]) + else: # if not self.ro_config["ng"]: + if netslice_vld.get("mgmt-network"): + mgmt_network = True + RO_ns_params = {} + RO_ns_params["name"] = netslice_vld["name"] + RO_ns_params["datacenter"] = vim_account_2_RO(db_nsir["instantiation_parameters"]["vimAccountId"]) + + # Creating scenario if vim-network-name / vim-network-id are present as instantiation parameter + # Use vim-network-id instantiation parameter + vim_network_option = None + if ip_vld: + if ip_vld.get("vim-network-id"): + vim_network_option = "vim-network-id" + elif ip_vld.get("vim-network-name"): + vim_network_option = "vim-network-name" + if ip_vld.get("ip-profile"): + populate_dict(RO_ns_params, ("networks", netslice_vld["name"], "ip-profile"), + ip_profile_2_RO(ip_vld["ip-profile"])) + + if vim_network_option: + if ip_vld.get(vim_network_option): + if isinstance(ip_vld.get(vim_network_option), list): + for vim_net_id in ip_vld.get(vim_network_option): + for vim_account, vim_net in vim_net_id.items(): + RO_vld_sites.append({ + "netmap-use": vim_net, + "datacenter": vim_account_2_RO(vim_account) + }) + elif isinstance(ip_vld.get(vim_network_option), dict): + for vim_account, vim_net in ip_vld.get(vim_network_option).items(): RO_vld_sites.append({ "netmap-use": vim_net, "datacenter": vim_account_2_RO(vim_account) }) - elif isinstance(ip_vld.get(vim_network_option), dict): - for vim_account, vim_net in ip_vld.get(vim_network_option).items(): - RO_vld_sites.append({ - "netmap-use": vim_net, - "datacenter": vim_account_2_RO(vim_account) - }) - else: - RO_vld_sites.append({ - "netmap-use": ip_vld[vim_network_option], - "datacenter": vim_account_2_RO(netslice_vld["vimAccountId"])}) - - # Use default netslice vim-network-name from template - else: - for nss_conn_point_ref in get_iterable(netslice_vld, "nss-connection-point-ref"): - if nss_conn_point_ref.get("vimAccountId"): - if nss_conn_point_ref["vimAccountId"] != netslice_vld["vimAccountId"]: + else: RO_vld_sites.append({ - "netmap-create": None, - "datacenter": vim_account_2_RO(nss_conn_point_ref["vimAccountId"])}) + "netmap-use": ip_vld[vim_network_option], + "datacenter": vim_account_2_RO(netslice_vld["vimAccountId"])}) - if vld_shared: - populate_dict(RO_ns_params, ("networks", netslice_vld["name"], "use-network"), vld_shared) + # Use default netslice vim-network-name from template + else: + for nss_conn_point_ref in get_iterable(netslice_vld, "nss-connection-point-ref"): + if nss_conn_point_ref.get("vimAccountId"): + if nss_conn_point_ref["vimAccountId"] != netslice_vld["vimAccountId"]: + RO_vld_sites.append({ + "netmap-create": None, + "datacenter": vim_account_2_RO(nss_conn_point_ref["vimAccountId"])}) - if RO_vld_sites: - populate_dict(RO_ns_params, ("networks", netslice_vld["name"], "sites"), RO_vld_sites) + if vld_shared: + populate_dict(RO_ns_params, ("networks", netslice_vld["name"], "use-network"), vld_shared) - RO_ns_params["scenario"] = {"nets": [{"name": netslice_vld["name"], - "external": mgmt_network, "type": "bridge"}]} + if RO_vld_sites: + populate_dict(RO_ns_params, ("networks", netslice_vld["name"], "sites"), RO_vld_sites) - # self.logger.debug(logging_text + step) - desc = await RO.create("ns", descriptor=RO_ns_params) - db_nsir_update_RO = {} - db_nsir_update_RO["netslice_scenario_id"] = desc["uuid"] - db_nsir_update_RO["vld_id"] = RO_ns_params["name"] + RO_ns_params["scenario"] = {"nets": [{"name": netslice_vld["name"], + "external": mgmt_network, "type": "bridge"}]} + + # self.logger.debug(logging_text + step) + desc = await RO.create("ns", descriptor=RO_ns_params) + db_nsir_update_RO["netslice_scenario_id"] = desc["uuid"] db_nsir_update["_admin.deployed.RO"].append(db_nsir_update_RO) def overwrite_nsd_params(self, db_nsir, nslcmop): - RO_list = [] + nonlocal nsi_vld_instantiationi_params + nonlocal db_nsir_update vld_op_list = [] vld = None nsr_id = nslcmop.get("nsInstanceId") # Overwrite instantiation parameters in netslice runtime - if db_nsir.get("_admin"): - if db_nsir["_admin"].get("deployed"): - db_admin_deployed_nsir = db_nsir["_admin"].get("deployed") - if db_admin_deployed_nsir.get("RO"): - RO_list = db_admin_deployed_nsir["RO"] - - for RO_item in RO_list: - for netslice_vld in get_iterable(db_nsir["_admin"], "netslice-vld"): - # if is equal vld of _admin with vld of netslice-vld then go for the CPs - if RO_item.get("vld_id") == netslice_vld.get("id"): - # Search the cp of netslice-vld that match with nst:netslice-subnet - for nss_cp_item in get_iterable(netslice_vld, "nss-connection-point-ref"): - # Search the netslice-subnet of nst that match - for nss in get_iterable(db_nsir["_admin"], "netslice-subnet"): - # Compare nss-ref equal nss from nst - if nss_cp_item["nss-ref"] == nss["nss-id"]: - db_nsds = self.db.get_one("nsds", {"_id": nss["nsdId"]}) - # Go for nsd, and search the CP that match with nst:CP to get vld-id-ref - for cp_nsd in db_nsds.get("connection-point", ()): - if cp_nsd["name"] == nss_cp_item["nsd-connection-point-ref"]: - if nslcmop.get("operationParams"): - if nslcmop["operationParams"].get("nsName") == nss["nsName"]: - vld_id = RO_item["vld_id"] - netslice_scenario_id = RO_item["netslice_scenario_id"] - nslcmop_vld = {} - nslcmop_vld["ns-net"] = {vld_id: netslice_scenario_id} - nslcmop_vld["name"] = cp_nsd["vld-id-ref"] - for vld in get_iterable(nslcmop["operationParams"], "vld"): - if vld["name"] == cp_nsd["vld-id-ref"]: - nslcmop_vld.update(vld) - vld_op_list.append(nslcmop_vld) + RO_list = db_nsir_admin["deployed"]["RO"] + + for ro_item_index, RO_item in enumerate(RO_list): + netslice_vld = next((n for n in get_iterable(db_nsir["_admin"], "netslice-vld") + if RO_item.get("vld_id") == n.get("id")), None) + if not netslice_vld: + continue + # if is equal vld of _admin with vld of netslice-vld then go for the CPs + # Search the cp of netslice-vld that match with nst:netslice-subnet + for nss_cp_item in get_iterable(netslice_vld, "nss-connection-point-ref"): + # Search the netslice-subnet of nst that match + nss = next((nss for nss in get_iterable(db_nsir["_admin"], "netslice-subnet") + if nss_cp_item["nss-ref"] == nss["nss-id"]), None) + # Compare nss-ref equal nss from nst + if not nss: + continue + db_nsds = self.db.get_one("nsds", {"_id": nss["nsdId"]}) + # Go for nsd, and search the CP that match with nst:CP to get vld-id-ref + for cp_nsd in db_nsds.get("connection-point", ()): + if cp_nsd["name"] == nss_cp_item["nsd-connection-point-ref"]: + if nslcmop.get("operationParams"): + if nslcmop["operationParams"].get("nsName") == nss["nsName"]: + vld_id = RO_item["vld_id"] + netslice_scenario_id = RO_item["netslice_scenario_id"] + nslcmop_vld = {} + nslcmop_vld["name"] = cp_nsd["vld-id-ref"] + for vld in get_iterable(nslcmop["operationParams"], "vld"): + if vld["name"] == cp_nsd["vld-id-ref"]: + nslcmop_vld.update(vld) + if self.ro_config["ng"]: + nslcmop_vld["common_id"] = netslice_scenario_id + nslcmop_vld.update(nsi_vld_instantiationi_params.get(RO_item["vld_id"], {})) + else: + nslcmop_vld["ns-net"] = {vld_id: netslice_scenario_id} + vld_op_list.append(nslcmop_vld) nslcmop["operationParams"]["vld"] = vld_op_list self.update_db_2("nslcmops", nslcmop["_id"], {"operationParams.vld": vld_op_list}) return nsr_id, nslcmop @@ -297,7 +310,6 @@ class NetsliceLcm(LcmBase): db_nsir_update["_admin.deployed.RO"] = db_nsir_admin["deployed"]["RO"] for vld_item in get_iterable(nsir_admin, "netslice-vld"): await netslice_scenario_create(self, vld_item, nsir_id, db_nsir, db_nsir_admin, db_nsir_update) - self.update_db_2("nsis", nsir_id, db_nsir_update) step = "Instantiating netslice subnets" db_nsir_update["detailed-status"] = step @@ -547,19 +559,20 @@ class NetsliceLcm(LcmBase): for nsir_deployed_RO in get_iterable(nsir_deployed, "RO"): RO_nsir_id = nsir_deployed_RO.get("netslice_scenario_id") try: - step = db_nsir_update["detailed-status"] = "Deleting netslice-vld at RO" - db_nsilcmop_update["detailed-status"] = "Deleting netslice-vld at RO" - self.logger.debug(logging_text + step) - desc = await RO.delete("ns", RO_nsir_id) - RO_delete_action = desc["action_id"] - nsir_deployed_RO["vld_delete_action_id"] = RO_delete_action - nsir_deployed_RO["vld_status"] = "DELETING" - db_nsir_update["_admin.deployed"] = nsir_deployed - self.update_db_2("nsis", nsir_id, db_nsir_update) - if RO_delete_action: - # wait until NS is deleted from VIM - step = "Waiting ns deleted from VIM. RO_id={}".format(RO_nsir_id) + if not self.ro_config["ng"]: + step = db_nsir_update["detailed-status"] = "Deleting netslice-vld at RO" + db_nsilcmop_update["detailed-status"] = "Deleting netslice-vld at RO" self.logger.debug(logging_text + step) + desc = await RO.delete("ns", RO_nsir_id) + RO_delete_action = desc["action_id"] + nsir_deployed_RO["vld_delete_action_id"] = RO_delete_action + nsir_deployed_RO["vld_status"] = "DELETING" + db_nsir_update["_admin.deployed"] = nsir_deployed + self.update_db_2("nsis", nsir_id, db_nsir_update) + if RO_delete_action: + # wait until NS is deleted from VIM + step = "Waiting ns deleted from VIM. RO_id={}".format(RO_nsir_id) + self.logger.debug(logging_text + step) except ROclient.ROClientException as e: if e.http_code == 404: # not found nsir_deployed_RO["vld_id"] = None