pkgs/switches: fixes

This commit is contained in:
Astro 2021-11-07 02:21:48 +01:00
parent 5c074bb051
commit 8fc0567204
6 changed files with 48 additions and 13 deletions

View File

@ -57,7 +57,6 @@ with lib;
expect -- "-vlan${vlan}]"
send "name ${net}\r"
expect -- "-vlan${vlan}]"
${optionalString (net == "mgmt") ''
# Actually only used for mgmt_vlan, switches are not routers
send "interface Vlan-interface ${vlan}\r"

View File

@ -54,14 +54,14 @@ with lib;
send "vlan ${vlan}\r"
expect "(vlan-${vlan})#"
send "name ${hostName}\r"
send "name ${net}\r"
expect "(vlan-${vlan})#"
send "jumbo\r"
expect "(vlan-${vlan})#"
# Actually only used for mgmt_vlan, switches are not routers
${optionalString (hosts4 ? ${hostName}) ''
# Actually only used for mgmt_vlan, switches are not routers
send "ip address ${hostAddr4} ${netmask}\r"
expect "(vlan-${vlan})#"
''}
@ -89,7 +89,13 @@ with lib;
isAccess = config.site.net ? ${name};
netConfig = config.site.net.${name};
isTrunk = !isAccess;
isBond = isTrunk && builtins.length linkConfig.ports > 1;
port0 = builtins.head linkConfig.ports;
isBond =
builtins.length linkConfig.ports > 1
||
hasInfix "-" port0
||
hasInfix "," port0;
ports = concatStringsSep "," linkConfig.ports;
in
if isTrunk && isBond

View File

@ -68,10 +68,10 @@ with lib;
expect "(config)#"
''}
# Actually only used for mgmt_vlan, switches are not routers
send "interface vlan ${vlan}\r"
expect "(config-if)#"
${optionalString (hosts4 ? ${hostName}) ''
# Actually only used for mgmt_vlan, switches are not routers
send "ip address ${hostAddr4} ${netmask}\r"
expect "(config-if)#"
''}
@ -86,16 +86,23 @@ with lib;
isAccess = config.site.net ? ${name};
netConfig = config.site.net.${name};
isTrunk = !isAccess;
isBond = isTrunk && builtins.length linkConfig.ports > 1;
ports = concatStringsSep "," linkConfig.ports;
port0 = builtins.head linkConfig.ports;
isBond =
builtins.length linkConfig.ports > 1
||
hasInfix "-" port0;
vlans = concatStringsSep "," (map toString linkConfig.vlans);
ports = concatMapStringsSep "," (port:
"1/0/${port}"
) linkConfig.ports;
in
if isTrunk
then ''
send "interface range gigabitEthernet 1/0/${ports}\r"
send "interface range gigabitEthernet ${ports}\r"
expect "(config-if-range)#"
send "switchport mode trunk\r"
expect "(config-if-range)#"
${if (builtins.length linkConfig.ports > 1)
${if isBond
then ''
send "channel-group ${linkConfig.group} mode active\r"
expect "(config-if-range)#"
@ -105,7 +112,7 @@ with lib;
send "no channel-group\r"
expect "(config-if-range)#"
''}
send "switchport trunk allowed vlan ${concatStringsSep "," (map toString linkConfig.vlans)}\r"
send "switchport trunk allowed vlan ${vlans}\r"
expect "(config-if-range)#"
send "exit\r"
expect "(config)#"

View File

@ -54,6 +54,7 @@ with lib;
netConfig = config.site.net.${name};
isTrunk = !isAccess;
isBond = isTrunk && builtins.length linkConfig.ports > 1;
vlans = concatStringsSep "," (map toString linkConfig.vlans);
ports = concatStringsSep "," linkConfig.ports;
in
if isTrunk && isBond
@ -72,7 +73,7 @@ with lib;
expect "(config-if)#"
send "switchport mode trunk\r"
expect "(config-if)#"
send "switchport trunk allowed vlan add ${concatStringsSep "," (map toString linkConfig.vlans)}\r"
send "switchport trunk allowed vlan add ${vlans}\r"
expect "(config-if)#"
send "exit\r"
@ -86,7 +87,7 @@ with lib;
expect "(config-if)#"
send "switchport mode trunk\r"
expect "(config-if)#"
send "switchport trunk allowed vlan add ${concatStringsSep "," (map toString linkConfig.vlans)}\r"
send "switchport trunk allowed vlan add ${vlans}\r"
expect "(config-if)#"
send "exit\r"
expect "(config)#"

View File

@ -0,0 +1,22 @@
{ config, pkgs, ... }:
with pkgs;
with lib;
rec {
sort = builtins.sort (a: b:
if builtins.isList a && builtins.isList b
then compareLists a b
else a < b
);
sortBy = f: builtins.sort (a: b:
let
ra = f a;
rb = f b;
in
if builtins.isList ra && builtins.isList rb
then compareLists compare ra rb < 0
else ra < rb
);
sortNetsByVlan = builtins.sort (net1: net2:
config.site.net.${net1}.vlan < config.site.net.${net2}.vlan
);
}

View File

@ -729,7 +729,7 @@ switches:
# Unused: 3
switch-d1:
model: 'TL-SG3210'
location: Turm D Keller
location: Turm D Elektroraum
ports:
switch-b1:
mode: bond