One of these days I’m gonna write a defaultattr Jinja filter and become rich and famous.
32 lines
915 B
Django/Jinja
32 lines
915 B
Django/Jinja
{% for vrf in interfaces | selectattr('vrf') | map(attribute='vrf.name') | sort | unique %}
|
|
auto {{ vrf }}
|
|
iface {{ vrf }}
|
|
vrf-table auto
|
|
address 127.0.0.1/8
|
|
address ::1/128
|
|
|
|
{%+ endfor %}
|
|
|
|
{%- for iface in interfaces | selectattr('enabled') %}
|
|
{% if not iface.mgmt_only|default(false) and not iface.wwn|default(false) %}
|
|
auto {{ iface.name }}
|
|
iface {{ iface.name }}{% if iface.name == 'lo' %} inet loopback{% endif +%}
|
|
{% if iface.mtu %}
|
|
mtu {{ iface.mtu }}
|
|
{% endif %}
|
|
{% if iface.vrf %}
|
|
vrf {{ iface.vrf.name }}
|
|
{% endif %}
|
|
{% for ip in iface.ip_addresses %}
|
|
address {{ ip.address }}
|
|
{% set subnet = ip.address | ipaddr('subnet') %}
|
|
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
|
|
{% set gateway = prefix.custom_fields.gateway.address %}
|
|
{% if gateway is defined %}
|
|
gateway {{ gateway | ipaddr('address') }}
|
|
{% endif %}
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
{% endfor %}
|