Skip to content

Commit 5255683

Browse files
authored
Merge pull request #950 from netenglabs/interface-add-support-for-vrf-bond
Interface add support for vrf bond
2 parents 9ffb095 + 68e34ef commit 5255683

File tree

30 files changed

+7857
-34279
lines changed

30 files changed

+7857
-34279
lines changed

suzieq/cli/sqcmds/InterfaceCmd.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"!notConnected"])
2121
@argument("mtu",
2222
description="MTU(s), space separated, can use <, >, <=, >=, !")
23+
@argument("macaddr",
24+
description="interface macaddr, space separated")
25+
@argument("bond",
26+
description="show portchannel and mbr ports for, space separated")
2327
class InterfaceCmd(SqTableCommand):
2428
"""Device interface information including MTU, Speed, IP address etc"""
2529

@@ -42,6 +46,8 @@ def __init__(
4246
mtu: str = '',
4347
portmode: str = '',
4448
vlan: str = '',
49+
macaddr: str = '',
50+
bond: str = ''
4551
) -> None:
4652
super().__init__(
4753
engine=engine,
@@ -63,6 +69,8 @@ def __init__(
6369
'mtu': mtu.split(),
6470
'vlan': vlan.split(),
6571
'portmode': portmode.split(),
72+
'macaddr': macaddr.split(),
73+
'bond': bond.split()
6674
}
6775

6876
@command("assert")

suzieq/engines/pandas/address.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import numpy as np
44
import pandas as pd
5+
import pyarrow as pa
6+
import pyarrow.compute as pc
57

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

69-
if df.empty:
71+
if df.empty or 'error' in df:
7072
return df
7173

74+
# pylint: disable=no-member
75+
df['v4addrlen'] = pc.list_value_length(
76+
pa.array(df.ipAddressList)).to_pandas()
77+
# pylint: disable=no-member
78+
df['v6addrlen'] = pc.list_value_length(
79+
pa.array(df.ip6AddressList)).to_pandas()
80+
81+
df = (
82+
df.query('v4addrlen > 0 or v6addrlen > 0')
83+
.reset_index(drop=True)
84+
)
85+
7286
if 'master' in df.columns:
7387
df = df.rename({'master': 'vrf'}, axis=1) \
7488
.replace({'vrf': {'': 'default'}})

suzieq/engines/pandas/interfaces.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def table_name():
2727
'''Table name'''
2828
return 'interfaces'
2929

30+
# pylint: disable=too-many-statements
3031
def get(self, **kwargs):
3132
"""Handling state outside of regular filters"""
3233
state = kwargs.pop('state', '')
@@ -38,11 +39,16 @@ def get(self, **kwargs):
3839
user_query = kwargs.pop('query_str', '')
3940
vlan = kwargs.pop('vlan', '')
4041
portmode = kwargs.pop('portmode', '')
42+
macaddr: List[str] = kwargs.pop('macaddr', [])
43+
bond: List[str] = kwargs.pop('bond', [])
4144

4245
addnl_fields = []
4346
if vrf:
4447
master.extend(vrf)
4548

49+
if bond:
50+
master.extend(bond)
51+
4652
fields = self.schema.get_display_fields(columns)
4753
self._add_active_to_fields(kwargs.get('view', self.iobj.view), fields,
4854
addnl_fields)
@@ -51,6 +57,29 @@ def get(self, **kwargs):
5157
user_query_cols = self._get_user_query_cols(user_query)
5258
addnl_fields += [x for x in user_query_cols if x not in addnl_fields]
5359

60+
if vlan or portmode or ('vlan' in columns and
61+
'portmode' not in addnl_fields+fields):
62+
addnl_fields.append('portmode')
63+
if 'vlan' not in fields+addnl_fields:
64+
addnl_fields.append('vlan')
65+
66+
if state and 'state' not in addnl_fields+fields:
67+
addnl_fields.append('state')
68+
69+
if macaddr and 'macaddr' not in fields + addnl_fields:
70+
addnl_fields.append('macaddr')
71+
72+
if any(x in addnl_fields + fields
73+
for x in ['portmode', 'vlanList', 'vlan']):
74+
req_pm_fields = ['namespace', 'hostname', 'state', 'adminState',
75+
'type', 'ipAddressList', 'ip6AddressList']
76+
addnl_fields.extend([f for f in req_pm_fields
77+
if f not in addnl_fields + fields])
78+
79+
if bond:
80+
if 'master' not in fields + addnl_fields:
81+
addnl_fields.append('master')
82+
5483
if not ifname and iftype and iftype != ["all"]:
5584
df = super().get(type=iftype, master=master, columns=fields,
5685
addnl_fields=addnl_fields, **kwargs)
@@ -75,9 +104,9 @@ def get(self, **kwargs):
75104
if vlan or "vlanList" in fields:
76105
df = self._add_vlanlist(df, **kwargs)
77106

78-
if state or portmode:
107+
if state or portmode or macaddr:
79108
query_str = build_query_str([], self.schema, state=state,
80-
portmode=portmode)
109+
portmode=portmode, macaddr=macaddr)
81110

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

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

731-
def _add_vlanlist(self, df: pd.DataFrame, **kwargs) -> pd.DataFrame():
760+
def _add_vlanlist(self, df: pd.DataFrame, **kwargs) -> pd.DataFrame:
732761
"""Add list of active, unpruned VLANs on trunked ports
733762
734763
:param df[pd.Dataframe]: The dataframe to add vlanList to

suzieq/restServer/query.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ def query_interface(verb: CommonExtraVerbs, request: Request,
446446
ignore_missing_peer: bool = Query(False),
447447
vlan: List[str] = Query(None),
448448
portmode: List[str] = Query(None),
449+
macaddr: List[str] = Query(None),
450+
bond: List[str] = Query(None),
449451
query_str: str = None,
450452
count: str = None, reverse: str = None,
451453
):

suzieq/sqobjects/interfaces.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def __init__(self, **kwargs):
1313
super().__init__(table='interfaces', **kwargs)
1414
self._valid_get_args = ['namespace', 'hostname', 'ifname', 'columns',
1515
'state', 'type', 'mtu', 'master', 'ifindex',
16-
'vrf', 'portmode', 'vlan', 'query_str']
16+
'vrf', 'portmode', 'vlan', 'query_str',
17+
'bond', 'macaddr']
1718
self._valid_assert_args = self._valid_get_args + \
1819
['what', 'value', 'result', 'ignore_missing_peer']
1920
self._valid_arg_vals = {

0 commit comments

Comments
 (0)