From 711886e79fc49a81fc3bde0a9584d56d13e03b47 Mon Sep 17 00:00:00 2001 From: catvayor Date: Sat, 6 Apr 2024 23:11:39 +0200 Subject: [PATCH] making from an hive --- configMaker.nix | 69 ++++++++++++---------------------------------- moduleMaker.nix | 33 ++++++++++++---------- netconf-hive.nix | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 67 deletions(-) create mode 100644 netconf-hive.nix diff --git a/configMaker.nix b/configMaker.nix index f818513..f2e6fe1 100644 --- a/configMaker.nix +++ b/configMaker.nix @@ -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 {}) }: +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 ).evalModules { - specialArgs.pkgs = import {}; - modules = [ - module - module_inst - ]; -} - + evaluator = name: module_inst: + let cfg = pkgs.lib.evalModules { + specialArgs = { inherit pkgs name; }; + modules = [ + 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)) diff --git a/moduleMaker.nix b/moduleMaker.nix index a6b5c8d..449997e 100644 --- a/moduleMaker.nix +++ b/moduleMaker.nix @@ -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 "" else ""; # FIXME : need to enforce address in reality @@ -140,9 +143,9 @@ in with lib; { 0 - +
${addr}
-
+
@@ -162,7 +165,7 @@ in with lib; { ${builtins.concatStringsSep "\n" vlans} ''; - rpc_requests = pkgs.writeText "config_rpc.xml" '' + rpc_requests = pkgs.writeText "config-${name}_rpc.xml" '' @@ -179,8 +182,8 @@ in with lib; { ''; - 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} '' ; } diff --git a/netconf-hive.nix b/netconf-hive.nix new file mode 100644 index 0000000..1c6a1c5 --- /dev/null +++ b/netconf-hive.nix @@ -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"; + }; + }; + }; +}