forked from zentralwerk/network
pkgs/switches: fixes
This commit is contained in:
parent
5c074bb051
commit
8fc0567204
|
@ -57,7 +57,6 @@ with lib;
|
||||||
expect -- "-vlan${vlan}]"
|
expect -- "-vlan${vlan}]"
|
||||||
send "name ${net}\r"
|
send "name ${net}\r"
|
||||||
expect -- "-vlan${vlan}]"
|
expect -- "-vlan${vlan}]"
|
||||||
|
|
||||||
${optionalString (net == "mgmt") ''
|
${optionalString (net == "mgmt") ''
|
||||||
# Actually only used for mgmt_vlan, switches are not routers
|
# Actually only used for mgmt_vlan, switches are not routers
|
||||||
send "interface Vlan-interface ${vlan}\r"
|
send "interface Vlan-interface ${vlan}\r"
|
||||||
|
|
|
@ -54,14 +54,14 @@ with lib;
|
||||||
send "vlan ${vlan}\r"
|
send "vlan ${vlan}\r"
|
||||||
expect "(vlan-${vlan})#"
|
expect "(vlan-${vlan})#"
|
||||||
|
|
||||||
send "name ${hostName}\r"
|
send "name ${net}\r"
|
||||||
expect "(vlan-${vlan})#"
|
expect "(vlan-${vlan})#"
|
||||||
|
|
||||||
send "jumbo\r"
|
send "jumbo\r"
|
||||||
expect "(vlan-${vlan})#"
|
expect "(vlan-${vlan})#"
|
||||||
|
|
||||||
# Actually only used for mgmt_vlan, switches are not routers
|
|
||||||
${optionalString (hosts4 ? ${hostName}) ''
|
${optionalString (hosts4 ? ${hostName}) ''
|
||||||
|
# Actually only used for mgmt_vlan, switches are not routers
|
||||||
send "ip address ${hostAddr4} ${netmask}\r"
|
send "ip address ${hostAddr4} ${netmask}\r"
|
||||||
expect "(vlan-${vlan})#"
|
expect "(vlan-${vlan})#"
|
||||||
''}
|
''}
|
||||||
|
@ -89,7 +89,13 @@ with lib;
|
||||||
isAccess = config.site.net ? ${name};
|
isAccess = config.site.net ? ${name};
|
||||||
netConfig = config.site.net.${name};
|
netConfig = config.site.net.${name};
|
||||||
isTrunk = !isAccess;
|
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;
|
ports = concatStringsSep "," linkConfig.ports;
|
||||||
in
|
in
|
||||||
if isTrunk && isBond
|
if isTrunk && isBond
|
||||||
|
|
|
@ -68,10 +68,10 @@ with lib;
|
||||||
expect "(config)#"
|
expect "(config)#"
|
||||||
''}
|
''}
|
||||||
|
|
||||||
# Actually only used for mgmt_vlan, switches are not routers
|
|
||||||
send "interface vlan ${vlan}\r"
|
send "interface vlan ${vlan}\r"
|
||||||
expect "(config-if)#"
|
expect "(config-if)#"
|
||||||
${optionalString (hosts4 ? ${hostName}) ''
|
${optionalString (hosts4 ? ${hostName}) ''
|
||||||
|
# Actually only used for mgmt_vlan, switches are not routers
|
||||||
send "ip address ${hostAddr4} ${netmask}\r"
|
send "ip address ${hostAddr4} ${netmask}\r"
|
||||||
expect "(config-if)#"
|
expect "(config-if)#"
|
||||||
''}
|
''}
|
||||||
|
@ -86,16 +86,23 @@ with lib;
|
||||||
isAccess = config.site.net ? ${name};
|
isAccess = config.site.net ? ${name};
|
||||||
netConfig = config.site.net.${name};
|
netConfig = config.site.net.${name};
|
||||||
isTrunk = !isAccess;
|
isTrunk = !isAccess;
|
||||||
isBond = isTrunk && builtins.length linkConfig.ports > 1;
|
port0 = builtins.head linkConfig.ports;
|
||||||
ports = concatStringsSep "," 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
|
in
|
||||||
if isTrunk
|
if isTrunk
|
||||||
then ''
|
then ''
|
||||||
send "interface range gigabitEthernet 1/0/${ports}\r"
|
send "interface range gigabitEthernet ${ports}\r"
|
||||||
expect "(config-if-range)#"
|
expect "(config-if-range)#"
|
||||||
send "switchport mode trunk\r"
|
send "switchport mode trunk\r"
|
||||||
expect "(config-if-range)#"
|
expect "(config-if-range)#"
|
||||||
${if (builtins.length linkConfig.ports > 1)
|
${if isBond
|
||||||
then ''
|
then ''
|
||||||
send "channel-group ${linkConfig.group} mode active\r"
|
send "channel-group ${linkConfig.group} mode active\r"
|
||||||
expect "(config-if-range)#"
|
expect "(config-if-range)#"
|
||||||
|
@ -105,7 +112,7 @@ with lib;
|
||||||
send "no channel-group\r"
|
send "no channel-group\r"
|
||||||
expect "(config-if-range)#"
|
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)#"
|
expect "(config-if-range)#"
|
||||||
send "exit\r"
|
send "exit\r"
|
||||||
expect "(config)#"
|
expect "(config)#"
|
||||||
|
|
|
@ -54,6 +54,7 @@ with lib;
|
||||||
netConfig = config.site.net.${name};
|
netConfig = config.site.net.${name};
|
||||||
isTrunk = !isAccess;
|
isTrunk = !isAccess;
|
||||||
isBond = isTrunk && builtins.length linkConfig.ports > 1;
|
isBond = isTrunk && builtins.length linkConfig.ports > 1;
|
||||||
|
vlans = concatStringsSep "," (map toString linkConfig.vlans);
|
||||||
ports = concatStringsSep "," linkConfig.ports;
|
ports = concatStringsSep "," linkConfig.ports;
|
||||||
in
|
in
|
||||||
if isTrunk && isBond
|
if isTrunk && isBond
|
||||||
|
@ -72,7 +73,7 @@ with lib;
|
||||||
expect "(config-if)#"
|
expect "(config-if)#"
|
||||||
send "switchport mode trunk\r"
|
send "switchport mode trunk\r"
|
||||||
expect "(config-if)#"
|
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)#"
|
expect "(config-if)#"
|
||||||
|
|
||||||
send "exit\r"
|
send "exit\r"
|
||||||
|
@ -86,7 +87,7 @@ with lib;
|
||||||
expect "(config-if)#"
|
expect "(config-if)#"
|
||||||
send "switchport mode trunk\r"
|
send "switchport mode trunk\r"
|
||||||
expect "(config-if)#"
|
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)#"
|
expect "(config-if)#"
|
||||||
send "exit\r"
|
send "exit\r"
|
||||||
expect "(config)#"
|
expect "(config)#"
|
||||||
|
|
22
nix/pkgs/switches/shared.nix
Normal file
22
nix/pkgs/switches/shared.nix
Normal 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
|
||||||
|
);
|
||||||
|
}
|
|
@ -729,7 +729,7 @@ switches:
|
||||||
# Unused: 3
|
# Unused: 3
|
||||||
switch-d1:
|
switch-d1:
|
||||||
model: 'TL-SG3210'
|
model: 'TL-SG3210'
|
||||||
location: Turm D Keller
|
location: Turm D Elektroraum
|
||||||
ports:
|
ports:
|
||||||
switch-b1:
|
switch-b1:
|
||||||
mode: bond
|
mode: bond
|
||||||
|
|
Loading…
Reference in New Issue
Block a user