Skip to content

Commit 0a59b32

Browse files
authored
New report: names of selected nodes (to be used in bash scripts) (#2420)
This is a minimally-intrusive solution for #2418: * "netlab report nodes --node glob" prints out the names of the selected nodes * The names of the selected nodes can be used in a bash script (see documentation for an example) Closes #2418
1 parent 1bcee07 commit 0a59b32

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

docs/netlab/connect.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ The rest of the arguments are passed to SSH or docker exec command
2929
```
3030

3131
```{tip}
32-
The [**‌--show** option](netlab-connect-show) must be used _after_ the host parameter, as the **‌--show** option consumes all arguments specified after it.
32+
* The [**‌--show** option](netlab-connect-show) must be used _after_ the host parameter, as the **‌--show** option consumes all arguments specified after it.
33+
* **‌netlab connect** connects to a single node. Use a bash script described in the [**netlab report** examples](netlab-report-examples) if you want to use a single command to connect to multiple nodes in a multi-window environment.
3334
```
3435

3536
## Collecting Device Data
@@ -59,6 +60,10 @@ Command line parameters specified after the device name are passed to the **ssh*
5960

6061
If you want to process the results of the command executed on a lab device, use **netlab connect -q** to remove the "_we are going to connect to device X_" message.
6162

63+
```{tip}
64+
Use [**‌netlab exec**](netlab-exec) if you want to execute the same command on multiple devices
65+
```
66+
6267
(netlab-connect-show)=
6368
## Executing a Show Command
6469

docs/netlab/report.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,25 @@ options:
2929
The **[netlab show reports](netlab-show-reports)** command displays up-to-date list of available system reports
3030
```
3131

32+
(netlab-report-examples)=
3233
## Examples
3334

34-
* `netlab report addressing` creates lab addressing report in text format on standard output (printed to the screen)
35+
* `netlab report addressing` creates the lab addressing report in text format on standard output (printed to the screen)
3536
* `netlab report addressing.html x.html` creates an HTML addressing report (**addressing.html**) and stores it into `x.html`.
3637
* `netlab report bgp-neighbor.md` creates the table of BGP neighbors in Markdown format
3738
* `netlab report bgp-neighbor.ascii` creates the Markdown BGP neighbors report and renders it as ASCII text using the [rich.markdown](https://rich.readthedocs.io/en/stable/markdown.html) library.
3839
* `netlab report addressing --node r1,r2` creates addressing report for R1 and R2.
40+
* `netlab report nodes` lists the space-separated node names (you can use the `--node` argument to select a subset of nodes) in a format that can be used in a **bash** script. For example, the following script (when started within a **screen** session) connects to all specified devices in separate **screen** windows[^BM]:
41+
42+
```
43+
#!/bin/bash
44+
for n in $(netlab report --node "${1:-*}" nodes); do
45+
echo "Connecting to $n"
46+
screen -t "$n" netlab connect $n &
47+
done
48+
```
49+
50+
[^BM]: The **bash** magic used for the `--node` parameter uses the value of the first script parameter or '*' if the script has no parameters. The double quotes around that magic prevent **bash** filename expansion.
3951

4052
```{tip}
4153
[**netlab inspect** documentation](netlab-inspect-node) describes how to specify the nodes on which the command will be executed.

netsim/reports/nodes.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{# description: List of selected (or all) nodes in the lab topology #}
2+
{{ nodes.keys()|join(" ") -}}

0 commit comments

Comments
 (0)