def delete(self, uuid): """ Delete a specific wim. used by: `katana wim rm [uuid]` """ wim = mongoUtils.get("wim", uuid) if wim: if wim["slices"]: return "Cannot delete wim {} - In use".format(uuid), 400 mongoUtils.delete("wim_obj", uuid) mongoUtils.delete("wim", uuid) try: monitoring_url = wim["monitoring-url"] except KeyError: pass else: try: with open("/targets/wim_targets.json", mode="r") as prom_file: prom = json.load(prom_file) prom.remove({"targets": [monitoring_url], "labels": {"wim_id": wim["id"]}}) with open("/targets/wim_targets.json", mode="w") as prom_file: json.dump(prom, prom_file) except ValueError: pass return "Deleted WIM {}".format(uuid), 200 else: # if uuid is not found, return error return "Error: No such wim: {}".format(uuid), 404
def delete(self, uuid): """ Delete a specific EMS. used by: `katana ems rm [uuid]` """ mongoUtils.delete("ems_obj", uuid) result = mongoUtils.delete("ems", uuid) if result: return "Deleted EMS {}".format(uuid), 200 else: # if uuid is not found, return error return "Error: No such EMS: {}".format(uuid), 404
def delete(self, uuid): """ Delete a specific network function. used by: `katana function rm [uuid]` """ result = mongoUtils.get("func", uuid) if result: if len(result["tenants"]) > 0: return f"Error: Function is used by slices {result['tenants']}" mongoUtils.delete("func", uuid) return "Deleted Network Function {}".format(uuid), 200 else: # if uuid is not found, return error return "Error: No such Network Function: {}".format(uuid), 404
def delete(self, uuid): """ Delete a specific wim. used by: `katana wim rm [uuid]` """ wim = mongoUtils.get("wim", uuid) if wim: if wim["slices"]: return "Cannot delete wim {} - In use".format(uuid), 400 mongoUtils.delete("wim_obj", uuid) mongoUtils.delete("wim", uuid) return "Deleted WIM {}".format(uuid), 200 else: # if uuid is not found, return error return "Error: No such wim: {}".format(uuid), 404
def delete(self, uuid): """ Delete a specific vim. used by: `katana vim rm [uuid]` """ vim = mongoUtils.get("vim", uuid) if vim: if vim["tenants"]: return "Cannot delete vim {} - In use".format(uuid), 400 mongoUtils.delete("vim_obj", uuid) mongoUtils.delete("vim", uuid) return "Deleted VIM {}".format(uuid), 200 else: # if uuid is not found, return error return "Error: No such vim: {}".format(uuid), 404
def delete(self, uuid): """ Delete a specific nfvo. used by: `katana nfvo rm [uuid]` """ del_nfvo = mongoUtils.get("nfvo", uuid) if del_nfvo: if del_nfvo["tenants"]: return "Cannot delete nfvo {} - In use".format(uuid), 400 mongoUtils.delete("nfvo_obj", uuid) mongoUtils.delete_all("nsd", {"nfvo_id": del_nfvo["id"]}) mongoUtils.delete_all("vnfd", {"nfvoid": del_nfvo["id"]}) mongoUtils.delete("nfvo", uuid) return "Deleted NFVO {}".format(uuid), 200 else: # if uuid is not found, return error return "Error: No such nfvo: {}".format(uuid), 404
def delete(self, uuid): """ Delete a specific Slice Descriptor. used by: `katana slice_des rm [uuid]` """ result = mongoUtils.delete("base_slice_des_ref", uuid) if result: return "Deleted Slice Descriptor {}".format(uuid), 200 else: # if uuid is not found, return error return "Error: No such Slice Descriptor: {}".format(uuid), 404
def delete(self, uuid): """ Delete a specific policy management system. used by: `katana policy rm [uuid]` """ del_policy = mongoUtils.delete("policy", uuid) if del_policy: return "Deleted policy management system {}".format(uuid), 200 else: # if uuid is not found, return error return "Error: No such policy management system: {}".format(uuid), 404
def delete(self, uuid): """ Delete a specific vim. used by: `katana vim rm [uuid]` """ vim = mongoUtils.get("vim", uuid) if vim: if vim["tenants"]: return "Cannot delete vim {} - In use".format(uuid), 400 mongoUtils.delete("vim_obj", uuid) mongoUtils.delete("vim", uuid) # Update the location removing the VIM location = mongoUtils.find("location", {"id": vim["location"].lower()}) if location: location["vims"].remove(vim["id"]) mongoUtils.update("location", location["_id"], location) return "Deleted VIM {}".format(uuid), 200 else: # if uuid is not found, return error return "Error: No such vim: {}".format(uuid), 404
def delete(self, uuid): """ Delete a registered platform location used by: `katana location rm [uuid] """ del_location = mongoUtils.get("location", uuid) if del_location["id"] == "core": return "You cannot delete core location", 400 if del_location: if del_location["vims"] or del_location["functions"]: return ( f"Location {uuid} is in use by another component, cannot update it", 400, ) del_location = mongoUtils.delete("location", uuid) return f"Deleted location {uuid}", 200 else: return f"Error: No such location {uuid}", 404
def delete_slice(slice_id, force=False): """ Deletes the given network slice """ # Update the slice status in mongo db slice_json = mongoUtils.get("slice", slice_id) slice_json["status"] = "Terminating" mongoUtils.update("slice", slice_json["_id"], slice_json) logger.info(f"{slice_json['_id']} Status: Terminating") # Check if slice monitoring has been enabled monitoring = os.getenv("KATANA_MONITORING", None) slice_monitoring = slice_json.get("slice_monitoring", None) mon_producer = None if monitoring: # Create the Kafka producer mon_producer = create_producer() mon_producer.send( "nfv_mon", value={ "action": "katana_mon", "slice_info": { "slice_id": slice_id, "status": "terminating" }, }, ) # *** Step-1: Radio Slice Configuration *** if slice_json["conf_comp"]["ems"]: ems_messages = slice_json.get("ems_data", None) if ems_messages: for ems_id, ems_message in ems_messages.items(): # Find the EMS target_ems = mongoUtils.find("ems", {"id": ems_id}) if not target_ems or ems_id not in slice_json["conf_comp"][ "ems"]: # Error handling: There is no such EMS logger.error( "EMS {} not found - No configuration".format(ems_id)) continue target_ems_obj = pickle.loads( mongoUtils.find("ems_obj", {"id": ems_id})["obj"]) target_ems_obj.del_slice(ems_message) else: logger.info("There was not EMS configuration") # *** Step-2: WAN Slice *** wim_data = slice_json.get("wim_data", None) if wim_data: # Select WIM - Assume that there is only one registered wim_list = list(mongoUtils.index("wim")) if wim_list: target_wim = wim_list[0] target_wim_id = target_wim["id"] target_wim_obj = pickle.loads( mongoUtils.find("wim_obj", {"id": target_wim_id})["obj"]) target_wim_obj.del_slice(slice_id) try: del target_wim["slices"][slice_json["_id"]] except KeyError: logger.warning(f"Slice {slice_id} not in WIM {target_wim_id}") else: mongoUtils.update("wim", target_wim["_id"], target_wim) else: err = "Cannot find WIM - WAN Slice will not be deleted" logger.warning(err) slice_json["status"] = "Error" if monitoring: mon_producer.send( "nfv_mon", value={ "action": "katana_mon", "slice_info": { "slice_id": slice_id, "status": "error" }, }, ) slice_json["error"] = slice_json.get("error", "") + err mongoUtils.update("slice", slice_json["_id"], slice_json) else: logger.info("There was no WIM configuration") # *** Step-3: Cloud *** vim_error_list = [] try: total_ns_list = slice_json["total_ns_list"] ns_inst_info = slice_json["ns_inst_info"] for ns in total_ns_list: # Check if the NS is shared. If it is, check if there is another running slice on this # sharing list if ns["shared_function"]: # Find the shared list shared_list = mongoUtils.get("sharing_lists", ns["shared_slice_key"]) # If there is another running slice, don't terminate the NS if len(shared_list["nest_list"]) > 1: continue if ns["nsd-id"] not in slice_json["conf_comp"]["nf"]: logger.error( f"{ns['nsd-id']} was not instantiated successfully") continue # Get the NFVO nfvo_id = ns["nfvo-id"] target_nfvo = mongoUtils.find("nfvo", {"id": ns["nfvo-id"]}) if not target_nfvo: logger.warning( "NFVO with id {} was not found - NSs won't terminate". format(nfvo_id)) vim_error_list += ns["vims"] continue target_nfvo_obj = pickle.loads( mongoUtils.find("nfvo_obj", {"id": ns["nfvo-id"]})["obj"]) # Stop the NS nfvo_inst_ns = ns_inst_info[ns["ns-id"]][ ns["placement_loc"]["location"]]["nfvo_inst_ns"] target_nfvo_obj.deleteNs(nfvo_inst_ns) while True: if target_nfvo_obj.checkNsLife(nfvo_inst_ns): break time.sleep(5) except KeyError as e: err = f"Error, not all NSs started or terminated correctly {e}" logger.warning(err) slice_json["status"] = "Error" if monitoring: mon_producer.send( "nfv_mon", value={ "action": "katana_mon", "slice_info": { "slice_id": slice_id, "status": "error" }, }, ) slice_json["error"] = slice_json.get("error", "") + err mongoUtils.update("slice", slice_json["_id"], slice_json) vim_dict = slice_json.get("vim_list", {}) for vim, vim_info in vim_dict.items(): # Check if the VIM is shared with other slices. If yes, skip the deletion tenant_name = slice_id if vim_info["shared"]: shared_list = mongoUtils.get("sharing_lists", vim_info["shared_slice_list_key"]) tenant_name = vim_info["shared_slice_list_key"] vim_id = vim[:-2] # If there is another running slice, don't delete the VIM account if len(shared_list["nest_list"]) > 1: continue else: vim_id = vim try: # Delete the new tenants from the NFVO for nfvo, vim_account in vim_info["nfvo_vim_account"].items(): # Get the NFVO target_nfvo = mongoUtils.find("nfvo", {"id": nfvo}) target_nfvo_obj = pickle.loads( mongoUtils.find("nfvo_obj", {"id": nfvo})["obj"]) # Delete the VIM and update nfvo db target_nfvo_obj.deleteVim(vim_account) target_nfvo["tenants"][tenant_name].remove(vim_account) if len(target_nfvo["tenants"][tenant_name]) == 0: try: del target_nfvo["tenants"][tenant_name] except KeyError: logger.warning( f"Slice {tenant_name} not in NFO {nfvo}") else: mongoUtils.update("nfvo", target_nfvo["_id"], target_nfvo) # Delete the tenants from every vim if vim not in vim_error_list: # Get the VIM target_vim = mongoUtils.find("vim", {"id": vim_id}) if not target_vim: logger.warning( "VIM id {} was not found - Tenant won't be deleted". format(vim)) continue target_vim_obj = pickle.loads( mongoUtils.find("vim_obj", {"id": vim_id})["obj"]) if vim_info["shared"]: tenant_name = vim_info["shared_slice_list_key"] else: tenant_name = slice_json["_id"] target_vim_obj.delete_proj_user( target_vim["tenants"][tenant_name]) try: del target_vim["tenants"][tenant_name] except KeyError: logger.warning(f"Slice {slice_id} not in VIM {vim}") else: mongoUtils.update("vim", target_vim["_id"], target_vim) except KeyError as e: err = f"Error, not all tenants created or removed correctly {e}" logger.warning(err) slice_json["status"] = "Error" if monitoring: mon_producer.send( "nfv_mon", value={ "action": "katana_mon", "slice_info": { "slice_id": slice_id, "status": "error" }, }, ) slice_json["error"] = slice_json.get("error", "") + err mongoUtils.update("slice", slice_json["_id"], slice_json) if "error" not in slice_json: mongoUtils.delete("slice", slice_json["_id"]) if monitoring: mon_producer.send( "nfv_mon", value={ "action": "katana_mon", "slice_info": { "slice_id": slice_id, "status": "deleted" }, }, ) elif "error" in slice_json and force: mongoUtils.delete("slice", slice_json["_id"]) if monitoring: mon_producer.send( "nfv_mon", value={ "action": "katana_mon", "slice_info": { "slice_id": slice_id, "status": "deleted" }, }, ) # Remove Slice from the tenants list on functions for func_id in slice_json["functions"]: ifunc = mongoUtils.get("func", func_id) try: ifunc["tenants"].remove(slice_json["_id"]) except (KeyError, ValueError): logger.warning(f"Slice {slice_id} not in function {func_id}") else: mongoUtils.update("func", func_id, ifunc) # Remove Slice dashboard if monitoring and slice_monitoring: # Use the Grafana API in order to delete the new dashboard for the new slice grafana_url = f"http://katana-grafana:3000/api/dashboards/uid/{slice_id}" headers = { "accept": "application/json", "content-type": "application/json" } grafana_user = os.getenv("GF_SECURITY_ADMIN_USER", "admin") grafana_passwd = os.getenv("GF_SECURITY_ADMIN_PASSWORD", "admin") r = requests.delete( url=grafana_url, headers=headers, auth=(grafana_user, grafana_passwd), ) logger.info(f"Deleted Grafana dashboard for slice {slice_id}") # Stop the threads monitoring NS status of the slice ns_inst_info = slice_json["ns_inst_info"] mon_producer.send(topic="nfv_mon", value={ "action": "delete", "ns_list": ns_inst_info }) # Check if the NSI has shared NSSIs and remove them try: for func_key, shared_list_key in slice_json["shared"]["core"].items(): # Remove the slice from the shared list try: shared_list = mongoUtils.get("sharing_lists", shared_list_key) func = mongoUtils.get("func", func_key) if len(shared_list["nest_list"]) > 1: # Remove the Slice from the list shared_list["nest_list"].remove(slice_id) mongoUtils.update("sharing_lists", shared_list_key, shared_list) func["shared"]["sharing_list"][shared_list_key].remove( slice_id) else: # Remove the the shared list mongoUtils.delete("sharing_lists", shared_list_key) del func["shared"]["sharing_list"][shared_list_key] mongoUtils.update("func", func_key, func) except ValueError as e: pass except KeyError as e: pass try: for func_key, shared_list_key in slice_json["shared"]["radio"].items(): # Remove the slice from the shared list try: shared_list = mongoUtils.get("sharing_lists", shared_list_key) func = mongoUtils.get("func", func_key) if len(shared_list["nest_list"]) > 1: # Remove the Slice from the list shared_list["nest_list"].remove(slice_id) mongoUtils.update("sharing_lists", shared_list_key, shared_list) func["shared"]["sharing_list"][shared_list_key].remove( slice_id) else: # Remove the the shared list mongoUtils.delete("sharing_lists", shared_list_key) del func["shared"]["sharing_list"][shared_list_key] mongoUtils.update("func", func_key, func) except ValueError as e: pass except KeyError as e: pass
def delete_slice(slice_id, force=False): """ Deletes the given network slice """ # Update the slice status in mongo db slice_json = mongoUtils.get("slice", slice_id) slice_json["status"] = "Terminating" mongoUtils.update("slice", slice_json["_id"], slice_json) logger.info(f"{slice_json['_id']} Status: Terminating") # *** Step-1: Radio Slice Configuration *** if slice_json["conf_comp"]["ems"]: ems_messages = slice_json.get("ems_data", None) if ems_messages: for ems_id, ems_message in ems_messages.items(): # Find the EMS target_ems = mongoUtils.find("ems", {"id": ems_id}) if not target_ems or ems_id not in slice_json["conf_comp"]["ems"]: # Error handling: There is no such EMS logger.error("EMS {} not found - No configuration".format(ems_id)) continue target_ems_obj = pickle.loads(mongoUtils.find("ems_obj", {"id": ems_id})["obj"]) target_ems_obj.del_slice(ems_message) else: logger.info("There was not EMS configuration") # *** Step-2: WAN Slice *** wim_data = slice_json.get("wim_data", None) if wim_data: # Select WIM - Assume that there is only one registered wim_list = list(mongoUtils.index("wim")) if wim_list: target_wim = wim_list[0] target_wim_id = target_wim["id"] target_wim_obj = pickle.loads(mongoUtils.find("wim_obj", {"id": target_wim_id})["obj"]) target_wim_obj.del_slice(slice_id) try: del target_wim["slices"][slice_json["_id"]] except KeyError: logger.warning(f"Slice {slice_id} not in WIM {target_wim_id}") else: mongoUtils.update("wim", target_wim["_id"], target_wim) else: err = "Cannot find WIM - WAN Slice will not be deleted" logger.warning(err) slice_json["status"] = "Error" slice_json["error"] = slice_json.get("error", "") + err mongoUtils.update("slice", slice_json["_id"], slice_json) else: logger.info("There was no WIM configuration") # *** Step-3: Cloud *** vim_error_list = [] try: total_ns_list = slice_json["total_ns_list"] ns_inst_info = slice_json["ns_inst_info"] for ns in total_ns_list: if ns["nsd-id"] not in slice_json["conf_comp"]["nf"]: logger.error(f"{ns['nsd-id']} was not instantiated successfully") continue # Get the NFVO nfvo_id = ns["nfvo-id"] target_nfvo = mongoUtils.find("nfvo", {"id": ns["nfvo-id"]}) if not target_nfvo: logger.warning( "NFVO with id {} was not found - NSs won't terminate".format(nfvo_id) ) vim_error_list += ns["vims"] continue target_nfvo_obj = pickle.loads( mongoUtils.find("nfvo_obj", {"id": ns["nfvo-id"]})["obj"] ) # Stop the NS nfvo_inst_ns = ns_inst_info[ns["ns-id"]][ns["placement_loc"]["location"]][ "nfvo_inst_ns" ] target_nfvo_obj.deleteNs(nfvo_inst_ns) while True: if target_nfvo_obj.checkNsLife(nfvo_inst_ns): break time.sleep(5) except KeyError as e: err = f"Error, not all NSs started or terminated correctly {e}" logger.warning(err) slice_json["status"] = "Error" slice_json["error"] = slice_json.get("error", "") + err mongoUtils.update("slice", slice_json["_id"], slice_json) vim_dict = slice_json["vim_list"] for vim, vim_info in vim_dict.items(): try: # Delete the new tenants from the NFVO for nfvo, vim_account in vim_info["nfvo_vim_account"].items(): # Get the NFVO target_nfvo = mongoUtils.find("nfvo", {"id": nfvo}) target_nfvo_obj = pickle.loads(mongoUtils.find("nfvo_obj", {"id": nfvo})["obj"]) # Delete the VIM and update nfvo db target_nfvo_obj.deleteVim(vim_account) target_nfvo["tenants"][slice_json["_id"]].remove(vim_account) if len(target_nfvo["tenants"][slice_json["_id"]]) == 0: try: del target_nfvo["tenants"][slice_json["_id"]] except KeyError: logger.warning(f"Slice {slice_id} not in NFO {nfvo}") else: mongoUtils.update("nfvo", target_nfvo["_id"], target_nfvo) # Delete the tenants from every vim if vim not in vim_error_list: # Get the VIM target_vim = mongoUtils.find("vim", {"id": vim}) if not target_vim: logger.warning("VIM id {} was not found - Tenant won't be deleted".format(vim)) continue target_vim_obj = pickle.loads(mongoUtils.find("vim_obj", {"id": vim})["obj"]) target_vim_obj.delete_proj_user(target_vim["tenants"][slice_json["_id"]]) try: del target_vim["tenants"][slice_json["_id"]] except KeyError: logger.warning(f"Slice {slice_id} not in VIM {vim}") else: mongoUtils.update("vim", target_vim["_id"], target_vim) except KeyError as e: err = f"Error, not all tenants created or removed correctly {e}" logger.warning(err) slice_json["status"] = "Error" slice_json["error"] = slice_json.get("error", "") + err mongoUtils.update("slice", slice_json["_id"], slice_json) if "error" not in slice_json: mongoUtils.delete("slice", slice_json["_id"]) elif "error" in slice_json and force: mongoUtils.delete("slice", slice_json["_id"]) # Remove Slice from the tenants list on functions for func_id in slice_json["functions"]: ifunc = mongoUtils.get("func", func_id) try: ifunc["tenants"].remove(slice_json["_id"]) except (KeyError, ValueError): logger.warning(f"Slice {slice_id} not in function {func_id}") else: mongoUtils.update("func", func_id, ifunc)