Skip to content

Commit c316ab5

Browse files
committed
Make '--instance' and '--snapshot' CLI parameters consistent
* Add '--instance' parameter to most netlab commands * Add 'change to instance directory' processing to the 'load snapshot' function * Allow '--snapshot' parameter only in read-only commands that do not access lab devices Closes #1784
1 parent 232d81c commit c316ab5

28 files changed

+231
-215
lines changed

docs/netlab/capture.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ You cannot capture traffic on point-to-point links between *‌libvirt* virtual
1212
The **netlab capture** command takes two parameters: the node you want to perform packet capture on and the interface name within that node.
1313

1414
```text
15-
$ netlab capture -h
16-
usage: netlab capture [-h] [--snapshot [SNAPSHOT]] node [intf]
15+
usage: netlab capture [-h] [-i INSTANCE] node [intf]
1716
1817
Start a packet capture on the specified node/interface
1918
@@ -23,8 +22,8 @@ positional arguments:
2322
2423
options:
2524
-h, --help show this help message and exit
26-
--snapshot [SNAPSHOT]
27-
Transformed topology snapshot file
25+
-i INSTANCE, --instance INSTANCE
26+
Specify lab instance to capture traffic in
2827
2928
All other arguments are passed directly to the packet-capturing utility
3029
```

docs/netlab/collect.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33

44
**netlab collect** command uses Ansible *device facts* modules (or an equivalent list of Ansible tasks) to collect device configurations and store them in specified output directory.
55

6-
A single configuration file in the output directory is created for most network devices; multiple files stored in host-specific subdirectory are collected from Cumulus VX.
6+
A single configuration file in the output directory is created for most network devices; multiple files are collected from FRR and Cumulus VX.
77

88
After collecting the device configurations, you can save them in a tar archive with the `--tar` option and clean up the working directory with `--cleanup` option.
99

1010
```{tip}
11-
**netlab collect** command does not need a topology file (so you don't have to specify one even if you're using a non-default topology name). It's just a thin wrapper around an Ansible playbook which uses Ansible inventory created by **netlab create** or **netlab up** command.
11+
* **netlab collect** command is just a thin wrapper around an Ansible playbook which uses Ansible inventory created by **netlab create** or **netlab up** command.
12+
* When executed with the `-i` option, **‌netlab collect** switches to the lab directory to execute the Ansible playbook, but stores the results within the directory from which it was executed.
1213
```
1314

1415
## Usage
1516

1617
```text
17-
usage: netlab collect [-h] [-v] [-q] [-o [OUTPUT]] [--tar TAR] [--cleanup]
18+
usage: netlab collect [-h] [-v] [-q] [-o [OUTPUT]] [--tar TAR] [--cleanup] [-i INSTANCE]
1819
1920
Collect device configurations
2021
21-
optional arguments:
22+
options:
2223
-h, --help show this help message and exit
2324
-v, --verbose Verbose logging
2425
-q, --quiet Run Ansible playbook and tar with minimum output
@@ -27,6 +28,8 @@ optional arguments:
2728
--tar TAR Create configuration tarball
2829
--cleanup Clean up config directory and modified configuration file after
2930
creating tarball
31+
-i INSTANCE, --instance INSTANCE
32+
Specify lab instance to collect configuration from
3033
3134
All other arguments are passed directly to ansible-playbook
3235
```

docs/netlab/config.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55

66
You have to use **netlab config** on a running lab. If you want to try out the configuration templates without starting the lab, add the [**config** attribute](custom-config) to node data and run **netlab create** (to create the Ansible inventory) followed by **[netlab initial -c -o](netlab-initial)** to create the configuration files.
77

8-
```
9-
108
## Usage
119

1210
```text
13-
usage: netlab config [-h] [-r] [-v] [-q] template
11+
usage: netlab config [-h] [-r] [-v] [-q] [-i INSTANCE] template
1412
1513
Deploy custom configuration template
1614
1715
positional arguments:
18-
template Configuration template or a directory with templates
16+
template Configuration template or a directory with templates
1917
2018
options:
21-
-h, --help show this help message and exit
22-
-r, --reload Reload saved device configurations
23-
-v, --verbose Verbose logging (add multiple flags for increased verbosity)
24-
-q, --quiet Report only major errors
19+
-h, --help show this help message and exit
20+
-r, --reload Reload saved device configurations
21+
-v, --verbose Verbose logging (add multiple flags for increased verbosity)
22+
-q, --quiet Report only major errors
23+
-i INSTANCE, --instance INSTANCE
24+
Specify lab instance to configure
2525
2626
All other arguments are passed directly to ansible-playbook
2727
```
@@ -34,6 +34,10 @@ When you specify a directory name, the **netlab config** command tries to find t
3434

3535
See [](custom-config), [](netlab-initial-custom) and [](dev-find-custom) for more details.
3636

37+
```{tip}
38+
When executed with the `-i` option, **‌netlab config** expects the configuration template file or directory to be within the lab directory.
39+
```
40+
3741
## Limiting the Scope of Configuration Deployments
3842

3943
All unrecognized parameters are passed to the internal `config.ansible` Ansible playbook. You can use **ansible-playbook** CLI parameters to modify the configuration deployment, for example:
@@ -51,4 +55,4 @@ After that, it treats the saved device configurations as custom templates and us
5155

5256
To display device configurations within the Ansible playbook without deploying them, use `-v --tags test` parameters after the template name.
5357

54-
The `-v` flag will trigger a debugging printout, and the bogus `test` flag will skip the actual configuration deployment.
58+
The `-v` flag triggers a debugging printout, and the bogus `test` flag skips the configuration deployment.

docs/netlab/connect.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
## Usage
77

88
```text
9-
usage: netlab connect [-h] [-v] [-q] [--dry-run] [--snapshot [SNAPSHOT]]
10-
[-s SHOW [SHOW ...]]
11-
host
9+
$ netlab connect -h
10+
usage: netlab connect [-h] [-v] [-q] [--dry-run] [-s SHOW [SHOW ...]] [-i INSTANCE] host
1211
1312
Connect to a network device or an external tool
1413
@@ -17,13 +16,14 @@ positional arguments:
1716
1817
options:
1918
-h, --help show this help message and exit
20-
-v, --verbose Verbose logging
21-
-q, --quiet No logging
22-
--dry-run Print the commands that would be executed, but do not execute them
23-
--snapshot [SNAPSHOT]
24-
Transformed topology snapshot file
19+
-v, --verbose Verbose logging (add multiple flags for increased verbosity)
20+
-q, --quiet Report only major errors
21+
--dry-run Print the commands that would be executed, but do not execute
22+
them
2523
-s SHOW [SHOW ...], --show SHOW [SHOW ...]
2624
Show command to execute on the device
25+
-i INSTANCE, --instance INSTANCE
26+
Specify lab instance to connect to
2727
2828
The rest of the arguments are passed to SSH or docker exec command
2929
```

docs/netlab/down.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@ This command uses the lab topology or the snapshot file created by **netlab up**
88
## Usage
99

1010
```
11-
usage: netlab down [-h] [-v] [--cleanup] [--dry-run] [-i INSTANCE] [--force] [--snapshot [SNAPSHOT]]
11+
$ netlab down -h
12+
usage: netlab down [-h] [-v] [--cleanup] [--dry-run] [--force] [-i INSTANCE]
1213
1314
Destroy the virtual lab
1415
1516
options:
1617
-h, --help show this help message and exit
1718
-v, --verbose Verbose logging (where applicable)
1819
--cleanup Remove all configuration files created by netlab create
19-
--dry-run Print the commands that would be executed, but do not execute them
20+
--dry-run Print the commands that would be executed, but do not execute
21+
them
22+
--force Force shutdown or cleanup (use at your own risk)
2023
-i INSTANCE, --instance INSTANCE
2124
Specify lab instance to shut down
22-
--force Force shutdown or cleanup (use at your own risk)
2325
```
2426

2527
Notes:
2628

2729
* **netlab down** needs transformed topology data to find the virtualization provider and link (bridge) names.
28-
* **netlab down** reads the transformed topology from `netlab.snapshot.yml` file created by **netlab up** or **netlab create**. You can specify a different snapshot file name, but you really should not.
30+
* **netlab down** reads the transformed topology from `netlab.snapshot.yml` file created by **netlab up** or **netlab create**.
2931
* With the `--instance` flag, you can shut down a lab instance running in a different directory. Use the `netlab status --all` command to display all running instances.
3032
* Use the `--cleanup` flag to delete all Ansible-, Vagrant- or containerlab-related configuration files.
3133
* Use the `--force` flag with the `--cleanup` flag if you want to clean up the directory even when the virtualization provider fails during the shutdown process.

docs/netlab/exec.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
## Usage
77

88
```text
9-
usage: netlab exec [-h] [-v] [-q] [--dry-run] [--snapshot [SNAPSHOT]]
10-
node
9+
$ netlab exec -h
10+
usage: netlab exec [-h] [-v] [-q] [--dry-run] [-i INSTANCE] node
1111
12-
Executes a command on one or more network devices
12+
Run a command on one or more network devices
1313
1414
positional arguments:
15-
node Device(s) to execute the command on
15+
node Node(s) to run command on
1616
1717
options:
1818
-h, --help show this help message and exit
19-
-v, --verbose Verbose logging
20-
-q, --quiet No logging
21-
--dry-run Print the commands that would be executed, but do not execute them
22-
--snapshot [SNAPSHOT]
23-
Transformed topology snapshot file
19+
-v, --verbose Verbose logging (add multiple flags for increased verbosity)
20+
-q, --quiet Report only major errors
21+
--dry-run Print the hosts and the commands that would be executed on them,
22+
but do not execute them
23+
-i INSTANCE, --instance INSTANCE
24+
Specify lab instance to execute commands in
2425
2526
The rest of the arguments are passed to SSH or docker exec command
2627
```

docs/netlab/graph.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ You will have to install [Graphviz](https://graphviz.org/download/) or [D2](http
1010
## Usage
1111

1212
```text
13-
usage: netlab graph [-h] [--snapshot [SNAPSHOT]] [-t {topology,bgp}] [-e {graphviz,d2}] [output]
13+
usage: netlab graph [-h] [-t {topology,bgp}] [-e {graphviz,d2}] [-i INSTANCE]
14+
[--snapshot [SNAPSHOT]]
15+
[output]
1416
1517
Create a graph description in Graphviz or D2 format
1618
@@ -19,12 +21,18 @@ positional arguments:
1921
2022
options:
2123
-h, --help show this help message and exit
22-
--snapshot [SNAPSHOT]
23-
Transformed topology snapshot file
2424
-t {topology,bgp}, --type {topology,bgp}
2525
Graph type
2626
-e {graphviz,d2}, --engine {graphviz,d2}
2727
Graphing engine
28+
-i INSTANCE, --instance INSTANCE
29+
Specify lab instance to create a graph from
30+
--snapshot [SNAPSHOT]
31+
Transformed topology snapshot file
32+
```
33+
34+
```{tip}
35+
When executed with the `--instance` option, **‌netlab graph** creates the graph description file in the lab directory.
2836
```
2937

3038
## Examples

docs/netlab/initial.md

+16-8
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,39 @@ Jinja2 templates are used together with **_device_\_config** Ansible modules to
3333
## Usage
3434

3535
```text
36-
usage: netlab initial [--log] [-q] [-v] [-i] [-m [MODULE]] [-c] [--ready] [--fast] [-o [OUTPUT]]
36+
$ netlab initial -h
37+
usage: netlab initial [-h] [--log] [-v] [-q] [-i] [-m [MODULE]] [-c] [--ready] [--fast]
38+
[-o [OUTPUT]] [--instance INSTANCE]
3739
3840
Initial device configurations
3941
40-
optional arguments:
42+
options:
4143
-h, --help show this help message and exit
4244
--log Enable basic logging
45+
-v, --verbose Verbose logging (add multiple flags for increased verbosity)
4346
-q, --quiet Report only major errors
44-
-v, --verbose Verbose logging
4547
-i, --initial Deploy just the initial configuration
4648
-m [MODULE], --module [MODULE]
47-
Deploy module-specific configuration (optionally including a
49+
Deploy module-specific configuration (optionally including a
4850
list of modules separated by commas)
49-
-c, --custom Deploy custom configuration templates (specified in "config"
51+
-c, --custom Deploy custom configuration templates (specified in "config"
5052
group or node attribute)
5153
--ready Wait for devices to become ready
52-
--fast Use "free" strategy in Ansible playbook for faster
53-
configuration deployment
54+
--fast Use "free" strategy in Ansible playbook for faster configuration
55+
deployment
5456
-o [OUTPUT], --output [OUTPUT]
5557
Create a directory with initial configurations instead of
56-
deploying them
58+
deploying them (default output directory: config)
59+
--instance INSTANCE Specify lab instance to configure
5760
5861
All other arguments are passed directly to ansible-playbook
5962
```
6063

64+
```{tip}
65+
* While most **‌netlab** commands accept the `-i` option to specify the lab instance, you have to use the `--instance` option with **‌netlab initial**.
66+
* When executed with the `--instance` option, **‌netlab initial -o** switches to the lab directory to execute the Ansible playbook, but stores the results within the directory from which it was executed.
67+
```
68+
6169
## Wait for Devices to Become Ready
6270

6371
Some devices are not ready immediately after they complete the boot process. For example, Cisco Nexus OS or Juniper vPTX need another minute to realize they have data-plane interfaces.

docs/netlab/inspect.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ When selecting data from an individual node, _netlab_ adds group variables to no
1212
## Usage
1313

1414
```text
15-
usage: netlab inspect [-h] [--snapshot [SNAPSHOT]] [--node NODE]
16-
[--all] [--format {yaml,json}] [expr]
15+
$ netlab inspect -h
16+
usage: netlab inspect [-h] [--node NODE] [--all] [--format {yaml,json}] [-q]
17+
[-i INSTANCE] [--snapshot [SNAPSHOT]]
18+
[expr]
1719
1820
Inspect data structures in transformed lab topology
1921
@@ -22,11 +24,14 @@ positional arguments:
2224
2325
options:
2426
-h, --help show this help message and exit
25-
--snapshot [SNAPSHOT]
26-
Transformed topology snapshot file
2727
--node NODE Display data for selected node(s)
2828
--all Add global Ansible variables to node data
2929
--format {yaml,json} Select data presentation format
30+
-q, --quiet Report only major errors
31+
-i INSTANCE, --instance INSTANCE
32+
Specify lab instance to inspect
33+
--snapshot [SNAPSHOT]
34+
Transformed topology snapshot file
3035
```
3136

3237
## Topology Inspection Examples

docs/netlab/report.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ The **netlab report** command creates a report from the transformed lab topology
66
## Usage
77

88
```text
9-
usage: netlab report [-h] [--snapshot [SNAPSHOT]] [--node NODE] report [output]
9+
$ netlab report -h
10+
usage: netlab report [-h] [--node NODE] [-i INSTANCE] [--snapshot [SNAPSHOT]]
11+
report [output]
1012
1113
Create a report from the transformed lab topology data
1214
@@ -16,9 +18,11 @@ positional arguments:
1618
1719
options:
1820
-h, --help show this help message and exit
21+
--node NODE Limit the report to selected node(s)
22+
-i INSTANCE, --instance INSTANCE
23+
Specify lab instance to report on
1924
--snapshot [SNAPSHOT]
2025
Transformed topology snapshot file
21-
--node NODE Limit the report to selected node(s)
2226
```
2327

2428
```{tip}

docs/netlab/restart.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
**netlab restart** executes **[netlab down](down.md)** followed by **[netlab up](up.md)** to restart your lab from the transformed lab topology stored in `netlab.snapshot.yml` snapshot file.
44

5-
You can use **netlab restart** to restart the existing lab (use `--snapshot` keyword), or to recreate the lab configuration files in case you changed the lab topology.
5+
You can use **netlab restart** to restart the existing lab (use `--snapshot` keyword) or recreate the lab configuration files if you changed the lab topology.
66

77
```{warning}
8-
**netlab restart** does not support `-d`, `-p` or `-s` flags used by **netlab create** or **netlab up**. If you want to change lab topology settings with CLI parameters use **netlab down** and **netlab up** commands.
8+
* **netlab restart** does not support `-d`, `-p` or `-s` flags used by **netlab create** or **netlab up**. If you want to change lab topology settings with CLI parameters, use **netlab down** and **netlab up** commands.
9+
* You must execute the **‌netlab restart** command within the lab directory.
910
```
1011

1112
## Usage
1213

1314
```text
14-
usage: netlab [-h] [--log] [-q] [-v] [--no-config] [--fast-config]
15+
$ netlab restart -h
16+
usage: netlab [-h] [--log] [-v] [-q] [--no-config] [--fast-config]
1517
[--snapshot [SNAPSHOT]]
1618
[topology]
1719
@@ -20,14 +22,13 @@ Reconfigure and restart the virtual lab
2022
positional arguments:
2123
topology Topology file (default: topology.yml)
2224
23-
optional arguments:
25+
options:
2426
-h, --help show this help message and exit
2527
--log Enable basic logging
26-
-q, --quiet Report only major errors
2728
-v, --verbose Verbose logging (add multiple flags for increased verbosity)
29+
-q, --quiet Report only major errors
2830
--no-config Do not configure lab devices
2931
--fast-config Use fast device configuration (Ansible strategy = free)
3032
--snapshot [SNAPSHOT]
31-
Use netlab snapshot file created by a previous lab run
32-
to start the lab
33+
Transformed topology snapshot file
3334
```

docs/netlab/status.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ This command uses the *netlab* status file (default: `~/.netlab/status.yml`) to
99

1010
```
1111
$ netlab status -h
12-
usage: netlab status [-h] [-i INSTANCE] [-l] [--cleanup] [--reset] [--all] [-v] [-q]
12+
usage: netlab status [-h] [-l] [--cleanup] [--reset] [--all] [-v] [-q] [-i INSTANCE]
1313
1414
Display lab status
1515
1616
options:
1717
-h, --help show this help message and exit
18-
-i INSTANCE, --instance INSTANCE
19-
Display or cleanup specific lab instance(s)
2018
-l, --log Display the lab instance event log
2119
--cleanup Cleanup the current or specified lab instance
2220
--reset Reset the lab instance tracking system
2321
--all Display an overview of all lab instance(s)
2422
-v, --verbose Verbose logging (add multiple flags for increased verbosity)
2523
-q, --quiet Report only major errors
24+
-i INSTANCE, --instance INSTANCE
25+
Specify lab instance to inspect
2626
```
2727

2828
* **netlab status** displays the status and workload (VMs or containers) of the current or selected lab instance.

0 commit comments

Comments
 (0)