You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use 'files' plugin to implement inline configuration templates (#2580)
This change adds support for inline custom configuration templates in
node-, group- and validation test definitions. It allows the user to
specify small additions to device configurations directly in the node-
or group definition, or to define small changes to device configurations
directly in the validation tests.
Copy file name to clipboardExpand all lines: docs/custom-config-templates.md
+7-1Lines changed: 7 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
(custom-config)=
2
2
# Custom Configuration Templates
3
3
4
-
You can build complex labs with functionality that is [not yet part of *netlab*](netlab-customize) with the custom configuration templates that can be deployed with **[netlab config](netlab-config)**, **[netlab initial](netlab-initial)** or **[netlab up](netlab-up)** commands. The custom configuration templates could be stored in the lab topology directory, the user's defaults directory, or within the _netlab_ package. See [](dev-find-custom) for more details.
4
+
You can build complex labs with functionality that is [not yet part of *netlab*](netlab-customize) with the custom configuration templates that can be deployed with **[netlab config](netlab-config)**, **[netlab initial](netlab-initial)**, or **[netlab up](netlab-up)** commands. The custom configuration templates could be stored in the lab topology directory, the user's defaults directory, or within the _netlab_ package. See [](dev-find-custom) for more details. You can also use the **[files](plugin-files)** plugin to [store the configuration templates in the lab topology](plugin-files-configlets).
5
5
6
6
For a one-off deployment of custom configuration templates, use the **netlab config** command. To make the deployment of custom configuration template(s) part of a regular lab initialization process[^CC], use **config** group- or node attribute that can specify either a single template or a list of templates.
7
7
@@ -53,6 +53,8 @@ Node **config** attributes are merged with the group **config** attributes. [
53
53
_netlab_ sorts custom configuration templates in the order specified in groups and nodes to speed up their deployment. Specifying `custom: [ a,b ]` on one node and `custom: [ b,a ]` on another will result in a sorting loop and a fatal error.
54
54
```
55
55
56
+
Finally, the **files** plugin [allows you to use **config.inline** node— or group parameter](plugin-files-node-config) and store the configuration changes directly in the lab topology.
57
+
56
58
(custom-config-groups)=
57
59
## Custom Configuration Templates in Hierarchical Groups
58
60
@@ -125,6 +127,10 @@ The following configuration templates would be applied to individual nodes in th
125
127
| e | g2a, g2b (from g2 via g3), g3 (from g3), -g1 is ignored, e (from e) |
126
128
| f | none (it's not a member of any group) |
127
129
130
+
```{tip}
131
+
With the **files** plugin, you can use the [**config.inline** group parameter](plugin-files-node-config) to apply a configuration change to a group of lab devices.
Copy file name to clipboardExpand all lines: docs/plugins/files.md
+89-2Lines changed: 89 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,15 @@ The plugin defines two new topology attributes:
8
8
***files** -- a dictionary or list of extra files to create in the lab directory
9
9
***configlets** -- a dictionary of custom configuration templates
10
10
11
+
It also extends the meaning of the node/group **config** attribute and adds the **config.inline** attribute to validation tests.
12
+
13
+
```eval_rst
14
+
.. contents:: Table of Contents
15
+
:depth: 2
16
+
:local:
17
+
:backlinks: none
18
+
```
19
+
11
20
(plugin-files-create)=
12
21
## Creating Extra Files
13
22
@@ -52,6 +61,7 @@ The files specified in the **files** attribute are created just before the outpu
52
61
* The files specified in the **files** list will be removed during the `netlab down --cleanup` process, even when they existed before the `netlab up` was executed.
53
62
```
54
63
64
+
(plugin-files-configlets)=
55
65
## Creating Custom Configuration Templates
56
66
57
67
The **configlets** dictionary can be used to create custom configuration templates. Its contents are automatically converted to [elements of the **files** list](plugin-files-create), but provide a more intuitive way of specifying the templates.
@@ -60,8 +70,14 @@ For example, the following **configlets** dictionary creates **ifup.j2** and **i
60
70
61
71
```
62
72
configlets:
63
-
ifup: ip link set eth1 up
64
-
ifdown: ip link set eth1 down
73
+
ifup: |
74
+
ip link set eth1 up
75
+
ifdown: |
76
+
ip link set eth1 down
77
+
```
78
+
79
+
```{tip}
80
+
Always use the YAML *literal block scalar header* (`|`) for the configlet content; otherwise, the whole content will be folded into a single line.
65
81
```
66
82
67
83
You can use a more structured **configlets** dictionary to create custom configuration templates for multiple nodes, devices, or providers. For example, the following dictionary creates **ifup/eos.j2** and **ifup/frr.j2** files that can then be used as `ifup` custom configuration templates on Arista EOS or FRR:
@@ -110,3 +126,74 @@ configlets:
110
126
interface Management1
111
127
description Management interface
112
128
```
129
+
130
+
(plugin-files-node-config)=
131
+
## Inline Node/Group Configuration Templates
132
+
133
+
The **files** plugin allows you to specify the contents of custom configuration templates directly in the node- or group **config** attribute.
134
+
135
+
If you enabled the **files** plugin, and the content of the **config** attribute is a dictionary, the **files** plugin copies the dictionary into the **configlets** dictionary and replaces it with a list of custom configuration templates (the dictionary keys).
136
+
137
+
If you don't care about the configuration template names, use the **config.inline** template. **files** plugin will auto-generate a template name and use it to apply extra configuration to the node (or group of nodes) where the **config.inline** template is defined.
138
+
139
+
For example, the following lab topology creates a template `_n_x1.j2` that is then used to add a route map and extra BGP configuration to X1:
140
+
141
+
```
142
+
plugin: [ files ]
143
+
module: [ bgp ]
144
+
145
+
nodes:
146
+
dut:
147
+
bgp.as: 65000
148
+
149
+
x1:
150
+
id: 10
151
+
bgp.as: 65010
152
+
bgp.originate: 172.0.42.0/24
153
+
config.inline: |
154
+
route-map setcomm permit 10
155
+
set community 65000:1 additive
156
+
set extcommunity bandwidth 100
157
+
set large-community 65000:0:1 additive
158
+
exit
159
+
!
160
+
router bgp {{ bgp.as }}
161
+
!
162
+
address-family ipv4 unicast
163
+
{% for n in bgp.neighbors %}
164
+
neighbor {{ n.ipv4 }} route-map setcomm out
165
+
{% endfor %}
166
+
167
+
x2:
168
+
id: 11
169
+
bgp.as: 65011
170
+
```
171
+
172
+
```{tip}
173
+
Always use the YAML *literal block scalar header* (`|`) for the custom configuration content; otherwise, the whole content will be folded into a single line.
174
+
```
175
+
176
+
(plugin-files-validation-config)=
177
+
## Inline Configuration Changes in Validation Tests
178
+
179
+
Once the **files** plugin is activated, the validation tests can use the **config.inline** attribute to specify the changes that should be made to the device configuration directly in the validation test, for example:
180
+
181
+
```
182
+
validate:
183
+
...
184
+
bgp_lbd:
185
+
description: Shut down the loopback interface
186
+
config:
187
+
inline:
188
+
frr: |
189
+
#!/bin/bash
190
+
ip link set lo down
191
+
pass: BGP prefix is no longer announced
192
+
nodes: [ xf ]
193
+
```
194
+
195
+
```{tip}
196
+
Always use the YAML *literal block scalar header* (`|`) for the configuration content; otherwise, the whole content will be folded into a single line.
Copy file name to clipboardExpand all lines: docs/topology/validate.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,9 +40,10 @@ You can also set these test string attributes to prettify the test results:
40
40
41
41
The **show**, **exec**, and **valid** parameters can be strings or dictionaries. If you're building a lab that will be used with a single platform, specify them as strings; if you want to execute tests on different platforms, specify a dictionary of commands and Python validation snippets. The values of these parameters can be Jinja2 expressions (see [](validate-multi-platform) for more details).
42
42
43
-
The **config** parameter can be a string (the template to deploy) or a dictionary with two parameters:
43
+
The **config** parameter can be a string (the template to deploy) or a dictionary with these parameters:
44
44
45
-
***template**: the template to deploy
45
+
***template**: the template to deploy, or
46
+
***inline**: the [configuration change that has to be applied](plugin-files-validation-config) (needs **[files](plugin-files)** plugin to work)
46
47
***variable**: a dictionary of variable values that will be passed to the Ansible playbook as external variables. You can use these variables to influence the functionality of the configuration template ([example](validate-config))
0 commit comments