From 40803689276b2a8a8c31d7dc9db9e815730beffa Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 7 Nov 2021 02:22:24 +0100 Subject: [PATCH] pkgs/switches: sort output stably --- nix/pkgs/device-templates.nix | 7 +++++-- nix/pkgs/switches/3com-4200G.nix | 16 ++++++++++------ nix/pkgs/switches/HP-procurve-2824.nix | 15 +++++++++------ nix/pkgs/switches/TL-SG3210.nix | 12 ++++++++---- nix/pkgs/switches/linksys-srw2048.nix | 16 ++++++++++------ 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/nix/pkgs/device-templates.nix b/nix/pkgs/device-templates.nix index 4d82a10..1614122 100644 --- a/nix/pkgs/device-templates.nix +++ b/nix/pkgs/device-templates.nix @@ -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} ) ) ( diff --git a/nix/pkgs/switches/3com-4200G.nix b/nix/pkgs/switches/3com-4200G.nix index 3859a0c..0171653 100644 --- a/nix/pkgs/switches/3com-4200G.nix +++ b/nix/pkgs/switches/3com-4200G.nix @@ -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]" diff --git a/nix/pkgs/switches/HP-procurve-2824.nix b/nix/pkgs/switches/HP-procurve-2824.nix index 086afe3..16235d2 100644 --- a/nix/pkgs/switches/HP-procurve-2824.nix +++ b/nix/pkgs/switches/HP-procurve-2824.nix @@ -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}# " diff --git a/nix/pkgs/switches/TL-SG3210.nix b/nix/pkgs/switches/TL-SG3210.nix index 7c1a074..2c53b10 100644 --- a/nix/pkgs/switches/TL-SG3210.nix +++ b/nix/pkgs/switches/TL-SG3210.nix @@ -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 "#" diff --git a/nix/pkgs/switches/linksys-srw2048.nix b/nix/pkgs/switches/linksys-srw2048.nix index d1f2b0f..7cf0b0d 100644 --- a/nix/pkgs/switches/linksys-srw2048.nix +++ b/nix/pkgs/switches/linksys-srw2048.nix @@ -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) + )} ''