From ad775bffe9442e2b09e4a3d60916c97571256f5f Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Sun, 12 May 2019 00:59:55 +0100 Subject: [PATCH] use netbox's tagged_vlans on an interface to create sub-interfaces --- vyos.conf.j2 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vyos.conf.j2 b/vyos.conf.j2 index ebcd6d9..566bd29 100644 --- a/vyos.conf.j2 +++ b/vyos.conf.j2 @@ -69,14 +69,18 @@ interfaces { {% if not iface_data['enabled'] %}disable{% endif %} {% if iface_data['lag'] %}bond-group {{ iface_data['lag']['name'] }}{% endif %} - {% for subiface_name, subiface_data in pillar['netbox']['interfaces'].items() %}{% if subiface_data['form_factor']['label'] == 'Virtual' and subiface_name.startswith( iface_name + "." ) %} - vif {{ subiface_name.split( "." )[ 1 ] }} { - description "{{ subiface_data['description'].replace('"','\\"') or "-" }}" + {% for tagged_vlan in iface_data['tagged_vlans'] %} + {% set subiface_data = salt['pillar.get']('netbox:interfaces:%s.%04d'%(iface_name,tagged_vlan['vid']),{'description':'','addresses':[],'enabled':False}) %} + vif {{ tagged_vlan['vid'] }} { + description "{{ tagged_vlan['name'].replace('"','\\"') or "-" }} => {{ subiface_data['description'].replace('"','\\"') or "-" }}" {% for address in subiface_data['addresses'] %} address {{ address['address'] }} {% endfor %} {% if not subiface_data['enabled'] %}disable{% endif %} } + {% endfor %} + + {% for subiface_name, subiface_data in pillar['netbox']['interfaces'].items() %}{% if subiface_data['form_factor']['label'] == 'Virtual' and subiface_name.startswith( iface_name + "." ) %} {% endif %}{% endfor %} {% if salt['pillar.get']('interfaces:'+iface_name+':ip') %}