def get(self): """ Returns a list with all the onboarded nsds, used by: `katana ns ls` """ # Bootstrap the NFVO nfvo_obj_list = list(mongoUtils.find_all("nfvo_obj")) for infvo in nfvo_obj_list: nfvo = pickle.loads(infvo["obj"]) nfvo.bootstrapNfvo() # Return the list ns_list = mongoUtils.find_all("nsd") return dumps(ns_list), 200
def vim_update(): """ Gets the resources of the stored VIMs """ for vim in mongoUtils.find_all("vim"): if vim["type"] == "openstack": vim_obj = pickle.loads(mongoUtils.get("vim_obj", vim["_id"])["obj"]) resources = vim_obj.get_resources() vim["resources"] = resources mongoUtils.update("vim", vim["_id"], vim) else: resources = "N/A"
def get(self): """ Returns a list with all the onboarded nsds, used by: `katana ns ls` """ # Bootstrap the NFVO nfvo_obj_list = list(mongoUtils.find_all("nfvo_obj")) for infvo in nfvo_obj_list: nfvo = pickle.loads(infvo["obj"]) nfvo.bootstrapNfvo() nsd_id = request.args.get("nsd-id", None) nfvo_id = request.args.get("nfvo-id", None) search_params = {} if nsd_id: search_params["nsd-id"] = nsd_id if nfvo_id: search_params["nfvo_id"] = nfvo_id # Return the list ns_list = mongoUtils.find_all("nsd", search_params) return dumps(ns_list), 200
def get_vims(filter_data=None): """ Return the list of available VIMs """ vims = [] for vim in mongoUtils.find_all("vim", data=filter_data): vims.append({ "name": vim["name"], "id": vim["id"], "location": vim["location"], "type": vim["type"], "tenants": vim["tenants"], "resources": vim["resources"], }) return vims
def index(self): """ Returns the available resources on platform, used by: `katana resource ls` """ # Get VIMs vims = get_vims() # Get Functions functions = get_func() # Get locations locations = mongoUtils.find_all("location") resources = { "VIMs": vims, "Functions": functions, "Locations": locations } return dumps(resources), 200
def get_func(filter_data={}): """ Return the list of available Network Functions """ filter_data["type"] = 1 data = mongoUtils.find_all("func", data=filter_data) functions = [] for iserv in data: functions.append( dict( DB_ID=iserv["_id"], gen=(lambda x: "4G" if x == 4 else "5G")(iserv["gen"]), functionality=(lambda x: "Core" if x == 0 else "Radio")(iserv["func"]), pnf_list=iserv["pnf_list"], function_id=iserv["id"], location=iserv["location"], tenants=iserv["tenants"], shared=iserv["shared"], created_at=iserv["created_at"], ) ) return functions
def ns_details( ns_list, edge_loc, vim_dict, total_ns_list, shared_function=0, shared_slice_list_key=None, ): """ Get details for the NS that are part of the slice A) Find the nsd details for each NS B) Replace placement value with location C) Get the VIM for each NS """ pop_list = [] for ns in ns_list: try: if ns["placement_loc"] and not ns["placement"]: # Placement to Core already done - go to next NS continue else: # Placement to Edge - Is already done - Need to make another ns new_ns = copy.deepcopy(ns) except KeyError: # No placement at all new_ns = ns # 00) Check if the function is shared and if the ns is already instantiated new_ns["shared_function"] = shared_function new_ns["shared_slice_key"] = shared_slice_list_key # Search the nsd collection in Mongo for the nsd nsd = mongoUtils.find("nsd", {"nsd-id": new_ns["nsd-id"]}) if not nsd: # Bootstrap the NFVOs to check for NSDs that are not in mongo # If again is not found, check if NS is optional. # If it is just remove it, else error nfvo_obj_list = list(mongoUtils.find_all("nfvo_obj")) for infvo in nfvo_obj_list: nfvo = pickle.loads(infvo["obj"]) nfvo.bootstrapNfvo() nsd = mongoUtils.find("nsd", {"nsd-id": new_ns["nsd-id"]}) if not nsd and ns.get("optional", False): # The NS is optional - continue to next pop_list.append(ns) continue else: # Error handling: The ns is not optional and the nsd is not # on the NFVO - stop and return error_message = f"NSD {new_ns['nsd-id']} not found on any NFVO registered to SM" logger.error(error_message) return error_message, [] new_ns["nfvo-id"] = nsd["nfvo_id"] new_ns["nsd-info"] = nsd # B) ****** Replace placement value with location info ****** if type(new_ns["placement"]) is str: new_ns["placement_loc"] = {"location": new_ns["placement"]} else: new_ns["placement_loc"] = (lambda x: { "location": "Core" } if not x else { "location": edge_loc })(new_ns["placement"]) # C) ****** Get the VIM info ****** new_ns["vims"] = [] loc = new_ns["placement_loc"]["location"] get_vim = list(mongoUtils.find_all("vim", {"location": loc})) if not get_vim: if not new_ns.get("optional", False): # Error handling: There is no VIM at that location error_message = f"VIM not found in location {loc}" logger.error(error_message) return error_message, [] else: # The NS is optional - continue to next pop_list.append(ns) continue # TODO: Check the available resources and select vim # Temporary use the first element selected_vim = get_vim[0]["id"] if shared_function: selected_vim_id = selected_vim + "_s" else: selected_vim_id = selected_vim new_ns["vims"].append(selected_vim_id) try: vim_dict[selected_vim_id]["ns_list"].append(new_ns["ns-name"]) if new_ns["nfvo-id"] not in vim_dict[selected_vim_id]["nfvo_list"]: vim_dict[selected_vim_id]["nfvo_list"].append( new_ns["nfvo-id"]) except KeyError: vim_dict[selected_vim_id] = { "ns_list": [new_ns["ns-name"]], "nfvo_list": [new_ns["nfvo-id"]], "shared": shared_function, "shared_slice_list_key": shared_slice_list_key, } resources = vim_dict[selected_vim_id].get("resources", { "memory-mb": 0, "vcpu-count": 0, "storage-gb": 0, "instances": 0 }) for key in resources: resources[key] += nsd["flavor"][key] vim_dict[selected_vim_id]["resources"] = resources new_ns["placement_loc"]["vim"] = selected_vim_id # 0) Create an uuid for the ns new_ns["ns-id"] = str(uuid.uuid4()) total_ns_list.append(new_ns) del new_ns # Remove the ns that are optional and nsd was not found ns_list = [ns for ns in ns_list if ns not in pop_list] return 0, pop_list
def ns_details(ns_list, edge_loc, vim_dict, total_ns_list): """ Get details for the NS that are part of the slice A) Find the nsd details for each NS B) Replace placement value with location C) Get the VIM for each NS """ pop_list = [] for ns in ns_list: try: if ns["placement_loc"] and not ns["placement"]: # Placement to Core already done - go to next NS continue else: # Placement to Edge - Is already done - Need to make another ns new_ns = copy.deepcopy(ns) except KeyError: # No placement at all new_ns = ns # A) ****** Get the NSD ****** # Search the nsd collection in Mongo for the nsd nsd = mongoUtils.find("nsd", { "nsd-id": new_ns["nsd-id"], "nfvo_id": new_ns["nfvo-id"] }) if not nsd: # Bootstrap the NFVO to check for NSDs that are not in mongo # If again is not found, check if NS is optional. # If it is just remove it, else error nfvo_obj_json = mongoUtils.find("nfvo_obj", {"id": new_ns["nfvo-id"]}) if not nfvo_obj_json: # Error handling: There is no OSM for that ns - # Stop and return logger.error("There is no NFVO with id {}".format( new_ns["nfvo-id"])) return 1, [] nfvo = pickle.loads(nfvo_obj_json["obj"]) nfvo.bootstrapNfvo() nsd = mongoUtils.find("nsd", { "nsd-id": new_ns["nsd-id"], "nfvo_id": new_ns["nfvo-id"] }) if not nsd and ns.get("optional", False): pop_list.append(ns) continue else: # Error handling: The ns is not optional and the nsd is not # on the NFVO - stop and return logger.error( f"NSD {new_ns['nsd-id']} not found on OSM {new_ns['nfvo-id']}" ) return 1, [] new_ns["nsd-info"] = nsd # B) ****** Replace placement value with location info ****** new_ns["placement_loc"] = (lambda x: { "location": "Core" } if not x else { "location": edge_loc })(new_ns["placement"]) # C) ****** Get the VIM info ****** new_ns["vims"] = [] loc = new_ns["placement_loc"]["location"] get_vim = list(mongoUtils.find_all("vim", {"location": loc})) if not get_vim: # Error handling: There is no VIM at that location logger.error(f"VIM not found in location {loc}") return 1, [] # TODO: Check the available resources and select vim # Temporary use the first element selected_vim = get_vim[0]["id"] new_ns["vims"].append(selected_vim) try: vim_dict[selected_vim]["ns_list"].append(new_ns["ns-name"]) if new_ns["nfvo-id"] not in vim_dict[selected_vim]["nfvo_list"]: vim_dict[selected_vim]["nfvo_list"].append(new_ns["nfvo-id"]) except KeyError: vim_dict[selected_vim] = { "ns_list": [new_ns["ns-name"]], "nfvo_list": [new_ns["nfvo-id"]], } resources = vim_dict[selected_vim].get("resources", { "memory-mb": 0, "vcpu-count": 0, "storage-gb": 0, "instances": 0 }) for key in resources: resources[key] += nsd["flavor"][key] vim_dict[selected_vim]["resources"] = resources new_ns["placement_loc"]["vim"] = selected_vim # 0) Create an uuid for the ns new_ns["ns-id"] = str(uuid.uuid4()) total_ns_list.append(new_ns) del new_ns # Remove the ns that are optional and nsd was not found ns_list = [ns for ns in ns_list if ns not in pop_list] return 0, pop_list