WIP: Aruba switches #103

Draft
jeltz wants to merge 10 commits from aruba into master
2 changed files with 26 additions and 8 deletions
Showing only changes of commit fa96466116 - Show all commits

17
filter_plugins/aruba.py Normal file
View file

@ -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)
)

View file

@ -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