def get_ns_name(ns_uuid): # Get the NS name based on the NS uuid token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('password')) ns = NetworkService(token) response = ns.get(ns_uuid=ns_uuid) data = response.json() return data['name']
def get_nsd_ref_name(token, ns_uuid): """ Get the nsd reference name by ns identifier Args: token (str): the auth token in OSM ns_uuid (str): The identifier of the NS Returns: str: the nsd reference name """ ns = NetworkService(token) request = ns.get(ns_uuid=ns_uuid) response = request.json() return response.get('nsd-name-ref', None)
def discover_vnf_uuid_by_vnfd_name_index(vnfd_name_index): """ Discover the VDU uuid by given the vnfd name and index Args: vnfd_name_index (str): The VNFd name & index Returns: str: the vnf uuid """ token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) # Get the UUIDs of the running NSs ns = Ns(token) request = ns.get_list() nss_response = request.json() ns_uuids = [ns.get('id') for ns in nss_response] # TODO: what if more than one NSs are running # if len(ns_uuids): # raise Exception("More that one NSs are running...") vnf_uuid = None for ns_uuid in ns_uuids: vnf = Vnf(token) request = vnf.get_list_by_ns(ns_uuid=ns_uuid) vnfs = request.json() for i in vnfs: cur_vnfd_name_index = "{}.{}".format( i.get("vnfd-ref"), i.get("member-vnf-index-ref"), ) if vnfd_name_index == cur_vnfd_name_index: return i.get("id") return vnf_uuid
def discover_vdu_uuid_by_vnf_index(vnf_index): """ Discover the VDU uuid by given the vnf index Args: vnf_index (str): The VNF index Returns: str: the vdu uuid """ token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) # Get the UUIDs of the running NSs ns = Ns(token) request = ns.get_list() nss_response = request.json() ns_uuids = [ns.get('id') for ns in nss_response] # TODO: what if more than one NSs are running # if len(ns_uuids): # raise Exception("More that one NSs are running...") vdu_uuid = None for ns_uuid in ns_uuids: vnf = Vnf(token) request = vnf.get_list_by_ns(ns_uuid=ns_uuid) vnfs = request.json() for i in vnfs: if vnf_index in i.get("member-vnf-index-ref"): for vdur in i.get("vdur"): vdu_uuid = vdur.get("vim-id") return vdu_uuid return vdu_uuid
def get_vnf_details(vnf_uuid, record, source="vtranscoder3d"): """ Append MANO (OSM) details (ns, vnf and vdu) by given VNF uuid Args: vnf_uuid (str): The uuid of the VNF record (dict): The original metric as it is sent from monitoring metrics generator source (str): The NFVI or application ref. It could be "vtranscoder3d" etc.. Returns: dict: osm info for the given vdu """ mano = {} token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('password')) vnfr = Vnf(token) vnf_response = vnfr.get(vnf_uuid=vnf_uuid) vnf_record = vnf_response.json() # Get NS details ns_id = vnf_record.get("nsr-id-ref", None) ns = Ns(token) ns_response = ns.get(ns_uuid=ns_id) nsr = ns_response.json() # VNFd info vnfd = vnf_record.get("vnfd-id", None) # VDUs info vdu_records = vnf_record.get('vdur', []) # Number of VDU per VNFd vdus_count = len(vdu_records) if vdus_count > 1: logger.critical("{} VDUs were found for the VNF with uuid: {}".format( vdus_count, vnf_uuid)) vdu_record = vdu_records[0] try: # Find the VDU info vdu_metadata = record.get("resource_metadata", {}) # If the data coming from VNFs, discover in different way the VDU info if source in [ "telegraf", "vtranscoder3d", "vce", "kubernetes", "opennebula", "vtranscoder3d_spectators" ]: vdu_metadata["instance_id"] = vdu_record.get('vim-id', None) vdu_metadata["flavor"] = {} if vdus_count: # TODO: what about the IPs if exists VNF with multiple VDUs? vdu_metadata["state"] = vdu_record.get('status', "") vdu_metadata['name'] = vdu_record.get('name', "") vdu_metadata["flavor"]["ram"] = None vdu_metadata["flavor"]["vcpus"] = None vdu_metadata["flavor"]["disk"] = None elif source == "openstack": """By default, OpenStack (ceilometer) provides us the following info: vcpus, ram, ephemeral, swap, disk, name, id """ pass # Get IP per VDU vdu_metadata['ip_address'] = vdu_record.get("ip-address", None) # Get the VIM account Info vim_account = VimAccount(token) vim_response = vim_account.get( vim_account_uuid=nsr.get('datacenter', None)) vimr = vim_response.json() # Get the NSd uuid nsd_id = nsr.get('nsdId', None) if nsd_id is None: nsd_id = nsr.get('instantiate_params', {}).get('nsdId', None) mano = { "ns": { "id": ns_id, "name": nsr.get('name-ref', None), "nsd_id": nsd_id, "nsd_name": nsr.get('nsd-name-ref', None) }, "vnf": { "id": vnf_record.get("id", None), "name": vnf_record.get("name", None), # not in osm r5: it could be <vnfd_name>_<index> "index": vnf_record.get("member-vnf-index-ref", 0), "short_name": vnf_record.get("short-name", None), # not in osm r5 "vnfd_id": vnf_record.get("vnfd-id", None), "vnfd_name": vnf_record.get('vnfd-ref', None) }, "vdu": { "id": vdu_metadata.get("instance_id", None), "name": vdu_metadata.get("name", None), "image_id": vdu_metadata.get("image", {}).get("id", None), "flavor": vdu_metadata.get("flavor", {}), "status": vdu_metadata.get("state", None), "ip_address": vdu_metadata['ip_address'], "mgmt-interface": None # future usage }, "vim": { "uuid": vimr.get('_id', None), "name": vimr.get('name', None), "type": vimr.get('vim_type', None), "url": vimr.get('vim_url', None), "tag": source } } logger.debug(mano) except Exception as ex: logger.exception(ex) finally: # TODO: Since we don't know the VDU uuid, the 1st VDU will be used since 1 VDU is used for the VNF (UC1). return mano
def get_vdus_info(ns_uuid=None): """Get information about NS, VNF(s) and VDU(s) by given NS uuid Args: ns_uuid (str): The NS uuid Returns: dict: ns, vnf and vdu info """ vdus_info = [] if ns_uuid is None: return vdus_info token = bearer_token(OSM_ADMIN_CREDENTIALS.get('username'), OSM_ADMIN_CREDENTIALS.get('username')) ns = Ns(token) ns_response = ns.get(ns_uuid=ns_uuid) nsr = ns_response.json() # Get Vim vim_uuid = nsr.get('datacenter', None) vim_info = get_vim_info(vim_uuid=vim_uuid) # Get the Vnf UUIDs, members of the NS vnf_uuids = nsr.get('constituent-vnfr-ref', []) vnfr = Vnf(token) for vnf_uuid in vnf_uuids: vnf_response = vnfr.get(vnf_uuid=vnf_uuid) vnf_record = vnf_response.json() # VDUs info vdu_records = vnf_record.get('vdur', []) for vdu_record in vdu_records: mano = { "vim": vim_info, "ns": { "id": ns_uuid, "name": nsr.get('name-ref', None), "nsd_id": nsr.get('nsdId', None), "nsd_name": nsr.get('nsd-name-ref', None) }, "vnf": { "id": vnf_record.get("id", None), "name": None, # not provided in osm r4 "short_name": None, # not provided in osm r4 "vnfd_id": vnf_record.get("vnfd-id", None), "vnfd_name": None # not provided in osm r4 }, "vdu": { "id": vdu_record.get("vim-id", None), # NFVI-based uuid "image_id": None, "flavor": {}, "status": vdu_record.get("status", None), "ip_address": vdu_record.get("ip-address", None), "mgmt-interface": None # future usage } } vdus_info.append(mano) return vdus_info