Skip to content

Commit

Permalink
Refactor ethernet detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mraerino committed Sep 22, 2024
1 parent f39deba commit f76c5e8
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions ubiquiti-edge-router.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@
{% set device = dcim.Device.objects.get(pk=device_id) %}
{% endif %}

{# cursed pipeline to get all possible ethernet-like type #}
{%- set ether_types = dcim.Interface._meta.get_field("type").choices |
selectattr(0, "in", ["Ethernet (fixed)", "Ethernet (modular)", "Ethernet (backplane)"]) |
map(attribute=1) | sum(start=[]) | map(attribute=0) | list
%}

{%- for intf in device.interfaces.all() %}

{# Loopback #}
{%- if intf.name == "lo" %}{% set iftype = "loopback" %}{% endif %}

{# Ethernet #}
{%- if intf.type in ether_types %}
{%- if intf.type not in ["virtual", "other", "bridge", "lag"] %}
{%- set iftype = "ethernet" %}
{%- endif %}

Expand Down

0 comments on commit f76c5e8

Please sign in to comment.