From fbfb22d777b0fe3f8d168e4f8c9314b94ffde3b5 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 9 Dec 2024 11:10:28 +0100 Subject: [PATCH] feat(modules/netconf): Add hardware module --- modules/netconf/default.nix | 6 +++ modules/netconf/dgn-hardware/EX2300-48P.nix | 6 +++ modules/netconf/dgn-hardware/EX4100-F-48P.nix | 13 +++++ modules/netconf/dgn-hardware/EX4400-24X.nix | 6 +++ modules/netconf/dgn-hardware/EX4400-EM-4Y.nix | 6 +++ modules/netconf/dgn-hardware/default.nix | 52 +++++++++++++++++++ 6 files changed, 89 insertions(+) create mode 100644 modules/netconf/default.nix create mode 100644 modules/netconf/dgn-hardware/EX2300-48P.nix create mode 100644 modules/netconf/dgn-hardware/EX4100-F-48P.nix create mode 100644 modules/netconf/dgn-hardware/EX4400-24X.nix create mode 100644 modules/netconf/dgn-hardware/EX4400-EM-4Y.nix create mode 100644 modules/netconf/dgn-hardware/default.nix diff --git a/modules/netconf/default.nix b/modules/netconf/default.nix new file mode 100644 index 0000000..ed754d7 --- /dev/null +++ b/modules/netconf/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + # List of modules to import + ./dgn-hardware + ]; +} diff --git a/modules/netconf/dgn-hardware/EX2300-48P.nix b/modules/netconf/dgn-hardware/EX2300-48P.nix new file mode 100644 index 0000000..5852109 --- /dev/null +++ b/modules/netconf/dgn-hardware/EX2300-48P.nix @@ -0,0 +1,6 @@ +range: + +{ + poe = range "ge-0/0/" 48; + regular = (range "ge-0/1/" 4) ++ (range "xe-0/1/" 4); +} diff --git a/modules/netconf/dgn-hardware/EX4100-F-48P.nix b/modules/netconf/dgn-hardware/EX4100-F-48P.nix new file mode 100644 index 0000000..06b2fde --- /dev/null +++ b/modules/netconf/dgn-hardware/EX4100-F-48P.nix @@ -0,0 +1,13 @@ +range: + +{ + poe = range "ge-0/0/" 48; + regular = + # SFP ports + (range "ge-0-1/" 4) + ++ (range "xe-0/1/" 4) + ++ (range "et-0/1/" 4) + # Uplink ports + ++ (range "ge-0/2/" 4) + ++ (range "xe-0/2/" 4); +} diff --git a/modules/netconf/dgn-hardware/EX4400-24X.nix b/modules/netconf/dgn-hardware/EX4400-24X.nix new file mode 100644 index 0000000..f8000c5 --- /dev/null +++ b/modules/netconf/dgn-hardware/EX4400-24X.nix @@ -0,0 +1,6 @@ +range: + +{ + poe = [ ]; + regular = (range "ge-0/0/" 24) ++ (range "xe-0/0/" 24) ++ (range "et-0/1/" 2); +} diff --git a/modules/netconf/dgn-hardware/EX4400-EM-4Y.nix b/modules/netconf/dgn-hardware/EX4400-EM-4Y.nix new file mode 100644 index 0000000..244c567 --- /dev/null +++ b/modules/netconf/dgn-hardware/EX4400-EM-4Y.nix @@ -0,0 +1,6 @@ +range: + +{ + poe = [ ]; + regular = (range "ge-0/2/" 4) ++ (range "xe-0/2/" 4) ++ (range "et-0/2/" 4); +} diff --git a/modules/netconf/dgn-hardware/default.nix b/modules/netconf/dgn-hardware/default.nix new file mode 100644 index 0000000..f376ee9 --- /dev/null +++ b/modules/netconf/dgn-hardware/default.nix @@ -0,0 +1,52 @@ +{ config, lib, ... }: + +let + inherit (lib) genList mkOption listToAttrs; + + inherit (lib.types) enum; + + range = prefix: genList (port: "${prefix}${builtins.toString port}"); + mkInterfaces = + { supportPoE, interfaces }: + listToAttrs ( + builtins.map (int: { + name = int; + value = { + inherit supportPoE; + }; + }) interfaces + ); + + cfg = config.dgn-hardware; +in + +{ + options.dgn-hardware = { + model = mkOption { + type = enum [ + "EX2300-48P" + "EX4100-F-48P" + "EX4400-24X" + "EX4400-EM-4Y" + ]; + description = '' + The exact model of the switch to configure. + ''; + }; + }; + + config = { + netconf.mandatoryInterfaces = + let + ports = import ./. + "${cfg.model}.nix" range; + in + (mkInterfaces { + supportPoE = true; + interfaces = ports.poe; + }) + // (mkInterfaces { + supportPoE = false; + interfaces = ports.regular; + }); + }; +}