Skip to content

Commit 7d665cd

Browse files
committed
Use pickled data as snapshot file
* Add 'pickle' output module and use it as one of default outputs * Refactor output file selection into 'select_output_file'. This function can be used by all output modules (future improvement) * Add 'load_pickled_data' to 'utils.read' * Read pickled or YAML data in 'load_snapshot' function Minor changes: * Change the default value of the 'args.snapshot' parameter * Change the parser default value of '--snapshot' parameter * Change the help message in 'netlab create' command * Add 'snapshot' argument to 'netlab down' to be able to shut down a lab from the YAML snapshot file * Add 'netlab.snapshot.pickle' as another file to clean up when the lab is shut down * Fix exception reporting to use 'str(ex)' (just to be on the safe side) Off-topic: * Create a large topology in platform-integration tests to test the performance improvements Finally: * Updated the documentation to refer to the pickle snapshot file Implements #2635
1 parent 85cf9d6 commit 7d665cd

File tree

21 files changed

+170
-27
lines changed

21 files changed

+170
-27
lines changed

docs/dev/config/deploy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ The filename search patterns can use Jinja2 expressions that rely on [Ansible va
193193
| `package:` | **networklab** package (system file) |
194194
| `topology:` | Directory containing the current lab topology |
195195

196-
The directory search patterns are evaluated during the [data transformation process](../transform.md), and the absolute paths are stored in the Ansible inventory (in the **all** group) and the `netlab.snapshot.yml` file. You can use the **netlab inspect defaults.paths** command to display the transformed values (**netlab inspect** command is available after starting the lab or executing the **netlab create** command).
196+
The directory search patterns are evaluated during the [data transformation process](../transform.md), and the absolute paths are stored in the Ansible inventory (in the **all** group) and the `netlab.snapshot.pickle` file. You can use the **netlab inspect defaults.paths** command to display the transformed values (**netlab inspect** command is available after starting the lab or executing the **netlab create** command).
197197

198198
For example, the default custom configuration template directory search path (**defaults.paths.custom.dirs**) contains these entries:
199199

@@ -206,7 +206,7 @@ custom: # Custom configuration templates
206206
- "package:extra"
207207
```
208208

209-
The evaluated search path that is stored in `netlab.snapshot.yml` might contain these values (the topology directory is equal to the current directory, **netlab** is executed from local Git directory):
209+
The evaluated search path that is stored in `netlab.snapshot.pickle` might contain these values (the topology directory is equal to the current directory, **netlab** is executed from local Git directory):
210210

211211
```
212212
$ netlab inspect defaults.paths.custom.dirs

docs/netlab/connect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The rest of the arguments are passed to SSH or docker exec command
3535

3636
## Collecting Device Data
3737

38-
**netlab connect** uses the lab snapshot file (default: `netlab.snapshot.yml`) to read device- and node information. You can overwrite the default snapshot file with the `--snapshot` command line parameter.
38+
**netlab connect** uses the lab snapshot file (default: `netlab.snapshot.pickle`) to read device- and node information. You can overwrite the default snapshot file with the `--snapshot` command line parameter.
3939

4040
**netlab connect** command uses the following device data. Most of that data is derived from the device **group_vars**, although you can override it on [node-](node-ansible-data) or [custom group](groups-object-data) level; use the **[`netlab inspect --node _name_`](inspect.md)** command to inspect it.
4141

docs/netlab/create.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ You can influence the data model transformation with optional [configuration mod
2222

2323
**netlab create** uses transformed node- and link-level data structures to create:
2424

25-
* Snapshot of the transformed topology in the **netlab.snapshot.yml** file. This file is used by **netlab down** command to find the virtualization provider and link (bridge) names.
25+
* Pickled transformed topology data in the **netlab.snapshot.pickle** file. This file is used by many other **netlab** commands to get the information about the currently running lab topology.
26+
* Snapshot of the transformed topology in the **netlab.snapshot.yml** file. You can use this file to get the information about the current lab topology in your own scripts.
2627
* **Vagrantfile** supporting *[libvirt](lab-libvirt)* environment
2728
* **clab.yml** file used by *containerlab*.
2829
* Ansible inventory[^1], either as a single-file data structure, or as a minimal inventory file with data stored primarily in **host_vars** and **group_vars**
2930
* Various graphs in *graphviz* DOT format
3031
* YAML or JSON representation of transformed lab topology or parts of the transformed data model
31-
* Configuration file for *graphite* visualization tool
32+
* Configuration files for [external tools](extools.md)
3233

3334
```{warning}
34-
**‌netlab create** command refuses to create provider configuration files, Ansible inventory, or `netlab.snapshot.yml` file if it finds `netlab.lock` file in the current directory.
35+
**‌netlab create** command refuses to create provider configuration files, Ansible inventory, or `netlab.snapshot.pickle` file if it finds `netlab.lock` file in the current directory.
3536
3637
`netlab.lock` file is created by the **‌netlab up** command to ensure subsequent **‌netlab create** commands don't overwrite the provider configuration files. It is automatically removed after a successful completion of **‌netlab down** command.
3738
```
@@ -71,6 +72,7 @@ optional arguments:
7172
7273
output files created when no output is specified:
7374
75+
* Pickled transformed data in netlab.snapshot.pickle
7476
* Transformed topology snapshot in netlab.snapshot.yml
7577
* Virtualization provider file with provider-specific filename
7678
(Vagrantfile or clab.yml)

docs/netlab/down.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ options:
2727
Notes:
2828

2929
* **netlab down** needs transformed topology data to find the virtualization provider and link (bridge) names.
30-
* **netlab down** reads the transformed topology from `netlab.snapshot.yml` file created by **netlab up** or **netlab create**.
30+
* **netlab down** reads the transformed topology from `netlab.snapshot.pickle` file created by **netlab up** or **netlab create**.
3131
* 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.
3232
* Use the `--cleanup` flag to delete all Ansible-, Vagrant- or containerlab-related configuration files.
3333
* 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/graph.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(netlab-graph)=
22
# Creating Physical or BGP Topology Graphs
33

4-
**netlab graph** command creates a graph description in [Graphviz](https://graphviz.org/) or [D2](https://d2lang.com/) format from the transformed lab topology data (usually stored in `netlab.snapshot.yml`) created by **netlab create** command. It's replicating the functionality of **netlab create -o graph:_name_** command with a more convenient user interface.
4+
**netlab graph** command creates a graph description in [Graphviz](https://graphviz.org/) or [D2](https://d2lang.com/) format from the transformed lab topology data (usually stored in `netlab.snapshot.pickle`) created by **netlab create** command. It's replicating the functionality of **netlab create -o graph:_name_** command with a more convenient user interface.
55

66
```{note}
77
You will have to install [Graphviz](https://graphviz.org/download/) or [D2](https://d2lang.com/tour/install) and use them to create the actual graphs in PNG/JPEG/PDF format.

docs/netlab/initial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Jinja2 templates are used together with **_device_\_config** Ansible modules to
2626
[^init]: For example, Juniper vMX requires an evaluation license to be applied after the device boots.
2727

2828
```{tip}
29-
* The **netlab initial** command reads the transformed lab data from the `netlab.snapshot.yml` file created by the **netlab up** command.
29+
* The **netlab initial** command reads the transformed lab data from the `netlab.snapshot.pickle` file created by the **netlab up** command.
3030
* When run with the **-v** parameter, the command displays device configurations before deploying them.
3131
```
3232

docs/netlab/inspect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(netlab-inspect)=
22
# Inspect Data Structures in Transformed Lab Topology
33

4-
**netlab inspect** prints data structures in transformed lab topology (usually stored in `netlab.snapshot.yml`) created by the **netlab create** command. You can display data in YAML or JSON format and select a subset of data from the transformed topology or an individual node.
4+
**netlab inspect** prints data structures in transformed lab topology (usually stored in `netlab.snapshot.pickle`) created by the **netlab create** command. You can display data in YAML or JSON format and select a subset of data from the transformed topology or an individual node.
55

66
When selecting data from an individual node, _netlab_ adds group variables to node data, effectively displaying what you would see in the Ansible inventory.
77

docs/netlab/report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(netlab-report)=
22
# Creating a Report
33

4-
The **netlab report** command creates a report from the transformed lab topology data (usually stored in `netlab.snapshot.yml`) created by the **netlab create** command. It replicates the functionality of the **netlab create -o report:_name_** command with a more convenient user interface.
4+
The **netlab report** command creates a report from the transformed lab topology data (usually stored in `netlab.snapshot.pickle`) created by the **netlab create** or **netlab up** command. It replicates the functionality of the **netlab create -o report:*name*** command with a more convenient user interface.
55

66
## Usage
77

docs/netlab/restart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Restart Virtual Lab
22

3-
**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.
3+
**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.pickle` snapshot file.
44

55
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

docs/netlab/status.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ The **netlab status cleanup _instance_** command shuts down the specified lab in
115115
$ netlab status --cleanup
116116
Cleanup will remove lab instance "default" in /home/user/net101/tools/X. Are you sure? [y/n]y
117117
Shutting down lab default in /home/user/net101/tools/X
118-
Read transformed lab topology from snapshot file netlab.snapshot.yml
118+
Read transformed lab topology from snapshot file netlab.snapshot.pickle
119119
120120
┌──────────────────────────────────────────────────────────────────────────────────┐
121121
│ CHECKING virtualization provider installation │
@@ -147,4 +147,5 @@ INFO[0001] Removing containerlab host entries from /etc/hosts file
147147
... removing directory tree group_vars
148148
... removing directory tree host_vars
149149
... removing netlab.snapshot.yml
150+
... removing netlab.snapshot.pickle
150151
```

0 commit comments

Comments
 (0)