feat(netconf): toplevel rpc drv

This commit is contained in:
catvayor 2024-12-15 20:40:51 +01:00 committed by Tom Hubrecht
parent 9601caba4f
commit e8cdd06706
Signed by: thubrecht
SSH key fingerprint: SHA256:CYNvFo44Ar9qCNnWNnvJVhs0QXO9AZjOLlPeWcSij3Q
2 changed files with 74 additions and 39 deletions

View file

@ -126,11 +126,14 @@ in
}; };
netconf = { netconf = {
evalConfig = (import nixpkgs.nixos.unstable.path { }).lib.evalModules; evalConfig = nixpkgs.nixos.unstable.lib.evalModules;
defaults = defaults =
{ nodeMeta, nodePath, ... }: { nodeMeta, nodePath, ... }:
{ {
_module.args = {
pkgs = nixpkgs.nixos.unstable;
};
# Import the default modules # Import the default modules
imports = [ imports = [
# Import the base configuration for each node # Import the base configuration for each node

View file

@ -1,4 +1,10 @@
{ config, lib, ... }: {
config,
lib,
pkgs,
name,
...
}:
let let
inherit (lib) mapAttrs mkOption; inherit (lib) mapAttrs mkOption;
@ -9,6 +15,7 @@ let
str str
any any
submodule submodule
package
; ;
mandatory.options = { mandatory.options = {
@ -36,45 +43,70 @@ in
type = attrsOf any; type = attrsOf any;
default = { }; default = { };
}; };
netconf.xmls.configuration = mkOption { netconf = {
type = str; xmls.configuration = mkOption {
readOnly = true; type = str;
description = '' readOnly = true;
The full configuration to send to a JunOS. description = ''
''; The full configuration to send to a JunOS.
}; '';
netconf.mandatoryInterfaces = mkOption {
type = attrsOf (submodule mandatory);
example = {
"ge-0/0/0" = {
supportPoE = true;
};
"ge-0/0/1" = {
supportPoE = true;
};
"xe-0/0/0" = {
supportPoE = false;
};
}; };
description = '' mandatoryInterfaces = mkOption {
JunOS require some interfaces to always be configured (even if they are disabled), type = attrsOf (submodule mandatory);
which correspond to physical interfaces of the switch. They have to be declared here example = {
with some information about it (only if it supports PoE for now). "ge-0/0/0" = {
supportPoE = true;
};
"ge-0/0/1" = {
supportPoE = true;
};
"xe-0/0/0" = {
supportPoE = false;
};
};
description = ''
JunOS require some interfaces to always be configured (even if they are disabled),
which correspond to physical interfaces of the switch. They have to be declared here
with some information about it (only if it supports PoE for now).
'';
};
rpc = mkOption {
type = package;
readOnly = true;
};
};
};
config = {
interfaces =
let
mkIntf = _: _: { };
in
mapAttrs mkIntf config.netconf.mandatoryInterfaces;
netconf = {
xmls.configuration = with config.netconf.xmls; ''
<configuration>
${system}
${interfaces}
${protocols}
${vlans}
${poe}
</configuration>
'';
rpc = pkgs.writeText "${name}.rpc" ''
<rpc>
<edit-config>
<config>
${config.netconf.xmls.configuration}
</config>
<target>
<candidate/>
</target>
</edit-config>
</rpc>
<rpc>
<commit/>
</rpc>
''; '';
}; };
}; };
config.interfaces =
let
mkIntf = _: _: { };
in
mapAttrs mkIntf config.netconf.mandatoryInterfaces;
config.netconf.xmls.configuration = with config.netconf.xmls; ''
<configuration>
${system}
${interfaces}
${protocols}
${vlans}
${poe}
</configuration>
'';
} }