From fa9646611697e779cd092f87fbdb75a36857590e Mon Sep 17 00:00:00 2001 From: Jeltz Date: Mon, 5 Sep 2022 09:10:42 +0200 Subject: [PATCH] aruba: add aruba_ints filter --- filter_plugins/aruba.py | 17 +++++++++++++++++ roles/aruba/templates/config.j2 | 17 +++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 filter_plugins/aruba.py diff --git a/filter_plugins/aruba.py b/filter_plugins/aruba.py new file mode 100644 index 0000000..c733394 --- /dev/null +++ b/filter_plugins/aruba.py @@ -0,0 +1,17 @@ +class FilterModule: + def filters(self): + return { + "aruba_ints": aruba_ints, + } + + +def aruba_ints(seq, sep=",", hyphen="-"): + ranges = [] + for value in sorted(seq): + if not ranges or ranges[-1][1] + 1 != value: + ranges.append((value, value)) + else: + ranges[-1] = (ranges[-1][0], value) + return sep.join( + (f"{a}" if a == b else f"{a}{hyphen}{b}" for a, b in ranges) + ) diff --git a/roles/aruba/templates/config.j2 b/roles/aruba/templates/config.j2 index 3519f92..86a2e97 100644 --- a/roles/aruba/templates/config.j2 +++ b/roles/aruba/templates/config.j2 @@ -48,11 +48,10 @@ set lldp_enabled = set lldp_disabled = aruba__interfaces.keys() | difference(lldp_enabled) - | map("int") | list %} {% if lldp_disabled %} -lldp admin-status {{ lldp_disabled | join(",") }} disable +lldp admin-status {{ lldp_disabled | aruba_ints }} disable {% endif %} password manager plaintext {{ aruba__manager_password | enquote }} @@ -82,13 +81,12 @@ set loop_protect = | selectattr("value.loop_protect", "defined") | selectattr("value.loop_protect") | map(attribute="key") - | map("int") | list %} {% if loop_protect %} loop-protect disable-timer {{ aruba__loop_protect_disable_timer | int }} loop-protect transmit-interval {{ aruba__loop_protect_tx_interval | int }} -loop-protect {{ loop_protect | join(",") }} +loop-protect {{ loop_protect | aruba_ints }} {% endif %} {% if aruba__default_gateways | ipv4 %} @@ -110,11 +108,10 @@ set untagged = | selectattr("value.untagged", "defined") | selectattr("value.untagged", "==", id) | map(attribute="key") - | map("int") | list %} {% if untagged %} - untagged {{ untagged | join(",") }} + untagged {{ untagged | aruba_ints }} {% endif %} {% set tagged = @@ -123,11 +120,10 @@ set tagged = | selectattr("value.tagged", "defined") | selectattr("value.tagged", "contains", id) | map(attribute="key") - | map("int") | list %} {% if tagged %} - tagged {{ tagged | join(",") }} + tagged {{ tagged | aruba_ints }} {% endif %} {% if vlan.addresses | default([]) %} {% for address in vlan.addresses | ipv4 %} @@ -148,6 +144,11 @@ set tagged = interface {{ id | int }} {% if iface.name is defined %} name {{ iface.name | enquote }} +{% endif %} +{% if iface.enabled | default(True) %} + enable +{% else %} + no enable {% endif %} exit