22from datetime import datetime
33from collections import defaultdict
44from json import loads
5+ from typing import Dict
56import numpy as np
67
78from suzieq .poller .worker .services .service import Service
@@ -202,25 +203,22 @@ def _clean_eos_data(self, processed_data, _):
202203
203204 return processed_data
204205
205- def _clean_cumulus_data (self , processed_data , _ ):
206- """We have to merge the appropriate outputs of two separate commands"""
206+ def _entry_cumulus_sonic_cleaner (self , entry : Dict ):
207+ if entry .get ('hardware' , '' ) == 'ether' :
208+ entry ['type' ] = 'ethernet'
207209
208- for entry in processed_data :
209- if entry .get ('hardware' , '' ) == 'ether' :
210- entry ['type' ] = 'ethernet'
210+ if entry ['adminState' ] == "down" :
211+ entry ['state' ] = "down"
211212
212- if entry ['adminState' ] == "down" :
213- entry ['state' ] = "down"
213+ if entry ['type' ] == 'ether' :
214+ entry ['type' ] = 'ethernet'
215+ if entry .get ('type' , '' ) == 'vxlan' :
216+ entry ['speed' ] = NO_SPEED
214217
215- if entry ['type' ] == 'ether' :
216- entry ['type' ] = 'ethernet'
217- if entry .get ('type' , '' ) == 'vxlan' :
218- entry ['speed' ] = NO_SPEED
219-
220- if not entry ['linkUpCnt' ]:
221- entry ['linkUpCnt' ] = 0
222- if not entry ['linkDownCnt' ]:
223- entry ['linkDownCnt' ] = 0
218+ if not entry ['linkUpCnt' ]:
219+ entry ['linkUpCnt' ] = 0
220+ if not entry ['linkDownCnt' ]:
221+ entry ['linkDownCnt' ] = 0
224222
225223 entry ["numChanges" ] = (int (entry ["linkUpCnt" ]) +
226224 int (entry ["linkDownCnt" ]))
@@ -243,30 +241,36 @@ def _clean_cumulus_data(self, processed_data, _):
243241 entry ["statusChangeTimestamp1" ] = entry .get (
244242 "statusChangeTimestamp" , '' )
245243
246- if '(' in entry ['master' ]:
247- entry ['master' ] = entry ['master' ].replace (
248- '(' , '' ).replace (')' , '' )
244+ if '(' in entry ['master' ]:
245+ entry ['master' ] = entry ['master' ].replace (
246+ '(' , '' ).replace (')' , '' )
249247
250- # Lowercase the master value thanks to SoNIC
251- entry ['master' ] = entry .get ('master' , '' ).lower ()
252- if entry ['ip6AddressList' ] and 'ip6AddressList-_2nd' in entry :
253- # This is because textfsm adds peer LLA as well
254- entry ['ip6AddressList' ] = entry ['ip6AddressList-_2nd' ]
248+ # Lowercase the master value thanks to SoNIC
249+ entry ['master' ] = entry .get ('master' , '' ).lower ()
250+ if entry ['ip6AddressList' ] and 'ip6AddressList-_2nd' in entry :
251+ # This is because textfsm adds peer LLA as well
252+ entry ['ip6AddressList' ] = entry ['ip6AddressList-_2nd' ]
255253
256- # Remove loopbacks
257- entry ['ip6AddressList' ] = [x for x in entry ['ip6AddressList' ]
258- if x != "::1/128" ]
254+ # Remove loopbacks
255+ entry ['ip6AddressList' ] = [x for x in entry ['ip6AddressList' ]
256+ if x != "::1/128" ]
259257
260- if 'type-_2nd' in entry :
261- entry ['type' ] = entry ['type-_2nd' ]
258+ if 'type-_2nd' in entry :
259+ entry ['type' ] = entry ['type-_2nd' ]
262260
263- del entry ["linkUpCnt" ]
264- del entry ["linkDownCnt" ]
265- del entry ["linkUpTimestamp" ]
266- del entry ["linkDownTimestamp" ]
267- del entry ["vrf" ]
261+ del entry ["linkUpCnt" ]
262+ del entry ["linkDownCnt" ]
263+ del entry ["linkUpTimestamp" ]
264+ del entry ["linkDownTimestamp" ]
265+ del entry ["vrf" ]
268266
269- entry ['speed' ] = self ._textfsm_valid_speed_value (entry )
267+ entry ['speed' ] = self ._textfsm_valid_speed_value (entry )
268+
269+ def _clean_cumulus_data (self , processed_data , _ ):
270+ """We have to merge the appropriate outputs of two separate commands"""
271+
272+ for entry in processed_data :
273+ self ._entry_cumulus_sonic_cleaner (entry )
270274
271275 return processed_data
272276
@@ -956,8 +960,17 @@ def _clean_iosxe_data(self, processed_data, raw_data):
956960 def _clean_ios_data (self , processed_data , raw_data ):
957961 return self ._clean_iosxr_data (processed_data , raw_data )
958962
959- def _clean_sonic_data (self , processed_data , raw_data ):
960- return self ._clean_cumulus_data (processed_data , raw_data )
963+ def _clean_sonic_data (self , processed_data , _ ):
964+
965+ internal_ifnames = ['BFDRX' , 'BFDTX' , 'CPU' , 'bcm0' , 'dummy' ]
966+
967+ for entry in processed_data :
968+ self ._entry_cumulus_sonic_cleaner (entry )
969+
970+ if entry .get ('ifname' , '' ) in internal_ifnames :
971+ entry ['type' ] = 'internal'
972+
973+ return processed_data
961974
962975 def _common_data_cleaner (self , processed_data , _ ):
963976 for entry in processed_data :
0 commit comments