configuration des vlan depuis les interfaces #18086
-
Hi, I'd like to generate the vlan list from the device interfaces. Template ########################
{%- for interface in device.interfaces.all() -%}
{%- if interface.enabled == true and interface.untagged_vlan.vid != “None” and interface.type != “virtual” %}
Untagged VLANs: {{ interface.untagged_vlan.vid }}
{% for vlan in interface.tagged_vlans.all() -%}
{% if vlan.id != “” -%}
Tagged VLANs: {{ vlan.vid }}
{% endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor %}
######################## Rendered Config
but I'd like to have this rendering, a list of vlan with unique ids, name and description Rendered Config Needed
I can't use this variable "device.site.vlans.all()" because vlans can be present on several sites but not all. Can you help me, please? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
maybe not the fastest way but :
|
Beta Was this translation helpful? Give feedback.
-
i try this way ########################
{%- set vlList = [] -%}
{%- for interface in device.interfaces.all() -%}
{%- if interface.enabled == true and interface.untagged_vlan.vid != "None" and interface.type != "virtual" -%}{%- set _ = vlList.append(interface.untagged_vlan.vid) -%}
{%- for vlan in interface.tagged_vlans.all() -%}
{%- if vlan.id != "" -%}
{%- set _ = vlList.append(vlan.vid) -%}
{%- endif -%}{%- endfor -%}
{%- endif -%}{%- endfor -%}
{%- for vlan in vlList|sort|unique %}
vlan {{vlan}}
name
description
{% endfor -%}
######################## Rendered Config
I don't see how i can get the name and description for each vlan. |
Beta Was this translation helpful? Give feedback.
-
Thx you very much, I found and succeeded. |
Beta Was this translation helpful? Give feedback.
-
Thx, very nice filter
|
Beta Was this translation helpful? Give feedback.
Thx, very nice filter
i just have to add an _ on vid__in, and that's works fine
{%- for vlan in ipam.VLAN.objects.filter(vid__in=vlList).distinct() %}