Page MenuHomeVyOS Platform

Jinja2: add plugin to test if a variable is defined and not none to reduce template complexity
Closed, ResolvedPublicFEATURE REQUEST

Description

We have a lot of boiler plate template code like

{%   if config.interface is defined and config.interface.remote_as is defined and config.interface.remote_as is not none %}
...
{%   endif %}

This can be stripped down using a custom test to:

{%   if config.interface.remote_as is vyos_defined %}
...
{%   endif %}

In addition the new vyos_defined test supports comparison

{%   if foo.bar.baz is vyos_defined('zoo') %}
...
{%   endif %}

So the above will only evaluate to true if the variable foo.bar.baz is defined and its content is zoo

This is inspired from https://github.com/aristanetworks/ansible-avd/ which make heavy use of it.

All new templates should be written in this new style.

Details

Difficulty level
Normal (likely a few hours)
Version
-
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Perfectly compatible
Issue type
Internal change (not visible to end users)

Event Timeline

c-po changed the task status from Open to In progress.Apr 1 2022, 7:43 PM
c-po claimed this task.
c-po triaged this task as Wishlist priority.
c-po created this task.
c-po changed Difficulty level from Unknown (require assessment) to Normal (likely a few hours).
c-po changed Is it a breaking change? from Unspecified (possibly destroys the router) to Perfectly compatible.
c-po changed Issue type from Unspecified (please specify) to Internal change (not visible to end users).
c-po updated the task description. (Show Details)