Conversation
ipspace
left a comment
There was a problem hiding this comment.
Lovely idea. I would make a few slight changes in the variable names and streamline the tests.
|
|
||
| {# End of `config global` #} | ||
|
|
||
| {% if netlab_allow is defined and netlab_allow != false %} |
There was a problem hiding this comment.
I would call it "netlab_default_policy" or some such, and generate the firewall policy if the variable is defined.
If you want to have an override option (setting it to false to disable it), go with netlab_default_policy|default(false)-- that will be false if the variable is not defined or if it's set to False, and will evaluate to false as a boolean expression even if it has falsy value (like None or an empty dictionary).
|
|
||
| config firewall policy | ||
| edit 1000 | ||
| {% if netlab_allow is mapping and netlab_allow.disable | default(false) %} |
There was a problem hiding this comment.
At this point, we know "netlab_default_policy" (or however it's called) is defined. Under our current Jinja2 setup, you could simply test netlab_default_policy.disable|default(false) and have the desired result even when netlab_default_policy is not a mapping.
Personally, I would prefer using enable with default true, "not disabling" is a double negation, and that tends to get confusing.
|
Here's how you can test whether any particular trick works with our Jinja2 setup. As we are using the same code to generate reports and device configs, you can create a report that uses none of the topology variables and play with Jinja2 expressions. The only tricks:
After setting this up, just do netlab report reportname and experiment. Here's what I tested: And here are the test results: |
This is possible variant to address #3323
Policy is injected in initial configuration.
It is configured by device configuration: