Skip to content

Commit

Permalink
Merge pull request #948 from netenglabs/sonic-if-parsing-internal
Browse files Browse the repository at this point in the history
sonic: change some interfaces to 'internal'
  • Loading branch information
ddutt authored May 23, 2024
2 parents a57d62c + e6ddd0f commit 00153e5
Showing 1 changed file with 50 additions and 37 deletions.
87 changes: 50 additions & 37 deletions suzieq/poller/worker/services/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from collections import defaultdict
from json import loads
from typing import Dict
import numpy as np

from suzieq.poller.worker.services.service import Service
Expand Down Expand Up @@ -202,25 +203,22 @@ def _clean_eos_data(self, processed_data, _):

return processed_data

def _clean_cumulus_data(self, processed_data, _):
"""We have to merge the appropriate outputs of two separate commands"""
def _entry_cumulus_sonic_cleaner(self, entry: Dict):
if entry.get('hardware', '') == 'ether':
entry['type'] = 'ethernet'

for entry in processed_data:
if entry.get('hardware', '') == 'ether':
entry['type'] = 'ethernet'
if entry['adminState'] == "down":
entry['state'] = "down"

if entry['adminState'] == "down":
entry['state'] = "down"
if entry['type'] == 'ether':
entry['type'] = 'ethernet'
if entry.get('type', '') == 'vxlan':
entry['speed'] = NO_SPEED

if entry['type'] == 'ether':
entry['type'] = 'ethernet'
if entry.get('type', '') == 'vxlan':
entry['speed'] = NO_SPEED

if not entry['linkUpCnt']:
entry['linkUpCnt'] = 0
if not entry['linkDownCnt']:
entry['linkDownCnt'] = 0
if not entry['linkUpCnt']:
entry['linkUpCnt'] = 0
if not entry['linkDownCnt']:
entry['linkDownCnt'] = 0

entry["numChanges"] = (int(entry["linkUpCnt"]) +
int(entry["linkDownCnt"]))
Expand All @@ -243,30 +241,36 @@ def _clean_cumulus_data(self, processed_data, _):
entry["statusChangeTimestamp1"] = entry.get(
"statusChangeTimestamp", '')

if '(' in entry['master']:
entry['master'] = entry['master'].replace(
'(', '').replace(')', '')
if '(' in entry['master']:
entry['master'] = entry['master'].replace(
'(', '').replace(')', '')

# Lowercase the master value thanks to SoNIC
entry['master'] = entry.get('master', '').lower()
if entry['ip6AddressList'] and 'ip6AddressList-_2nd' in entry:
# This is because textfsm adds peer LLA as well
entry['ip6AddressList'] = entry['ip6AddressList-_2nd']
# Lowercase the master value thanks to SoNIC
entry['master'] = entry.get('master', '').lower()
if entry['ip6AddressList'] and 'ip6AddressList-_2nd' in entry:
# This is because textfsm adds peer LLA as well
entry['ip6AddressList'] = entry['ip6AddressList-_2nd']

# Remove loopbacks
entry['ip6AddressList'] = [x for x in entry['ip6AddressList']
if x != "::1/128"]
# Remove loopbacks
entry['ip6AddressList'] = [x for x in entry['ip6AddressList']
if x != "::1/128"]

if 'type-_2nd' in entry:
entry['type'] = entry['type-_2nd']
if 'type-_2nd' in entry:
entry['type'] = entry['type-_2nd']

del entry["linkUpCnt"]
del entry["linkDownCnt"]
del entry["linkUpTimestamp"]
del entry["linkDownTimestamp"]
del entry["vrf"]
del entry["linkUpCnt"]
del entry["linkDownCnt"]
del entry["linkUpTimestamp"]
del entry["linkDownTimestamp"]
del entry["vrf"]

entry['speed'] = self._textfsm_valid_speed_value(entry)
entry['speed'] = self._textfsm_valid_speed_value(entry)

def _clean_cumulus_data(self, processed_data, _):
"""We have to merge the appropriate outputs of two separate commands"""

for entry in processed_data:
self._entry_cumulus_sonic_cleaner(entry)

return processed_data

Expand Down Expand Up @@ -956,8 +960,17 @@ def _clean_iosxe_data(self, processed_data, raw_data):
def _clean_ios_data(self, processed_data, raw_data):
return self._clean_iosxr_data(processed_data, raw_data)

def _clean_sonic_data(self, processed_data, raw_data):
return self._clean_cumulus_data(processed_data, raw_data)
def _clean_sonic_data(self, processed_data, _):

internal_ifnames = ['BFDRX', 'BFDTX', 'CPU', 'bcm0', 'dummy']

for entry in processed_data:
self._entry_cumulus_sonic_cleaner(entry)

if entry.get('ifname', '') in internal_ifnames:
entry['type'] = 'internal'

return processed_data

def _common_data_cleaner(self, processed_data, _):
for entry in processed_data:
Expand Down

0 comments on commit 00153e5

Please sign in to comment.