feat(modules/netconf): Add hardware module
This commit is contained in:
parent
c5e3da3ac9
commit
fbfb22d777
6 changed files with 89 additions and 0 deletions
6
modules/netconf/default.nix
Normal file
6
modules/netconf/default.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
imports = [
|
||||
# List of modules to import
|
||||
./dgn-hardware
|
||||
];
|
||||
}
|
6
modules/netconf/dgn-hardware/EX2300-48P.nix
Normal file
6
modules/netconf/dgn-hardware/EX2300-48P.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
range:
|
||||
|
||||
{
|
||||
poe = range "ge-0/0/" 48;
|
||||
regular = (range "ge-0/1/" 4) ++ (range "xe-0/1/" 4);
|
||||
}
|
13
modules/netconf/dgn-hardware/EX4100-F-48P.nix
Normal file
13
modules/netconf/dgn-hardware/EX4100-F-48P.nix
Normal 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);
|
||||
}
|
6
modules/netconf/dgn-hardware/EX4400-24X.nix
Normal file
6
modules/netconf/dgn-hardware/EX4400-24X.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
range:
|
||||
|
||||
{
|
||||
poe = [ ];
|
||||
regular = (range "ge-0/0/" 24) ++ (range "xe-0/0/" 24) ++ (range "et-0/1/" 2);
|
||||
}
|
6
modules/netconf/dgn-hardware/EX4400-EM-4Y.nix
Normal file
6
modules/netconf/dgn-hardware/EX4400-EM-4Y.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
range:
|
||||
|
||||
{
|
||||
poe = [ ];
|
||||
regular = (range "ge-0/2/" 4) ++ (range "xe-0/2/" 4) ++ (range "et-0/2/" 4);
|
||||
}
|
52
modules/netconf/dgn-hardware/default.nix
Normal file
52
modules/netconf/dgn-hardware/default.nix
Normal 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;
|
||||
});
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue