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 = {
interfaces = let
AP = { # AP
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 [
{ pkgs ? (import <nixpkgs> {}) }:
let
moduleEX2300 = import ./moduleMaker.nix [
"ge-0/0/0"
"ge-0/0/1"
"ge-0/0/2"
@ -103,11 +62,17 @@ let module_inst = {
"me0"
];
in (import <nixpkgs/lib>).evalModules {
specialArgs.pkgs = import <nixpkgs> {};
evaluator = name: module_inst:
let cfg = pkgs.lib.evalModules {
specialArgs = { inherit pkgs name; };
modules = [
module
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:
{ lib, pkgs, config, ... }:
{ name, lib, pkgs, config, ... }:
let cfg = config;
in with lib; {
options = {
deployement = {
targetHost = mkOption {
type = types.str;
};
cmd = mkOption {
type = types.package;
readOnly = true;
};
};
vlans = let
range_type.options = {
begin = mkOption { type = types.ints.unsigned; };
@ -16,7 +25,7 @@ in with lib; {
default = [ ];
};
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;
default = null;
description = ''
@ -47,21 +56,15 @@ in with lib; {
default = false;
};
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;
default = null;
};
};
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
disable_flag = if !cfg.interfaces.${name}.enable then "<disable/>" else "";
# FIXME : need to enforce address in reality
@ -140,9 +143,9 @@ in with lib; {
<unit>
<name>0</name>
<family>
<inet>
<inet6>
<address><name>${addr}</name></address>
</inet>
</inet6>
</family>
</unit>
</interface>
@ -162,7 +165,7 @@ in with lib; {
${builtins.concatStringsSep "\n" vlans}
</vlans>
'';
rpc_requests = pkgs.writeText "config_rpc.xml" ''
rpc_requests = pkgs.writeText "config-${name}_rpc.xml" ''
<rpc>
<edit-config>
<config>
@ -179,8 +182,8 @@ in with lib; {
<commit/>
</rpc>
'';
in pkgs.writeShellScript "deploy.sh" ''
${pkgs.openssh}/bin/ssh jourdan01.dgn -p 830 -s netconf < ${rpc_requests}
in pkgs.writeShellScript "deploy-${name}.sh" ''
${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";
};
};
};
}