diff --git a/nix/pkgs/switches/3com-4200G.nix b/nix/pkgs/switches/3com-4200G.nix index 3ed41b5..3859a0c 100644 --- a/nix/pkgs/switches/3com-4200G.nix +++ b/nix/pkgs/switches/3com-4200G.nix @@ -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" diff --git a/nix/pkgs/switches/HP-procurve-2824.nix b/nix/pkgs/switches/HP-procurve-2824.nix index 99c12e5..086afe3 100644 --- a/nix/pkgs/switches/HP-procurve-2824.nix +++ b/nix/pkgs/switches/HP-procurve-2824.nix @@ -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 diff --git a/nix/pkgs/switches/TL-SG3210.nix b/nix/pkgs/switches/TL-SG3210.nix index 9a216ba..7c1a074 100644 --- a/nix/pkgs/switches/TL-SG3210.nix +++ b/nix/pkgs/switches/TL-SG3210.nix @@ -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)#" diff --git a/nix/pkgs/switches/linksys-srw2048.nix b/nix/pkgs/switches/linksys-srw2048.nix index 8d168ad..d1f2b0f 100644 --- a/nix/pkgs/switches/linksys-srw2048.nix +++ b/nix/pkgs/switches/linksys-srw2048.nix @@ -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)#" diff --git a/nix/pkgs/switches/shared.nix b/nix/pkgs/switches/shared.nix new file mode 100644 index 000000000..40a3586 --- /dev/null +++ b/nix/pkgs/switches/shared.nix @@ -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 + ); +} diff --git a/salt-pillar/switches/init.sls b/salt-pillar/switches/init.sls index aa09971..541c3cd 100644 --- a/salt-pillar/switches/init.sls +++ b/salt-pillar/switches/init.sls @@ -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