Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sonic: change some interfaces to 'internal' #948

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading