def _clean_nxos_data(self, processed_data, raw_data): for entry in processed_data: entry['state'] = entry['state'].lower() entry['numChanges'] = int(entry['numChanges']) # Cisco's format examples are PT7H28M21S, P1DT4H9M46S entry['lastChangeTime'] = get_timestamp_from_cisco_time( entry['lastChangeTime'], raw_data[0]['timestamp']/1000) return processed_data
def _clean_nxos_data(self, processed_data, raw_data): entries_by_vrf = {} drop_indices = [] new_entries = [] # To add the AFI/SAFI-based entries for j, entry in enumerate(processed_data): if entry['_entryType'] == 'summary': for ventry in entries_by_vrf.get(entry['vrf'], []): ventry['asn'] = entry['asn'] ventry['routerId'] = entry['routerId'] drop_indices.append(j) continue if (entry.get('extnhAdvertised', False) == "true" and entry.get('extnhReceived', False) == "true"): entry['extnhEnabled'] = True else: entry['extnhEnabled'] = False entry['estdTime'] = get_timestamp_from_cisco_time( entry['estdTime'], raw_data[0]['timestamp'] / 1000) if entry['vrf'] not in entries_by_vrf: entries_by_vrf[entry['vrf']] = [] if not entry['peer']: if not entry.get('_dynPeer', None): drop_indices.append(i) continue entry['peer'] = entry['_dynPeer'].replace('/', '-') entry['origPeer'] = entry['_dynPeer'] entry['state'] = 'dynamic' entry['pfxRx'] = entry['_activePeers'] entry['pfxTx'] = entry['_maxconcurrentpeers'] entry['afi'] = entry['safi'] = 'dynamic' entry['estdTime'] = entry['_firstconvgtime'] if entry['state'] != 'Established': entry.pop('afiPrefix') entry.pop('pfxRcvd') entry.pop('pfxSent') entry.pop('sendComm') entry.pop('extendComm') entry.pop('defaultOrig') entry.pop('afiSafi') entry['afi'] = entry['safi'] = '' entries_by_vrf[entry['vrf']].append(entry) continue entry['afisAdvOnly'] = [] entry['afisRcvOnly'] = [] for i, item in enumerate(entry['afiSafi']): if entry['afAdvertised'][i] != entry['afRcvd'][i]: if entry['afAdvertised'][i] == 'true': entry['afisAdvOnly'].append(entry['afiSafi']) else: entry['afisRcvOnly'].append(entry['afiSafi']) entry.pop('afiSafi') entry.pop('afAdvertised') entry.pop('afRcvd') entry['rrclient'] = entry.get('rrclient', False) == "true" defint_list = [0] * len(entry.get('afiPrefix', [])) defbool_list = [False] * len(entry.get('afiPrefix', [])) defstr_list = [""] * len(entry.get('afiPrefix', [])) pfxRx_list = entry.get('pfxRcvd', []) or defint_list pfxTx_list = entry.get('pfxSent', []) or defint_list deforig_list = entry.get('defaultOrig', []) or defbool_list extcomm_list = entry.get('extendComm', []) or defbool_list comm_list = entry.get('sendComm', []) or defbool_list withdrawn_list = entry.get('pfxWithdrawn', []) or defint_list softrecon_list = entry.get('softReconfig', []) or defbool_list irmap_list = entry.get('ingressRmap', []) or defstr_list ermap_list = entry.get('egressRmap', []) or defstr_list for i, item in enumerate(entry['afiPrefix']): new_entry = deepcopy(entry) new_entry['afi'], new_entry['safi'] = \ [x.lower() for x in item.split()] new_entry['pfxRx'] = pfxRx_list[i] new_entry['pfxTx'] = pfxTx_list[i] new_entry['pfxWithdrawn'] = withdrawn_list[i] new_entry['softReconfig'] = softrecon_list[i] new_entry['defOriginate'] = deforig_list[i] new_entry['communityTypes'] = [] if comm_list[i]: new_entry['communityTypes'].append('standard') if extcomm_list[i] == "true": new_entry['communityTypes'].append('extended') new_entry['ingressRmap'] = irmap_list[i] new_entry['egressRmap'] = ermap_list[i] new_entry.pop('afiPrefix') new_entry.pop('pfxRcvd') new_entry.pop('pfxSent') new_entry.pop('sendComm') new_entry.pop('extendComm') new_entry.pop('defaultOrig') new_entries.append(new_entry) entries_by_vrf[new_entry['vrf']].append(new_entry) drop_indices.append(j) processed_data += new_entries processed_data = np.delete(processed_data, drop_indices).tolist() return processed_data
def _clean_nxos_data(self, processed_data, raw_data): entries_by_vrf = {} drop_indices = [] for i, entry in enumerate(processed_data): if entry['_entryType'] == 'summary': for ventry in entries_by_vrf.get(entry['vrf'], []): ventry['asn'] = entry['asn'] ventry['routerId'] = entry['routerId'] drop_indices.append(i) continue for i, item in enumerate(entry['afiSafi']): if item == 'IPv4 Unicast': entry['v4Advertised'] = entry['afAdvertised'][i] entry['v4Received'] = entry['afRcvd'][i] if (entry['v4Advertised'] == "true" and entry['v4Received'] == "true"): entry['v4Enabled'] = True else: entry['v4Enabled'] = False elif item == 'IPv6 Unicast': entry['v6Advertised'] = entry['afAdvertised'][i] entry['v6Received'] = entry['afRcvd'][i] if (entry['v6Advertised'] == "true" and entry['v6Received'] == "true"): entry['v6Enabled'] = True else: entry['v6Enabled'] = False elif item == 'L2VPN EVPN': entry['evpnAdvertised'] = entry['afAdvertised'][i] entry['evpnReceived'] = entry['afRcvd'][i] if (entry['evpnAdvertised'] == "true" and entry['evpnReceived'] == "true"): entry['evpnEnabled'] = True else: entry['evpnEnabled'] = False entry.pop('afiSafi') entry.pop('afAdvertised') entry.pop('afRcvd') entry['rrClient'] = entry.get('rrclient', False) == "true" defint_list = [0] * len(entry.get('afiPrefix', [])) defbool_list = [False] * len(entry.get('afiPrefix', [])) pfxRx_list = entry.get('pfxRcvd', []) or defint_list pfxTx_list = entry.get('pfxSent', []) or defint_list deforig_list = entry.get('defaultOrig', []) or defbool_list extcomm_list = entry.get('extendComm', []) or defbool_list comm_list = entry.get('sendComm', []) or defbool_list for i, item in enumerate(entry['afiPrefix']): if item == 'IPv4 Unicast': entry['v4PfxRx'] = pfxRx_list[i] entry['v4PfxTx'] = pfxTx_list[i] entry['v4DefaultSent'] = deforig_list[i] elif item == 'IPv6 Unicast': entry['v6PfxRx'] = pfxRx_list[i] entry['v6PfxTx'] = pfxTx_list[i] entry['v6DefaultSent'] = deforig_list[i] elif item == 'L2VPN EVPN': entry['evpnPfxRx'] = pfxRx_list[i] entry['evpnPfxTx'] = pfxTx_list[i] entry['evpnDefaultSent'] = deforig_list[i] if comm_list[i] == "true": if extcomm_list[i] == "true": entry['evpnSendCommunity'] = 'extendedAndstandard' else: entry['evpnSendCommunity'] = 'standard' elif extcomm_list[i] == "true": entry['evpnSendCommunity'] = 'extended' entry.pop('afiPrefix') entry.pop('pfxRcvd') entry.pop('pfxSent') entry.pop('sendComm') entry.pop('extendComm') entry.pop('defaultOrig') if (entry.get('extnhAdvertised', False) == "true" and entry.get('extnhReceived', False) == "true"): entry['extnhEnabled'] = True else: entry['extnhEnabled'] = False entry['estdTime'] = get_timestamp_from_cisco_time( entry['estdTime'], raw_data[0]['timestamp'] / 1000) if entry['vrf'] not in entries_by_vrf: entries_by_vrf[entry['vrf']] = [] entries_by_vrf[entry['vrf']].append(entry) processed_data = np.delete(processed_data, drop_indices).tolist() return processed_data