Netconf-Module/junos/poe.nix

52 lines
1 KiB
Nix
Raw Normal View History

2024-08-31 18:54:15 +02:00
{ lib, config, ... }:
let
2024-12-13 14:37:43 +01:00
inherit (lib)
mkOption
mkEnableOption
mapAttrsToList
optionalString
;
inherit (lib.types)
str
attrsOf
submodule
;
2024-08-31 18:54:15 +02:00
interface-module =
{ name, config, ... }:
{
options = {
2024-09-03 23:04:30 +02:00
enable = mkEnableOption "the PoE for this interface";
2024-08-31 18:54:15 +02:00
xml = mkOption {
2024-12-13 14:37:43 +01:00
type = str;
2024-08-31 18:54:15 +02:00
visible = false;
readOnly = true;
};
};
config.xml = ''
<interface><name>${name}</name>${optionalString (!config.enable) "<disable/>"}</interface>
'';
};
in
{
options = {
poe.interfaces = mkOption {
2024-12-13 14:37:43 +01:00
type = attrsOf (submodule interface-module);
2024-08-31 18:54:15 +02:00
default = { };
2024-09-03 23:04:30 +02:00
description = ''
PoE configuration of interfaces.
'';
2024-08-31 18:54:15 +02:00
};
netconf.xmls.poe = mkOption {
2024-12-13 14:37:43 +01:00
type = str;
2024-08-31 18:54:15 +02:00
visible = false;
readOnly = true;
};
};
config.netconf.xmls.poe = ''
<poe operation="replace">
2024-12-13 14:37:43 +01:00
${builtins.concatStringsSep "" (mapAttrsToList (_: intf: intf.xml) config.poe.interfaces)}
2024-08-31 18:54:15 +02:00
</poe>
'';
}