def find_by_priority(user_data, ws_id, project_id, vendor, name, version, is_vnf): """ Tries to find vnf / network services by descending priority 1. project 2. private catalogue 3. public catalogues. :param user_data: Information about the current user :param ws_id: The Workspace ID :param project_id: The project ID :param vendor: The descriptors vendor :param name: The descriptors name :param version: The descriptors versions :param is_vnf: if the descriptor is a VNF :return: The descriptor if found """ # 1. Try to find in project project = get_project(project_id) if project is None: raise NotFound("No project with id {} found.".format(project_id)) function = get_function(project.functions, vendor, name, version) if is_vnf else get_function( project.services, vendor, name, version) if function is not None: return function.as_dict() # 2. Try to find in private catalogue # private catalogue funcs/nss are cached in db function = query_private_nsfs(ws_id, vendor, name, version, is_vnf) if function is not None: return function.as_dict() # 3. Try to find in public catalogue catalogues = get_catalogues(ws_id) for catalogue in catalogues: try: function_list = get_all_in_catalogue(user_data, ws_id, catalogue['id'], is_vnf) except: continue for func in function_list: if func['vendor'] == vendor and func['name'] == name and func[ 'version'] == version: function = func return function.as_dict() # If none found, raise exception raise NotFound("VNF" if is_vnf else "NS" + " {}:{}:{} not found".format(vendor, name, version))
def find_by_priority(user_data, ws_id, project_id, vendor, name, version, is_vnf): """ Tries to find vnf / network services by descending priority 1. project 2. private catalogue 3. public catalogues. :param user_data: Information about the current user :param ws_id: The Workspace ID :param project_id: The project ID :param vendor: The descriptors vendor :param name: The descriptors name :param version: The descriptors versions :param is_vnf: if the descriptor is a VNF :return: The descriptor if found """ # 1. Try to find in project project = get_project(project_id) if project is None: raise NotFound("No project with id {} found.".format(project_id)) function = get_function(project.functions, vendor, name, version) if is_vnf else get_function(project.services, vendor, name, version) if function is not None: return function.as_dict() # 2. Try to find in private catalogue # private catalogue funcs/nss are cached in db function = query_private_nsfs(ws_id, vendor, name, version, is_vnf) if function is not None: return function.as_dict() # 3. Try to find in public catalogue catalogues = get_catalogues(ws_id) for catalogue in catalogues: try: function_list = get_all_in_catalogue(user_data, ws_id, catalogue['id'], is_vnf) except: continue for func in function_list: if func['vendor'] == vendor and func['name'] == name and func['version'] == version: function = func return function.as_dict() # If none found, raise exception raise NotFound("VNF" if is_vnf else "NS" + " {}:{}:{} not found".format(vendor, name, version))
def find_by_priority(user_data, ws_id, project_id, vendor, name, version, is_vnf): """ Tries to find vnf / network services by descending priority project / private catalogue / public catalogue. :param user_data: :param ws_id: :param project_id: :param vendor: :param name: :param version: :param is_vnf: :return: """ # 1. Try to find in project project = get_project(project_id) if project is None: raise NotFound("No project with id {} found.".format(project_id)) function = ( get_function(project.functions, vendor, name, version) if is_vnf else get_function(project.services, vendor, name, version) ) if function is not None: return function.as_dict() # 2. Try to find in private catalogue # private catalogue funcs/nss are cached in db function = query_private_nsfs(ws_id, vendor, name, version, is_vnf) if function is not None: return function.as_dict() # 3. Try to find in public catalogue catalogues = get_catalogues(ws_id) for catalogue in catalogues: try: function_list = get_all_in_catalogue(user_data, ws_id, catalogue["id"], is_vnf) except: continue for func in function_list: if func["vendor"] == vendor and func["name"] == name and func["version"] == version: function = func return function.as_dict() # If none found, raise exception raise NotFound("VNF" if is_vnf else "NS" + " {}:{}:{} not found".format(vendor, name, version))
def get(self, ws_id): """Lists catalogues Lists catalogues in a specific workspace""" return prepare_response(cataloguesimpl.get_catalogues(ws_id))