Skip to content

Commit

Permalink
Handle vlans
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino committed Sep 22, 2024
1 parent f46ce90 commit 4acfe51
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ubiquiti-edge-router.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{% endif %}

{%- for intf in device.interfaces.all() %}
{%- set ifpath = intf.name %}

{#- Loopback #}
{%- if intf.name == "lo" %}{% set iftype = "loopback" %}{% endif %}
Expand All @@ -16,6 +17,13 @@
{%- set iftype = "ethernet" %}
{%- endif %}

{#- VLANs #}
{%- if intf.type == 'virtual' and intf.parent and intf.mode == 'access' and intf.untagged_vlan is not none %}
{%- if intf.parent.type not in ["virtual", "other", "bridge", "lag"] %}{% set iftype = "ethernet" %}{% endif %}
{#- TODO: add other iftypes #}
{%- set ifpath = "%s vif %d" % (intf.parent.name, intf.untagged_vlan.vid) %}
{%- endif %}

{#- Tunnels #}
{%- with term = intf.tunnel_terminations.first() %}
{%- if term %}
Expand All @@ -41,16 +49,16 @@ set interfaces tunnel {{ intf.name }} remote-ip {{ remote_ip.address | ipaddr('a
{#- Generic interface config #}
{%- if iftype %}
{%- if intf.description != '' %}
set interfaces {{ iftype }} {{ intf.name }} description "{{ intf.description | slugify(lower=False, spaces=True, only_ascii=True, extra_chars='()') }}"
set interfaces {{ iftype }} {{ ifpath }} description "{{ intf.description | slugify(lower=False, spaces=True, only_ascii=True, extra_chars='()') }}"
{%- endif %}

{%- for addr in intf.ip_addresses.all() %}
{%- if addr.status == 'dhcp' %}
set interfaces {{ iftype }} {{ intf.name }} address dhcp
set interfaces {{ iftype }} {{ ifpath }} address dhcp
{%- elif addr.status == 'slaac' %}
set interfaces {{ iftype }} {{ intf.name }} ipv6 address autoconf
set interfaces {{ iftype }} {{ ifpath }} ipv6 address autoconf
{%- else %}
set interfaces {{ iftype }} {{ intf.name }} address {{ addr.address }}
set interfaces {{ iftype }} {{ ifpath }} address {{ addr.address }}
{%- endif %}
{%- endfor %}

Expand Down

0 comments on commit 4acfe51

Please sign in to comment.