Skip to content

Commit fc7a243

Browse files
authored
Merge pull request #977 from netenglabs/feature/device-filter-address
New feature device filter address
2 parents 11201d7 + 97a11e7 commit fc7a243

File tree

11 files changed

+96
-35
lines changed

11 files changed

+96
-35
lines changed

suzieq/cli/sqcmds/AddressCmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
description="type of address, v4, v6 or l2",
1414
choices=["v4", "v6", "l2"])
1515
@argument("address",
16-
description="Address(es), in quotes, space separated")
16+
description="IP Address(es), in quotes, space separated")
1717
@argument("prefix",
1818
description=("Show all the addresses in this "
1919
"subnet prefix (in quotes)"))

suzieq/cli/sqcmds/DeviceCmd.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
@argument("version", description="NOS version(s), space separated")
1313
@argument("vendor", description="Vendor(s), space separated")
1414
@argument("model", description="Model(s), space separated")
15+
@argument("address", description="IP Address(es), in quotes, space separated")
1516
class DeviceCmd(SqTableCommand):
1617
"""Basic device information such as OS, version, model etc."""
1718

@@ -31,6 +32,7 @@ def __init__(
3132
status: str = '',
3233
vendor: str = '',
3334
model: str = '',
35+
address: str = '',
3436
) -> None:
3537
super().__init__(
3638
engine=engine,
@@ -60,5 +62,6 @@ def __init__(
6062
'version': version.split(),
6163
'status': status.split(),
6264
'model': model,
63-
'vendor': vendor.split()
65+
'vendor': vendor.split(),
66+
'address': address.split()
6467
}

suzieq/restServer/query.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ def query_device(verb: CommonVerbs, request: Request,
365365
status: List[DeviceStatus] = Query(None),
366366
ignore_neverpoll: bool = None,
367367
count: str = None, reverse: str = None,
368+
address: List[str] = Query(None)
368369
):
369370
function_name = inspect.currentframe().f_code.co_name
370371
if status:

suzieq/sqobjects/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, **kwargs):
1212
super().__init__(table='device', **kwargs)
1313
self._valid_get_args = ['namespace', 'hostname', 'columns', 'os',
1414
'vendor', 'model', 'status', 'version',
15-
'query_str', 'ignore_neverpoll']
15+
'query_str', 'ignore_neverpoll', 'address']
1616
self._valid_arg_vals = {
1717
'status': ['alive', 'dead', 'neverpoll',
1818
'!alive', '!dead', '!neverpoll']

tests/integration/sqcmds/common-samples/help.yml

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,11 @@ tests:
279279
format: text
280280
marks: device help command
281281
output: "device show: \e[36mShow address info\e[0m\n\e[33m\nUse quotes when providing\
282-
\ more than one value\e[0m\n\e[33m\nArguments:\e[0m\n - columns: \e[36m\e[1mSpace\
283-
\ separated list of columns, * for all\e[0m\n - end_time: \e[36m\e[1mEnd of time\
284-
\ window, try natural language spec \e[0m\n - format: \e[36m\e[1mSelect the pformat\
285-
\ of the output\e[0m\n - hostname: \e[36m\e[1mHostname(s), space separated\e[0m\n\
282+
\ more than one value\e[0m\n\e[33m\nArguments:\e[0m\n - address: \e[36m\e[1mIP\
283+
\ Address(es), in quotes, space separated\e[0m\n - columns: \e[36m\e[1mSpace separated\
284+
\ list of columns, * for all\e[0m\n - end_time: \e[36m\e[1mEnd of time window,\
285+
\ try natural language spec \e[0m\n - format: \e[36m\e[1mSelect the pformat of\
286+
\ the output\e[0m\n - hostname: \e[36m\e[1mHostname(s), space separated\e[0m\n\
286287
\ - model: \e[36m\e[1mFilter by model\e[0m\n - namespace: \e[36m\e[1mNamespace(s),\
287288
\ space separated\e[0m\n - os: \e[36m\e[1mNOS(s), space separated\e[0m\n - query_str:\
288289
\ \e[36m\e[1mTrailing blank terminated pandas query format to further filter the\
@@ -297,46 +298,49 @@ tests:
297298
marks: device help command
298299
output: "device summarize: \e[36mSummarize relevant information about the table\e\
299300
[0m\n\e[33m\nUse quotes when providing more than one value\e[0m\n\e[33m\nArguments:\e\
300-
[0m\n - columns: \e[36m\e[1mSpace separated list of columns, * for all\e[0m\n\
301-
\ - end_time: \e[36m\e[1mEnd of time window, try natural language spec \e[0m\n\
302-
\ - format: \e[36m\e[1mSelect the pformat of the output\e[0m\n - hostname: \e\
303-
[36m\e[1mHostname(s), space separated\e[0m\n - model: \e[36m\e[1mFilter by model\e\
304-
[0m\n - namespace: \e[36m\e[1mNamespace(s), space separated\e[0m\n - os: \e[36m\e\
305-
[1mNOS(s), space separated\e[0m\n - query_str: \e[36m\e[1mTrailing blank terminated\
306-
\ pandas query format to further filter the output\e[0m\n - start_time: \e[36m\e\
307-
[1mStart of time window, try natural language spec\e[0m\n - status: \e[36m\e[1mstatus\
308-
\ of service to match\e[0m\n - vendor: \e[36m\e[1mVendor(s), space separated\e\
309-
[0m\n - version: \e[36m\e[1mNOS version(s), space separated\e[0m\n - view: \e\
310-
[36m\e[1mView all records or just the latest\e[0m\n"
301+
[0m\n - address: \e[36m\e[1mIP Address(es), in quotes, space separated\e[0m\n\
302+
\ - columns: \e[36m\e[1mSpace separated list of columns, * for all\e[0m\n - end_time:\
303+
\ \e[36m\e[1mEnd of time window, try natural language spec \e[0m\n - format: \e\
304+
[36m\e[1mSelect the pformat of the output\e[0m\n - hostname: \e[36m\e[1mHostname(s),\
305+
\ space separated\e[0m\n - model: \e[36m\e[1mFilter by model\e[0m\n - namespace:\
306+
\ \e[36m\e[1mNamespace(s), space separated\e[0m\n - os: \e[36m\e[1mNOS(s), space\
307+
\ separated\e[0m\n - query_str: \e[36m\e[1mTrailing blank terminated pandas query\
308+
\ format to further filter the output\e[0m\n - start_time: \e[36m\e[1mStart of\
309+
\ time window, try natural language spec\e[0m\n - status: \e[36m\e[1mstatus of\
310+
\ service to match\e[0m\n - vendor: \e[36m\e[1mVendor(s), space separated\e[0m\n\
311+
\ - version: \e[36m\e[1mNOS version(s), space separated\e[0m\n - view: \e[36m\e\
312+
[1mView all records or just the latest\e[0m\n"
311313
- command: device help --command=unique
312314
data-directory: tests/data/parquet
313315
format: text
314316
marks: device help command
315317
output: "device unique: \e[36mGet unique values (and counts) associated with requested\
316318
\ field\e[0m\n\e[33m\nUse quotes when providing more than one value\e[0m\n\e[33m\n\
317-
Arguments:\e[0m\n - columns: \e[36m\e[1mSpace separated list of columns, * for\
318-
\ all\e[0m\n - count: \e[36m\e[1minclude count of times a value is seen\e[0m\n\
319-
\ - end_time: \e[36m\e[1mEnd of time window, try natural language spec \e[0m\n\
320-
\ - format: \e[36m\e[1mSelect the pformat of the output\e[0m\n - hostname: \e\
321-
[36m\e[1mHostname(s), space separated\e[0m\n - model: \e[36m\e[1mFilter by model\e\
322-
[0m\n - namespace: \e[36m\e[1mNamespace(s), space separated\e[0m\n - os: \e[36m\e\
323-
[1mNOS(s), space separated\e[0m\n - query_str: \e[36m\e[1mTrailing blank terminated\
324-
\ pandas query format to further filter the output\e[0m\n - start_time: \e[36m\e\
325-
[1mStart of time window, try natural language spec\e[0m\n - status: \e[36m\e[1mstatus\
326-
\ of service to match\e[0m\n - vendor: \e[36m\e[1mVendor(s), space separated\e\
327-
[0m\n - version: \e[36m\e[1mNOS version(s), space separated\e[0m\n - view: \e\
328-
[36m\e[1mView all records or just the latest\e[0m\n"
319+
Arguments:\e[0m\n - address: \e[36m\e[1mIP Address(es), in quotes, space separated\e\
320+
[0m\n - columns: \e[36m\e[1mSpace separated list of columns, * for all\e[0m\n\
321+
\ - count: \e[36m\e[1minclude count of times a value is seen\e[0m\n - end_time:\
322+
\ \e[36m\e[1mEnd of time window, try natural language spec \e[0m\n - format: \e\
323+
[36m\e[1mSelect the pformat of the output\e[0m\n - hostname: \e[36m\e[1mHostname(s),\
324+
\ space separated\e[0m\n - model: \e[36m\e[1mFilter by model\e[0m\n - namespace:\
325+
\ \e[36m\e[1mNamespace(s), space separated\e[0m\n - os: \e[36m\e[1mNOS(s), space\
326+
\ separated\e[0m\n - query_str: \e[36m\e[1mTrailing blank terminated pandas query\
327+
\ format to further filter the output\e[0m\n - start_time: \e[36m\e[1mStart of\
328+
\ time window, try natural language spec\e[0m\n - status: \e[36m\e[1mstatus of\
329+
\ service to match\e[0m\n - vendor: \e[36m\e[1mVendor(s), space separated\e[0m\n\
330+
\ - version: \e[36m\e[1mNOS version(s), space separated\e[0m\n - view: \e[36m\e\
331+
[1mView all records or just the latest\e[0m\n"
329332
- command: device help --command=top
330333
data-directory: tests/data/parquet
331334
format: text
332335
marks: device help command
333336
output: "device top: \e[36mReturn the top n values for a field in a table\e[0m\n\
334337
\e[33m\nUse quotes when providing more than one value\e[0m\n\e[33m\nArguments:\e\
335-
[0m\n - columns: \e[36m\e[1mSpace separated list of columns, * for all\e[0m\n\
336-
\ - count: \e[36m\e[1mnumber of rows to return\e[0m\n - end_time: \e[36m\e[1mEnd\
337-
\ of time window, try natural language spec \e[0m\n - format: \e[36m\e[1mSelect\
338-
\ the pformat of the output\e[0m\n - hostname: \e[36m\e[1mHostname(s), space separated\e\
339-
[0m\n - model: \e[36m\e[1mFilter by model\e[0m\n - namespace: \e[36m\e[1mNamespace(s),\
338+
[0m\n - address: \e[36m\e[1mIP Address(es), in quotes, space separated\e[0m\n\
339+
\ - columns: \e[36m\e[1mSpace separated list of columns, * for all\e[0m\n - count:\
340+
\ \e[36m\e[1mnumber of rows to return\e[0m\n - end_time: \e[36m\e[1mEnd of time\
341+
\ window, try natural language spec \e[0m\n - format: \e[36m\e[1mSelect the pformat\
342+
\ of the output\e[0m\n - hostname: \e[36m\e[1mHostname(s), space separated\e[0m\n\
343+
\ - model: \e[36m\e[1mFilter by model\e[0m\n - namespace: \e[36m\e[1mNamespace(s),\
340344
\ space separated\e[0m\n - os: \e[36m\e[1mNOS(s), space separated\e[0m\n - query_str:\
341345
\ \e[36m\e[1mTrailing blank terminated pandas query format to further filter the\
342346
\ output\e[0m\n - reverse: \e[36m\e[1mreturn bottom n values\e[0m\n - start_time:\

tests/integration/sqcmds/cumulus-samples/device.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,13 @@ tests:
189189
error:
190190
error: '[{"error": "ERROR: Invalid columns specified: [''badcolumn'']"}]'
191191
marks: device unique
192+
- command: device show --format=json --namespace='ospf-single dual-evpn ospf-ibgp'
193+
--address='192.168.121.13 192.168.121.38'
194+
data-directory: tests/data/parquet/
195+
marks: device show
196+
output: '[{"namespace": "dual-evpn", "hostname": "leaf03", "model": "VX", "version":
197+
"3.7.9", "vendor": "Cumulus", "serialNumber": "None", "status": "alive", "address":
198+
"192.168.121.13", "bootupTimestamp": 1616644598.0, "timestamp": 1616644822331},
199+
{"namespace": "dual-evpn", "hostname": "leaf04", "model": "VX", "version": "3.7.9",
200+
"vendor": "Cumulus", "serialNumber": "None", "status": "alive", "address": "192.168.121.38",
201+
"bootupTimestamp": 1616644597.0, "timestamp": 1616644822465}]'

tests/integration/sqcmds/eos-samples/device.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,12 @@ tests:
171171
data-directory: tests/data/parquet/
172172
marks: device show filter eos
173173
output: '[{"version": "4.23.5M"}]'
174+
- command: device show --format=json --namespace=eos --address='10.255.2.118 10.255.2.117'
175+
data-directory: tests/data/parquet/
176+
marks: device show eos
177+
output: '[{"namespace": "eos", "hostname": "spine01", "model": "vEOS", "version":
178+
"4.23.5M", "vendor": "Arista", "serialNumber": "", "status": "alive", "address":
179+
"10.255.2.117", "bootupTimestamp": 1620676825.0, "timestamp": 1623025176945},
180+
{"namespace": "eos", "hostname": "spine02", "model": "vEOS", "version": "4.23.5M",
181+
"vendor": "Arista", "serialNumber": "", "status": "alive", "address": "10.255.2.118",
182+
"bootupTimestamp": 1620676826.0, "timestamp": 1623025177075}]'

tests/integration/sqcmds/junos-samples/device.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,12 @@ tests:
168168
data-directory: tests/data/parquet/
169169
marks: device show filter junos
170170
output: '[{"version": "19.4R1.10"}]'
171+
- command: device show --format=json --namespace=junos --address='10.255.5.118 10.255.5.117'
172+
data-directory: tests/data/parquet/
173+
marks: device show junos
174+
output: '[{"namespace": "junos", "hostname": "spine01", "model": "vqfx-10000", "version":
175+
"19.4R1.10", "vendor": "Juniper", "serialNumber": "38645725387", "status": "alive",
176+
"address": "10.255.5.117", "bootupTimestamp": 1622997977.081, "timestamp": 1623025799081},
177+
{"namespace": "junos", "hostname": "spine02", "model": "vqfx-10000", "version":
178+
"19.4R1.10", "vendor": "Juniper", "serialNumber": "05518142768", "status": "alive",
179+
"address": "10.255.5.118", "bootupTimestamp": 1622998003.357, "timestamp": 1623025799357}]'

tests/integration/sqcmds/nxos-samples/device.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,13 @@ tests:
403403
"model": "Nexus9000 C9300v Chassis", "version": "9.3(4)", "vendor": "Cisco", "serialNumber":
404404
"9AC2MF0S5QO", "status": "alive", "address": "10.255.2.188", "bootupTimestamp":
405405
1619043783.0, "timestamp": 1619275265679}]'
406+
- command: device show --format=json --namespace=nxos --address='10.255.2.119 10.255.2.120'
407+
data-directory: tests/data/parquet/
408+
marks: device show nxos
409+
output: '[{"namespace": "nxos", "hostname": "spine02", "model": "Nexus9000 C9300v
410+
Chassis", "version": "9.3(4)", "vendor": "Cisco", "serialNumber": "9SM7CHR8WEF",
411+
"status": "alive", "address": "10.255.2.120", "bootupTimestamp": 1619013194.0,
412+
"timestamp": 1619275263055}, {"namespace": "nxos", "hostname": "spine01", "model":
413+
"Nexus9000 C9300v Chassis", "version": "9.3(4)", "vendor": "Cisco", "serialNumber":
414+
"9U1GLRQOXD7", "status": "alive", "address": "10.255.2.119", "bootupTimestamp":
415+
1619013190.0, "timestamp": 1619275263589}]'

tests/integration/sqcmds/panos-samples/device.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,12 @@ tests:
9999
error:
100100
error: '[{"error": "ERROR: Invalid columns specified: [''badcolumn'']"}]'
101101
marks: device unique panos
102+
- command: device show --format=json --namespace=panos --address='10.255.2.118 10.255.2.117'
103+
data-directory: tests/data/parquet/
104+
marks: device show panos
105+
output: '[{"namespace": "panos", "hostname": "spine01", "model": "VX", "version":
106+
"4.1.1", "vendor": "Cumulus", "serialNumber": "None", "status": "alive", "address":
107+
"10.255.2.117", "bootupTimestamp": 1639470234.0, "timestamp": 1639476254852},
108+
{"namespace": "panos", "hostname": "spine02", "model": "VX", "version": "4.1.1",
109+
"vendor": "Cumulus", "serialNumber": "None", "status": "alive", "address": "10.255.2.118",
110+
"bootupTimestamp": 1639470234.0, "timestamp": 1639476254852}]'

0 commit comments

Comments
 (0)