pkgs/switches: sort output stably

This commit is contained in:
Astro 2021-11-07 02:22:24 +01:00
parent 8fc0567204
commit 4080368927
5 changed files with 42 additions and 24 deletions

View File

@ -9,11 +9,14 @@ let
pkgs.writeScript "${hostName}.sh" (
let
args = {
inherit pkgs self hostName config hostConfig;
inherit self hostName config hostConfig pkgs;
};
in {
ap = import ./ap.nix args;
switch = import (./switches + "/${model}.nix") args;
switch = import (./switches + "/${model}.nix")
(args //
import ./switches/shared.nix args
);
}.${role}
)
) (

View File

@ -1,5 +1,7 @@
# http://h20628.www2.hp.com/km-ext/kmcsdirect/emr_na-c02586144-1.pdf
{ self, pkgs, hostName, config, hostConfig, ... }:
{ self, pkgs, hostName, config, hostConfig
, sort, sortBy, sortNetsByVlan
, ... }:
with pkgs;
with lib;
''
@ -68,7 +70,7 @@ with lib;
''}
send "quit\r"
expect "${hostName}]"
'') (builtins.attrNames config.site.net)
'') (sortNetsByVlan (builtins.attrNames config.site.net))
}
${concatMapStrings (name:
@ -122,10 +124,10 @@ with lib;
${concatMapStrings (vlan: ''
send "port trunk permit vlan ${toString vlan}\r"
expect "]"
'') linkConfig.vlans}
'') (sort linkConfig.vlans)}
send "quit\r"
expect "${hostName}]"
'') linkConfig.ports}
'') (sort linkConfig.ports)}
'' else
concatMapStrings (port: ''
send "interface ${port}\r"
@ -144,8 +146,10 @@ with lib;
''}
send "quit\r"
expect "${hostName}]"
'') (linkConfig.ports)
) (builtins.attrNames hostConfig.links)}
'') (sort linkConfig.ports)
) (sortBy (link: hostConfig.links.${link}.ports)
(builtins.attrNames hostConfig.links)
)}
send "save main\r"
expect "Y/N]"

View File

@ -1,6 +1,7 @@
# http://ftp.hp.com/pub/networking/software/2600-2800-4100-6108-MgmtConfig-Oct2005-59906023.pdf
{ self, pkgs, hostName, config, hostConfig, ... }:
{ self, pkgs, hostName, config, hostConfig
, sort, sortBy, sortNetsByVlan
, ... }:
with pkgs;
with lib;
''
@ -80,7 +81,7 @@ with lib;
send "no vlan ${vlan} untagged all\r"
expect "(config)# "
''}
'') (builtins.attrNames config.site.net)
'') (sortNetsByVlan (builtins.attrNames config.site.net))
}
${concatMapStrings (name:
@ -108,7 +109,7 @@ with lib;
${concatMapStrings (vlan: ''
send "vlan ${toString vlan} tagged trk${linkConfig.group}\r"
expect "(config)# "
'') linkConfig.vlans}
'') (sort linkConfig.vlans)}
''
else if isTrunk
@ -121,7 +122,7 @@ with lib;
${concatMapStrings (vlan: ''
send "vlan ${toString vlan} tagged ${ports}\r"
expect "(config)# "
'') linkConfig.vlans}
'') (sort linkConfig.vlans)}
''
else ''
@ -131,7 +132,9 @@ with lib;
send "vlan ${toString netConfig.vlan} untagged ${ports}\r"
expect "(config)# "
''
) (builtins.attrNames hostConfig.links)}
) (sortBy (link: hostConfig.links.${link}.ports)
(builtins.attrNames hostConfig.links)
)}
send "exit\r"
expect "${hostName}# "

View File

@ -1,5 +1,7 @@
# http://static.tp-link.com/res/down/doc/TL-SG3210(UN)_V2.0_CLI_.pdf
{ self, pkgs, hostName, config, hostConfig, ... }:
{ self, pkgs, hostName, config, hostConfig
, sort, sortBy, sortNetsByVlan
, ... }:
with pkgs;
with lib;
''
@ -78,7 +80,7 @@ with lib;
send "exit\r"
expect "(config)#"
''
) (builtins.attrNames config.site.net)}
) (sortNetsByVlan (builtins.attrNames config.site.net))}
${concatMapStrings (name:
let
@ -91,7 +93,7 @@ with lib;
builtins.length linkConfig.ports > 1
||
hasInfix "-" port0;
vlans = concatStringsSep "," (map toString linkConfig.vlans);
vlans = concatStringsSep "," (map toString (sort linkConfig.vlans));
ports = concatMapStringsSep "," (port:
"1/0/${port}"
) linkConfig.ports;
@ -126,7 +128,9 @@ with lib;
send "exit\r"
expect "(config)#"
''
) (builtins.attrNames hostConfig.links)}
) (sortBy (link: hostConfig.links.${link}.ports)
(builtins.attrNames hostConfig.links)
)}
send "exit\r"
expect "#"

View File

@ -1,5 +1,7 @@
# https://www.crc.id.au/real-console-on-linksys-srw2024-switch/
{ self, pkgs, hostName, config, hostConfig, ... }:
{ self, pkgs, hostName, config, hostConfig
, sort, sortBy, sortNetsByVlan
, ... }:
with pkgs;
with lib;
''
@ -34,7 +36,7 @@ with lib;
${concatMapStrings (net: ''
send "vlan ${toString config.site.net.${net}.vlan}\r"
expect "(config-vlan)#"
'') (builtins.attrNames config.site.net)}
'') (sortNetsByVlan (builtins.attrNames config.site.net))}
send "exit\r"
expect "(config)#"
@ -45,7 +47,7 @@ with lib;
expect "(config-if)#"
send "exit\r"
expect "(config)#"
'') (builtins.attrNames config.site.net)}
'') (sortNetsByVlan (builtins.attrNames config.site.net))}
${concatMapStrings (name:
let
@ -54,7 +56,7 @@ with lib;
netConfig = config.site.net.${name};
isTrunk = !isAccess;
isBond = isTrunk && builtins.length linkConfig.ports > 1;
vlans = concatStringsSep "," (map toString linkConfig.vlans);
vlans = concatStringsSep "," (map toString (sort linkConfig.vlans));
ports = concatStringsSep "," linkConfig.ports;
in
if isTrunk && isBond
@ -103,6 +105,8 @@ with lib;
expect "(config-if)#"
send "exit\r"
expect "(config)#"
'') linkConfig.ports
) (builtins.attrNames hostConfig.links)}
'') (sort linkConfig.ports)
) (sortBy (link: hostConfig.links.${link}.ports)
(builtins.attrNames hostConfig.links)
)}
''