Skip to content

Commit

Permalink
Implement 'netlab show module --feature' argument (#1613)
Browse files Browse the repository at this point in the history
Closes #1577
  • Loading branch information
ipspace authored Dec 5, 2024
1 parent b06ac87 commit af1ab99
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
41 changes: 39 additions & 2 deletions docs/netlab/show.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ The **netlab show modules** command displays available configuration modules and
```text
usage: netlab show modules [-h] [--system] [--format {table,text,yaml}] [-m MODULE]
[--feature FEATURE]

Display supported configuration modules

Expand All @@ -332,8 +333,8 @@ options:
--system Display system information (without user defaults)
--format {table,text,yaml}
Output format (table, text, yaml)
-m MODULE, --module MODULE
Display information for a single module
-m, --module MODULE Display information for a single module
--feature FEATURE Display information for a single feature of the selected module
```

**Examples:**
Expand Down Expand Up @@ -480,6 +481,42 @@ vyos:
irb: true
```
* Display devices supporting EVPN asymmetrical IRB:
```text
$ netlab show modules -m evpn --feature asymmetrical_irb
Devices supported by the evpn module and their support for the asymmetrical_irb feature

┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃ device ┃ asymmetrical_irb ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ arubacx │ x │
├──────────┼──────────────────┤
│ cumulus │ x │
├──────────┼──────────────────┤
│ dellos10 │ x │
├──────────┼──────────────────┤
│ eos │ x │
├──────────┼──────────────────┤
│ frr │ x │
├──────────┼──────────────────┤
│ nxos │ │
├──────────┼──────────────────┤
│ srlinux │ x │
├──────────┼──────────────────┤
│ sros │ x │
├──────────┼──────────────────┤
│ vyos │ x │
└──────────┴──────────────────┘

Notes:
* All devices listed in the table support evpn configuration module.
* Some devices might not support any module-specific additional feature

Feature legend:
* asymmetrical_irb: Support asymmetrical IRB (routing on ingress, bridging on egress)
```

* When using the `initial` pseudo-module, the command displays device support for various initial configuration features:

```text
Expand Down
4 changes: 4 additions & 0 deletions netsim/cli/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
'exec': _mod_support.show,
'parse': _mod_support.parse
},
'module': {
'exec': _modules.show,
'parse': _modules.parse
},
'modules': {
'exec': _modules.show,
'parse': _modules.parse
Expand Down
33 changes: 32 additions & 1 deletion netsim/cli/show_commands/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@

from ...utils import strings
from ... import data
from .. import error_and_exit
from . import show_common_parser,parser_add_module,DEVICES_TO_SKIP,get_modlist

def parse() -> argparse.ArgumentParser:
parser = show_common_parser('modules','supported configuration modules')
parser_add_module(parser)
parser.add_argument(
'--feature',
dest='feature',
action='store',
help='Display information for a single feature of the selected module')
return parser

def get_feature_list(features: Box,prefix: str = '') -> list:
Expand Down Expand Up @@ -79,10 +85,27 @@ def show(settings: Box, args: argparse.Namespace) -> None:
mod_list = get_modlist(settings,args)

result = data.get_empty_box()

if args.feature:
if not args.module:
error_and_exit('The --feature parameter is only valid with the --module parameter')
if args.feature not in settings[args.module].features:
error_and_exit(
f'Module {args.module} does not have feature {args.feature}',
more_hints=f'Use "netlab show defaults {args.module}.features" to display valid device features')

# Remove all other features from the module feature list to display just the selected feature
#
f = settings[args.module].features[args.feature]
settings[args.module].features = { args.feature: f }

if args.format == 'table':
if args.module:
if settings[args.module].features:
print(f"Devices and features supported by {args.module} module")
if args.feature:
print(f"Devices supported by the {args.module} module and their support for the {args.feature} feature")
else:
print(f"Devices and features supported by {args.module} module")
else:
print(f"Devices supported by {args.module} module")
print("")
Expand All @@ -109,6 +132,14 @@ def show(settings: Box, args: argparse.Namespace) -> None:
if args.module and settings[args.module].features:
for d in dev_list:
result[d] = settings.devices[d].features[m]

# Remove all non-relevant features from device results
#
if args.feature:
if args.feature in result[d]:
result[d] = { args.feature: result[d][args.feature] }
else:
result[d] = {}
else:
result[m] = settings[m].dev_list

Expand Down

0 comments on commit af1ab99

Please sign in to comment.