Replies: 3 comments 36 replies
-
🎉 ! open points2 template wrapperThis contains various helper functions (like ip & expect used in your example template above splitting&testing used in the sros template) and respective tests for these. I also overwrite standard text/template functions to enable them to be piped & at the same time keep them backward compatible to text/template. It was another 800-1000 lines of code that is purely used to make text/template usable for this purpose, and adding some functions that one would expect coming from ansible/jinja. So during the review we decided to split it out in the future functions for assigning IPs from pools can be added here as well 3 variable prepThis is quite important for links, else you have to explicitly specify an IP on each, but with some more thought I can probably move this to template functions as well |
Beta Was this translation helpful? Give feedback.
-
1. the way to provide variables for templationHaving two sections to define variables can cause some issues,
I think it's better to keep variables in one place. The link's labels can be used to influence how an interface is configured, e.g:
2. providing templates to use for templationThe templates can be a global variable, a path that is recursively parsed to load all the templates. Open points
|
Beta Was this translation helpful? Give feedback.
-
#495 addresses the issues of required @hellt you want me to work on # 4?
|
Beta Was this translation helpful? Give feedback.
-
Hi @kellerza @karimra
I merged the #383. Sorry it took so long, @kellerza, I wish I could get to it sooner... Thank you for stepping in and delivering the feature implementation of the config generation and provisioning. It was a lot of work, and you made a very important first step!
I propose to open this forum to discuss how do we take it from here, because although it is a working solution, it has quite a few things which are somewhat opinionated and not generic.
Let me summarize here what I did on top of the #383 after the last commit of @kellerza:
1. the way to provide variables for templation
I followed the original idea of providing variables for nodes and links to not introduce any breaking change. But we need to discuss this, as we may have a stronger design here. @karimra that is the issue we discussed the other day.
Originally the
labels
attribute of nodes and links was used to keep variables that are used in config templation.I changed that to the following:
.topology.nodes.<node>.config.vars
. This is amap[string]string
structure which allows flat variables pairs in the form ofvar-name:var-value
..topology.links[].vars
That change required me to change the original
.topology.nodes.<node>.config
to ``.topology.nodes..startup-configto free up the
config` key.The
.topology.nodes.<node>.config
is of type *ConfigDispatcher. It is not a simple map for a single reason that it was envisioned to grow and incorporate transport selection, transport options, template names to use.Consequently, I had to create a few methods for Topology and NodeDefinition struct, namely GetConfigDispatcher
An example of the variables defined in clab file:
2 providing templates to use for templation
The templates that will be rendered on a per-node basis are provided via two flags of the
config
subcommand--template-path
- recieves a list of paths where the actual template files will be looked at--template-list
- takes a list of names of the templates files that will be searched in paths provided with the flag aboveThe
--template-list
requires a bit of an explanation. The pattern that the templates of the current code are using is<name>__<role>.tmpl
.The
name
is a free formed string, whereas therole
is a suffix that denotes to which role this template belongs to. The idea here is that in a multivendor lab or in a lab with multiple roles the devices would require different templates.The
role
by default is assumed to be thekind
of the node, but it is configurable.Let's imagine we want to create a template that configures eBGP between SRL and SR OS, we could create the following files
bgp__srl.tmpl
bgp__vr-sros.tmpl
and then by doing
clab config -t <topo> --template-path <path> --template-list bgp
we are able to pick the right template per each node of the lab, based on the kind selector.A very basic example of the template for interface provisioning on SRL can look like this:
If, say, you have this file under
./private/iface__srl.tmpl
, then you can configure your SRL nodes of the lab shown above with the following command# by omitting --template-list the code will take all files available in the search path clab config -t srl-cfg-demo.clab.yml --tempalte-path ./private
Open points
I know that @karimra wanted to re-eval the way the vars are split between the nodes and links. Our ultimate goal is to be able to specify tree based vars, to avoid the limitations of a flat variables structure.
@kellerza It would be interesting to see what warranted to create a wrapper around stdlib
text/template
. I am not a fan of using custom wrappers until necessary. I remember before you had a functions map that you supplied totext/template
regardless of 1) there are a few hard-coded assumptions in the code that does variables preparation for links. For example, it is expected that system ip is always provided in the vars -
containerlab/clab/config/utils.go
Line 75 in 929abda
I would rather assume that we should let users decide which variables need to be present. The code should only merge variables and pass them to the template
Beta Was this translation helpful? Give feedback.
All reactions