making from an hive

This commit is contained in:
catvayor 2024-04-06 23:11:39 +02:00
parent 1c863a8495
commit 711886e79f
3 changed files with 106 additions and 67 deletions

View file

@ -1,47 +1,6 @@
let module_inst = { { pkgs ? (import <nixpkgs> {}) }:
interfaces = let let
AP = { # AP moduleEX2300 = import ./moduleMaker.nix [
enable = true;
interface-mode = "trunk";
vlans = [ "users" "admin" ];
};
off.enable = false;
in {
"ge-0/0/12" = AP;
"ge-0/0/13" = AP;
"ge-0/0/14" = AP;
"ge-0/0/15" = AP;
"ge-0/0/16" = AP;
"ge-0/0/17" = AP;
"ge-0/1/1" = {
enable = true;
interface-mode = "trunk";
vlans = [ "uplink-cri" ];
};
"xe-0/1/0" = { # upstream
enable = true;
interface-mode = "trunk";
vlans = [ "all" ];
dhcp_trusted = true;
};
"me0" = { # mgmt
enable = true;
management = "192.168.42.6/24";
};
};
vlans = {
"users".ids = [ { begin = 3045; end = 4094; } ];
"admin" = {
ids = 3000;
management = "10.0.0.2/22";
};
"uplink-cri".ids = [ 223 ];
};
};
module = import ./moduleMaker.nix [
"ge-0/0/0" "ge-0/0/0"
"ge-0/0/1" "ge-0/0/1"
"ge-0/0/2" "ge-0/0/2"
@ -103,11 +62,17 @@ let module_inst = {
"me0" "me0"
]; ];
in (import <nixpkgs/lib>).evalModules { evaluator = name: module_inst:
specialArgs.pkgs = import <nixpkgs> {}; let cfg = pkgs.lib.evalModules {
modules = [ specialArgs = { inherit pkgs name; };
module modules = [
module_inst moduleEX2300
]; module_inst
} ];
};
in "ln -s ${cfg.config.deployement.cmd} $out/${name}";
hive = import ./netconf-hive.nix;
cmds = builtins.attrValues (builtins.mapAttrs evaluator hive);
in
pkgs.runCommand "netconf-deploy" {}
(builtins.concatStringsSep "\n" ([ "mkdir $out" ] ++ cmds))

View file

@ -1,8 +1,17 @@
interfaces: interfaces:
{ lib, pkgs, config, ... }: { name, lib, pkgs, config, ... }:
let cfg = config; let cfg = config;
in with lib; { in with lib; {
options = { options = {
deployement = {
targetHost = mkOption {
type = types.str;
};
cmd = mkOption {
type = types.package;
readOnly = true;
};
};
vlans = let vlans = let
range_type.options = { range_type.options = {
begin = mkOption { type = types.ints.unsigned; }; begin = mkOption { type = types.ints.unsigned; };
@ -16,7 +25,7 @@ in with lib; {
default = [ ]; default = [ ];
}; };
management = mkOption { management = mkOption {
# FIXME : support ipv4 and ipv6, either static or dhcp (with the coffee) # FIXME : support ipv4, either static or dhcp (with the coffee)
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;
description = '' description = ''
@ -47,21 +56,15 @@ in with lib; {
default = false; default = false;
}; };
management = mkOption { management = mkOption {
# FIXME : support ipv4 and ipv6, either static or dhcp (with the coffee) # FIXME : support ipv6, either static or dhcp (with the coffee)
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;
}; };
}; };
in builtins.listToAttrs (map (name: { inherit name; value = template name; }) interfaces); in builtins.listToAttrs (map (name: { inherit name; value = template name; }) interfaces);
toplevel = mkOption {
type = types.unspecified;
visible = false;
readOnly = true;
};
}; };
config.toplevel = let config.deployement.cmd = let
intf_xmlGen = name: let intf_xmlGen = name: let
disable_flag = if !cfg.interfaces.${name}.enable then "<disable/>" else ""; disable_flag = if !cfg.interfaces.${name}.enable then "<disable/>" else "";
# FIXME : need to enforce address in reality # FIXME : need to enforce address in reality
@ -140,9 +143,9 @@ in with lib; {
<unit> <unit>
<name>0</name> <name>0</name>
<family> <family>
<inet> <inet6>
<address><name>${addr}</name></address> <address><name>${addr}</name></address>
</inet> </inet6>
</family> </family>
</unit> </unit>
</interface> </interface>
@ -162,7 +165,7 @@ in with lib; {
${builtins.concatStringsSep "\n" vlans} ${builtins.concatStringsSep "\n" vlans}
</vlans> </vlans>
''; '';
rpc_requests = pkgs.writeText "config_rpc.xml" '' rpc_requests = pkgs.writeText "config-${name}_rpc.xml" ''
<rpc> <rpc>
<edit-config> <edit-config>
<config> <config>
@ -179,8 +182,8 @@ in with lib; {
<commit/> <commit/>
</rpc> </rpc>
''; '';
in pkgs.writeShellScript "deploy.sh" '' in pkgs.writeShellScript "deploy-${name}.sh" ''
${pkgs.openssh}/bin/ssh jourdan01.dgn -p 830 -s netconf < ${rpc_requests} ${pkgs.openssh}/bin/ssh ${cfg.deployement.targetHost} -p 830 -s netconf < ${rpc_requests}
'' ''
; ;
} }

71
netconf-hive.nix Normal file
View file

@ -0,0 +1,71 @@
let
vlansPlan = mgmt: {
"uplink-cri".ids = 223;
"admin-core" = {
ids = 3000;
management = mgmt;
};
"admin-ap".ids = 3001;
"users".ids = [ { begin = 3045; end = 4094; } ];
};
AP = {
enable = true;
interface-mode = "trunk";
vlans = [ "users" "admin-ap" ];
};
in {
netcore01 = {
deployement.targetHost = "jourdan01.dgn";
vlans = vlansPlan "fd26:baf9:d250:8000::1001/64";
interfaces = {
"ge-0/0/12" = AP;
"ge-0/0/13" = AP;
"ge-0/0/14" = AP;
"ge-0/0/15" = AP;
"ge-0/0/16" = AP;
"ge-0/0/17" = AP;
"xe-0/1/0" = {
enable = true;
interface-mode = "trunk";
vlans = [ "all" ];
dhcp_trusted = true;
};
"xe-0/1/1" = {
enable = true;
interface-mode = "trunk";
vlans = [ "users" "admin-ap" "admin-core" ];
};
"ge-0/1/3" = {
enable = true;
interface-mode = "trunk";
vlans = [ "uplink-cri" ];
};
"me0" = {
enable = true;
management = "192.168.42.6/24";
};
};
};
netaccess01 = {
deployement.targetHost = "jourdan02.dgn";
vlans = vlansPlan "fd26:baf9:d250:8000::2001/64";
interfaces = {
"xe-0/1/0" = {
enable = true;
interface-mode = "trunk";
vlans = [ "all" ];
dhcp_trusted = true;
};
"me0" = {
enable = true;
management = "192.168.42.6/24";
};
};
};
}