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

Interface add support for vrf bond #950

Merged
merged 15 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions suzieq/cli/sqcmds/InterfaceCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"!notConnected"])
@argument("mtu",
description="MTU(s), space separated, can use <, >, <=, >=, !")
@argument("macaddr",
description="interface macaddr, space separated")
@argument("bond",
description="show portchannel and mbr ports for, space separated")
class InterfaceCmd(SqTableCommand):
"""Device interface information including MTU, Speed, IP address etc"""

Expand All @@ -42,6 +46,8 @@ def __init__(
mtu: str = '',
portmode: str = '',
vlan: str = '',
macaddr: str = '',
bond: str = ''
) -> None:
super().__init__(
engine=engine,
Expand All @@ -63,6 +69,8 @@ def __init__(
'mtu': mtu.split(),
'vlan': vlan.split(),
'portmode': portmode.split(),
'macaddr': macaddr.split(),
'bond': bond.split()
}

@command("assert")
Expand Down
16 changes: 15 additions & 1 deletion suzieq/engines/pandas/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import numpy as np
import pandas as pd
import pyarrow as pa
import pyarrow.compute as pc

from suzieq.engines.pandas.engineobj import SqPandasEngine
from suzieq.shared.utils import (convert_macaddr_format_to_colon,
Expand Down Expand Up @@ -66,9 +68,21 @@ def get(self, **kwargs) -> pd.DataFrame:
df = super().get(addnl_fields=addnl_fields, columns=fields,
**kwargs)

if df.empty:
if df.empty or 'error' in df:
return df

# pylint: disable=no-member
df['v4addrlen'] = pc.list_value_length(
pa.array(df.ipAddressList)).to_pandas()
# pylint: disable=no-member
df['v6addrlen'] = pc.list_value_length(
pa.array(df.ip6AddressList)).to_pandas()

df = (
df.query('v4addrlen > 0 or v6addrlen > 0')
.reset_index(drop=True)
)

if 'master' in df.columns:
df = df.rename({'master': 'vrf'}, axis=1) \
.replace({'vrf': {'': 'default'}})
Expand Down
35 changes: 32 additions & 3 deletions suzieq/engines/pandas/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def table_name():
'''Table name'''
return 'interfaces'

# pylint: disable=too-many-statements
def get(self, **kwargs):
"""Handling state outside of regular filters"""
state = kwargs.pop('state', '')
Expand All @@ -38,11 +39,16 @@ def get(self, **kwargs):
user_query = kwargs.pop('query_str', '')
vlan = kwargs.pop('vlan', '')
portmode = kwargs.pop('portmode', '')
macaddr: List[str] = kwargs.pop('macaddr', [])
bond: List[str] = kwargs.pop('bond', [])

addnl_fields = []
if vrf:
master.extend(vrf)

if bond:
master.extend(bond)

fields = self.schema.get_display_fields(columns)
self._add_active_to_fields(kwargs.get('view', self.iobj.view), fields,
addnl_fields)
Expand All @@ -51,6 +57,29 @@ def get(self, **kwargs):
user_query_cols = self._get_user_query_cols(user_query)
addnl_fields += [x for x in user_query_cols if x not in addnl_fields]

if vlan or portmode or ('vlan' in columns and
'portmode' not in addnl_fields+fields):
addnl_fields.append('portmode')
if 'vlan' not in fields+addnl_fields:
addnl_fields.append('vlan')

if state and 'state' not in addnl_fields+fields:
addnl_fields.append('state')

if macaddr and 'macaddr' not in fields + addnl_fields:
addnl_fields.append('macaddr')

if any(x in addnl_fields + fields
for x in ['portmode', 'vlanList', 'vlan']):
req_pm_fields = ['namespace', 'hostname', 'state', 'adminState',
'type', 'ipAddressList', 'ip6AddressList']
addnl_fields.extend([f for f in req_pm_fields
if f not in addnl_fields + fields])

if bond:
if 'master' not in fields + addnl_fields:
addnl_fields.append('master')

if not ifname and iftype and iftype != ["all"]:
df = super().get(type=iftype, master=master, columns=fields,
addnl_fields=addnl_fields, **kwargs)
Expand All @@ -75,9 +104,9 @@ def get(self, **kwargs):
if vlan or "vlanList" in fields:
df = self._add_vlanlist(df, **kwargs)

if state or portmode:
if state or portmode or macaddr:
query_str = build_query_str([], self.schema, state=state,
portmode=portmode)
portmode=portmode, macaddr=macaddr)

df = df.query(query_str).reset_index(drop=True)

Expand Down Expand Up @@ -728,7 +757,7 @@ def _add_portmode(self, df: pd.DataFrame, **kwargs):
return df.drop(columns=['portmode_y', 'vlan_y'],
errors='ignore')

def _add_vlanlist(self, df: pd.DataFrame, **kwargs) -> pd.DataFrame():
def _add_vlanlist(self, df: pd.DataFrame, **kwargs) -> pd.DataFrame:
"""Add list of active, unpruned VLANs on trunked ports

:param df[pd.Dataframe]: The dataframe to add vlanList to
Expand Down
2 changes: 2 additions & 0 deletions suzieq/restServer/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ def query_interface(verb: CommonExtraVerbs, request: Request,
ignore_missing_peer: bool = Query(False),
vlan: List[str] = Query(None),
portmode: List[str] = Query(None),
macaddr: List[str] = Query(None),
bond: List[str] = Query(None),
query_str: str = None,
count: str = None, reverse: str = None,
):
Expand Down
3 changes: 2 additions & 1 deletion suzieq/sqobjects/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def __init__(self, **kwargs):
super().__init__(table='interfaces', **kwargs)
self._valid_get_args = ['namespace', 'hostname', 'ifname', 'columns',
'state', 'type', 'mtu', 'master', 'ifindex',
'vrf', 'portmode', 'vlan', 'query_str']
'vrf', 'portmode', 'vlan', 'query_str',
'bond', 'macaddr']
self._valid_assert_args = self._valid_get_args + \
['what', 'value', 'result', 'ignore_missing_peer']
self._valid_arg_vals = {
Expand Down
Loading
Loading