feat(modules/netconf): Add hardware module

This commit is contained in:
Tom Hubrecht 2024-12-09 11:10:28 +01:00
parent c5e3da3ac9
commit fbfb22d777
Signed by: thubrecht
SSH key fingerprint: SHA256:CYNvFo44Ar9qCNnWNnvJVhs0QXO9AZjOLlPeWcSij3Q
6 changed files with 89 additions and 0 deletions

View file

@ -0,0 +1,6 @@
{
imports = [
# List of modules to import
./dgn-hardware
];
}

View file

@ -0,0 +1,6 @@
range:
{
poe = range "ge-0/0/" 48;
regular = (range "ge-0/1/" 4) ++ (range "xe-0/1/" 4);
}

View file

@ -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);
}

View file

@ -0,0 +1,6 @@
range:
{
poe = [ ];
regular = (range "ge-0/0/" 24) ++ (range "xe-0/0/" 24) ++ (range "et-0/1/" 2);
}

View file

@ -0,0 +1,6 @@
range:
{
poe = [ ];
regular = (range "ge-0/2/" 4) ++ (range "xe-0/2/" 4) ++ (range "et-0/2/" 4);
}

View file

@ -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;
});
};
}