From 807f9d8e2999e51afa8dc6b0ee636ce6f053ec39 Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 23 Oct 2022 22:39:06 +0200 Subject: [PATCH] pkgs/switch-report: init --- nix/pkgs/default.nix | 6 ++- nix/pkgs/gateway-report.nix | 2 +- nix/pkgs/homepage/default.nix | 5 ++- nix/pkgs/homepage/header.html | 1 + nix/pkgs/switch-report.nix | 80 +++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 nix/pkgs/switch-report.nix diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index 812f190..16179b8 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -104,6 +104,10 @@ let inherit self nixpkgs system; }; + switch-report = import ./switch-report.nix { + inherit self nixpkgs system; + }; + vlan-report = import ./vlan-report.nix { inherit self nixpkgs system; }; @@ -115,6 +119,6 @@ in rootfs-packages // vm-packages // device-templates // openwrt-packages // network-graphs // network-cypher-graphs // starlink // subnetplans // { inherit export-openwrt-models export-config dns-slaves encrypt-secrets decrypt-secrets switch-to-production - homepage gateway-report vlan-report + homepage gateway-report switch-report vlan-report ; } diff --git a/nix/pkgs/gateway-report.nix b/nix/pkgs/gateway-report.nix index e9822b3..bc20d5d 100644 --- a/nix/pkgs/gateway-report.nix +++ b/nix/pkgs/gateway-report.nix @@ -4,7 +4,7 @@ let config = self.lib.config; in -writeText "vlan-report.md" '' +writeText "gateway-report.md" '' # Gateway Report ${lib.concatMapStrings (net: diff --git a/nix/pkgs/homepage/default.nix b/nix/pkgs/homepage/default.nix index d7b01db..8f6642a 100644 --- a/nix/pkgs/homepage/default.nix +++ b/nix/pkgs/homepage/default.nix @@ -12,7 +12,7 @@ let inherit (self.packages.${system}) export-config gateway-report network-graphs - subnetplans vlan-report; + subnetplans switch-report vlan-report; in stdenv.mkDerivation { @@ -30,8 +30,9 @@ stdenv.mkDerivation { pandoc -t html ${../../../doc/hello.md} > index.html cat ${./linked-data.html} >> index.html pandoc -t html ${../../../doc/vpn.md} > vpn.html - pandoc -t html ${vlan-report} > vlan-report.html pandoc -t html ${gateway-report} > gateway-report.html + pandoc -t html ${switch-report} > switch-report.html + pandoc -t html ${vlan-report} > vlan-report.html echo '
' > config.html
     bat --color=always --theme=GitHub -p ${export-config} | \
diff --git a/nix/pkgs/homepage/header.html b/nix/pkgs/homepage/header.html
index b5f34a7..28ed7d2 100644
--- a/nix/pkgs/homepage/header.html
+++ b/nix/pkgs/homepage/header.html
@@ -25,6 +25,7 @@
           
  • VLAN
  • Logisch
  • Physisch
  • +
  • Ports
  • VPN
  • Config
  • diff --git a/nix/pkgs/switch-report.nix b/nix/pkgs/switch-report.nix new file mode 100644 index 000000000..04ac2fe --- /dev/null +++ b/nix/pkgs/switch-report.nix @@ -0,0 +1,80 @@ +{ self, nixpkgs, system }: +with nixpkgs.legacyPackages.${system}; +let + config = self.lib.config; + + reportHosts = lib.concatMapStrings (hostName: + let + inherit (config.site.hosts.${hostName}) links model location; + + linksByPorts = builtins.foldl' (linksByPorts: linkName: + if links.${linkName}.group != null + then + # group ports + linksByPorts // { + ${lib.concatStringsSep "
    " links.${linkName}.ports} = linkName; + } + else + # expand lists of access ports to seperate rows + builtins.foldl' (linksByPorts': port: + linksByPorts' // { + ${port} = linkName; + } + ) linksByPorts links.${linkName}.ports + ) {} (builtins.attrNames links); + + in '' + ## ${hostName} + + `${model}` @ **${location}** + + |Name|Ports|Group|Trunk|Networks| + |-:|-:|:-:|:-:|:-| + ${lib.concatMapStrings (ports: + let + linkName = linksByPorts.${ports}; + link = links.${linkName}; + in '' + |**${ + linkName + }**|${ + ports + }|${ + lib.optionalString (link.group != null) ( + toString link.group + ) + }|${ + lib.optionalString link.trunk "✓" + }|${ + lib.concatStringsSep "
    " ( + map (net: + "${net} (`${toString config.site.net.${net}.vlan}`)" + ) (builtins.sort (a: b: + config.site.net.${a}.vlan < config.site.net.${b}.vlan + ) link.nets) + ) + }| + '') (lib.naturalSort ( + builtins.attrNames linksByPorts + ))} + + ''); + + reportRole = role: + reportHosts ( + lib.naturalSort ( + builtins.filter (hostName: + config.site.hosts.${hostName}.role == "switch" + ) (builtins.attrNames config.site.hosts) + ) + ); +in +writeText "switch-report.md" '' + # Switch Report + + ${reportRole "switch"} + + # Access Point Report + + ${reportRole "ap"} +''