Skip to content

Commit

Permalink
Implement 'configuration module overview' netlab show command
Browse files Browse the repository at this point in the history
Also: implement 'table', 'text' or 'yaml' show command output format
  • Loading branch information
ipspace committed Jul 3, 2023
1 parent cc51208 commit 5ea5597
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 27 deletions.
53 changes: 51 additions & 2 deletions docs/netlab/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@

* **devices** -- Valid device types
* **images** -- Vagrant box names or container names for all supported devices or a single device
* **module** -- Configuration modules
* **module-support** -- Configuration modules support matrix

## Usage

```
usage: netlab show [-h] [-d DEVICE] [--system] {images,devices,module-support}
usage: netlab show [-h] [-d DEVICE] [--system] [--format {table,text,yaml}]
{images,devices,module-support,modules}
Display default settings
positional arguments:
{images,devices,module-support}
{images,devices,module-support,modules}
Select the system information to display
options:
-h, --help show this help message and exit
-d DEVICE, --device DEVICE
Display information for a single device
--system Display system information (without user defaults)
--format {table,text,yaml}
Output format (table, text, yaml)
```

## Examples
Expand Down Expand Up @@ -70,6 +74,51 @@ eos image names by virtualization provider
+--------+-------------+-------------+--------------+
```

Configuration modules overview:

```
$ netlab show modules
netlab Configuration modules and supported devices
===========================================================================
bfd:
srlinux, sros, iosv, csr, nxos, eos, vyos, arubacx
bgp:
cumulus, cumulus_nvue, eos, frr, csr, iosv, nxos, asav, vsrx, vyos,
routeros, srlinux, sros, dellos10, routeros7, vmx, iosxr, arubacx,
vptx
eigrp:
csr, iosv, nxos
evpn:
sros, srlinux, frr, eos, vyos, dellos10, cumulus, nxos, arubacx,
vptx
gateway:
eos, cumulus, iosv, csr, nxos, sros, srlinux, vyos, dellos10,
arubacx
isis:
eos, frr, csr, iosv, nxos, asav, vsrx, srlinux, sros, vyos, vmx,
iosxr, vptx
mpls:
eos, iosv, csr, routeros, vyos, routeros7, sros, vmx, vsrx, frr,
vptx, arubacx
ospf:
arcos, cumulus, cumulus_nvue, eos, fortios, frr, csr, iosv, nxos,
vsrx, vyos, routeros, srlinux, sros, dellos10, routeros7, vmx,
iosxr, arubacx, vptx
sr:
csr, eos, srlinux, sros, vsrx, vmx, vptx
srv6:
sros
vlan:
eos, iosv, csr, vyos, dellos10, srlinux, routeros, nxos, frr,
cumulus, sros, routeros7, vmx, vsrx, arubacx, vptx
vrf:
eos, iosv, csr, routeros, dellos10, vyos, cumulus_nvue, nxos,
srlinux, frr, cumulus, sros, routeros7, vmx, vsrx, arubacx, vptx
vxlan:
eos, nxos, vyos, csr, dellos10, srlinux, frr, cumulus, sros,
arubacx, vptx
```

Configuration modules available for Arista EOS:

```
Expand Down
110 changes: 85 additions & 25 deletions netsim/cli/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#
import typing
import argparse
import os
import glob
import textwrap
from box import Box

from .. import common
from .. import read_topology
from .. import data

DEVICES_TO_SKIP = ['none','unknown']

def print_table(
heading: typing.List[str],
Expand Down Expand Up @@ -47,68 +49,118 @@ def print_row(separator: str, row: typing.Optional[list] = None, char: str = ' '

def show_images(settings: Box, args: argparse.Namespace) -> None:
heading = ['device']
heading.extend(settings.providers.keys())
heading.extend([ p for p in settings.providers.keys() if p != 'external'])

rows = []
result = data.get_empty_box()
for device in sorted(settings.devices.keys()):
if device == 'none':
if device in DEVICES_TO_SKIP:
continue

if args.device and device != args.device:
if device != args.device and args.device != '*':
continue

row = [ device ]
for p in heading[1:]:
row.append(settings.devices[device][p].get("image",""))
p_image = settings.devices[device][p].get("image","")
row.append(p_image)
if p_image:
result[device][p] = p_image

rows.append(row)

print((args.device or "Device") + " image names by virtualization provider")
print("")
print_table(heading,rows)
if args.format == 'table':
print((args.device or "Device") + " image names by virtualization provider")
print("")
print_table(heading,rows)
elif args.format in ['text','yaml']:
print(common.get_yaml_string(result))

def show_devices(settings: Box, args: argparse.Namespace) -> None:
heading = ['device','description']

rows = []
result = data.get_empty_box()
for device in sorted(settings.devices.keys()):
dev_data = settings.devices[device]
if device == 'none' or not 'description' in dev_data:
if device in DEVICES_TO_SKIP:
continue

if device != args.device and args.device != '*':
continue

row = [ device,dev_data.description ]
rows.append(row)
result[device] = dev_data.description

print('Virtual network devices supported by netlab')
print("")
print_table(heading,rows,inter_row_line=False)
if args.format == 'table':
print('Virtual network devices supported by netlab')
print("")
print_table(heading,rows,inter_row_line=False)
elif args.format in ['text','yaml']:
print(common.get_yaml_string(result))

def show_module_support(settings: Box, args: argparse.Namespace) -> None:
heading = ['device']
mod_list = sorted([ m for m in settings.keys() if 'supported_on' in settings[m]])
heading.extend(mod_list)

rows = []
result = data.get_empty_box()
for device in sorted(settings.devices.keys()):
if device == 'none':
if device in DEVICES_TO_SKIP:
continue

if args.device and device != args.device:
if device != args.device and args.device != '*':
continue

row = [ device ]
for m in heading[1:]:
value = "x".center(len(m)) if device in settings[m].supported_on else ""
row.append(value)
rows.append(row)

print("Configuration modules supported by " + (args.device or "individual devices"))
print("")
print_table(heading,rows)
if args.format == 'table':
row = [ device ]
for m in heading[1:]:
value = "x".center(len(m)) if device in settings[m].supported_on else ""
row.append(value)
rows.append(row)
else:
dev_mods = [ m for m in mod_list if device in settings[m].supported_on ]
result[device] = dev_mods
if args.format == 'text':
print(f'{device}: {",".join(dev_mods)}')

if args.format == 'table':
print("Configuration modules supported by " + (args.device or "individual devices"))
print("")
print_table(heading,rows)
elif args.format == 'yaml':
print(common.get_yaml_string(result))

def show_modules(settings: Box, args: argparse.Namespace) -> None:
mod_list = sorted([ m for m in settings.keys() if 'supported_on' in settings[m]])
result = data.get_empty_box()

if args.format == 'table':
print("netlab Configuration modules and supported devices")
print("=" * 75)

for m in mod_list:
dev_list = [ d for d in settings[m].supported_on if not d in DEVICES_TO_SKIP ]
if args.format == 'text':
print(f'{m}: {",".join(dev_list)}')
elif args.format == 'table':
print(f'{m}:')
print(textwrap.TextWrapper(
initial_indent=" ",
subsequent_indent=" ").fill(", ".join(dev_list)))
else:
result[m] = settings[m].dev_list

if args.format == 'yaml':
print(common.get_yaml_string(result))

show_dispatch = {
'images': show_images,
'devices': show_devices,
'module-support': show_module_support
'module-support': show_module_support,
'modules': show_modules
}

#
Expand All @@ -123,12 +175,20 @@ def show_parse(args: typing.List[str]) -> argparse.Namespace:
'-d','--device',
dest='device',
action='store',
default='*',
help='Display information for a single device')
parser.add_argument(
'--system',
dest='system',
action='store_true',
help='Display system information (without user defaults)')
parser.add_argument(
'--format',
dest='format',
action='store',
choices=['table','text','yaml'],
default='table',
help='Output format (table, text, yaml)')
parser.add_argument(
dest='action',
action='store',
Expand Down

0 comments on commit 5ea5597

Please sign in to comment.