QoL module improvement && addresses instead of address

This commit is contained in:
catvayor 2024-09-03 23:38:29 +02:00
parent 681db54504
commit e8c9d47754
Signed by: lbailly
GPG key ID: CE3E645251AC63F3
4 changed files with 100 additions and 113 deletions

View file

@ -55,7 +55,7 @@ let
};
modules = [
./junos
./ex2300.nix
./dgn-module.nix
hive_mod
module_inst
];

View file

@ -2,36 +2,67 @@
with lib;
let
intf-mod =
{ name, ... }:
{ name, config, ... }:
{
options = {
enable = mkEnableOption "The interface ${name}.";
poe = mkEnableOption "The PoE on interface ${name}.";
enable = mkEnableOption "this interface" // {
default = config.inet.enable || config.inet6.enable || config.ethernet-switching.enable;
defaultText = ''config.inet.enable || config.inet6.enable || config.ethernet-switching.enable'';
};
poe = mkEnableOption "the PoE on this interface";
ethernet-switching = {
enable = mkEnableOption "The ethernet switching on interface ${name}.";
enable = mkEnableOption "the ethernet switching on this interface" // {
default = config.ethernet-switching.interface-mode != null;
defaultText = ''config.ethernet-switching.interface-mode != null'';
};
interface-mode = mkOption {
type = types.enum [
"trunk"
"access"
];
type = types.nullOr (
types.enum [
"trunk"
"access"
]
);
default = null;
description = ''
Mode of operation for vlan addressing of this interface.
"trunk" means that the traffic is tagged, "access" means the
traffic is tagged by the switch.
Use null to desactivate the switching.
'';
};
vlans = mkOption {
type = types.listOf (types.either types.str types.ints.unsigned);
default = [ ];
description = ''
Vlans that can be used on this interface.
Only one ID should be here for "access" mode of operation.
'';
};
};
inet = {
enable = mkEnableOption "The ipv4 on the interface ${name}.";
address = mkOption {
enable = mkEnableOption "the ipv4 on this interface" // {
default = config.inet.addresses != [ ];
defaultText = ''config.inet.addresses != [ ]'';
};
addresses = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
ipv4 addresses of this interface.
'';
};
};
inet6 = {
enable = mkEnableOption "The ipv6 on the interface ${name}.";
address = mkOption {
enable = mkEnableOption "the ipv6 on this interface" // {
default = config.inet6.addresses != [ ];
defaultText = ''config.inet6.addresses != [ ]'';
};
addresses = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
ipv6 addresses of this interface.
'';
};
};
};
@ -44,12 +75,20 @@ in
options.dgn-interfaces = mkOption {
type = types.attrsOf (types.submodule intf-mod);
default = { };
description = ''
Unified configuration of interfaces adapted to DGNum usage:
- each interfaces have only one logical subinterface;
- enabling ethernet-switching also enable RSTP;
- automatic enabling interface and relevant config family when configuring;
- allows enabling PoE along other configurations.
'';
};
config = {
interfaces = mapAttrs (_: intf: {
inherit (intf) enable;
unit."0".family = {
inherit (intf) inet inet6 ethernet-switching;
inherit (intf) inet inet6;
ethernet-switching = mkIf intf.ethernet-switching.enable intf.ethernet-switching;
};
}) cfg;
poe.interfaces = filterAttrs (

View file

@ -40,7 +40,7 @@ let
#TODO : DHCP
inet = {
enable = mkEnableOption "the IPv4 configuration of this logical interface";
address = mkOption {
addresses = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
@ -50,7 +50,7 @@ let
};
inet6 = {
enable = mkEnableOption "the IPv6 configuration of this logical interface";
address = mkOption {
addresses = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
@ -78,14 +78,14 @@ let
</ethernet-switching>
'';
addr4 = map (addr: "<name>${addr}</name>") config.family.inet.address;
addr4 = map (addr: "<name>${addr}</name>") config.family.inet.addresses;
inet = optionalString config.family.inet.enable ''
<inet>
<address>${builtins.concatStringsSep "" addr4}</address>
</inet>
'';
addr6 = map (addr: "<name>${addr}</name>") config.family.inet6.address;
addr6 = map (addr: "<name>${addr}</name>") config.family.inet6.addresses;
inet6 = optionalString config.family.inet6.enable ''
<inet6>
<address>${builtins.concatStringsSep "" addr6}</address>

View file

@ -17,9 +17,8 @@ let
"ap-staging".id = 2000;
};
AP = {
enable = true;
poe = true;
ethernet-switching = {
enable = true;
interface-mode = "trunk";
vlans = [
"users"
@ -28,10 +27,8 @@ let
};
};
AP-staging = {
enable = true;
poe = true;
ethernet-switching = {
enable = true;
interface-mode = "access";
vlans = [ "ap-staging" ];
};
@ -40,7 +37,7 @@ in
{
netcore02 = {
deployment.targetHost = "netcore02.dgn";
imports = [ ./dgn-module.nix ];
imports = [ ./ex2300.nix ];
vlans = vlansPlan;
dgn-interfaces = {
# "ge-0/0/0" = AP-staging;
@ -62,88 +59,54 @@ in
# "ge-0/0/16" = AP-staging;
# "ge-0/0/17" = AP-staging;
"ge-0/0/42" = {
enable = true;
ethernet-switching = {
enable = true;
interface-mode = "trunk";
vlans = [ "all" ];
};
# oob
"ge-0/0/42".ethernet-switching = {
interface-mode = "trunk";
vlans = [ "all" ];
};
# AP de test
"ge-0/0/43" = AP-staging;
"ge-0/0/46" = {
# uplink oob
enable = true;
ethernet-switching = {
enable = true;
interface-mode = "access";
vlans = [ 500 ];
};
# uplink oob
"ge-0/0/46".ethernet-switching = {
interface-mode = "access";
vlans = [ 500 ];
};
"ge-0/0/47" = {
# ilo
enable = true;
ethernet-switching = {
enable = true;
interface-mode = "access";
vlans = [ "admin-core" ];
};
# ilo
"ge-0/0/47".ethernet-switching = {
interface-mode = "access";
vlans = [ "admin-core" ];
};
"xe-0/1/0" = {
# router
enable = true;
ethernet-switching = {
enable = true;
interface-mode = "trunk";
vlans = [ "all" ];
};
# router
"xe-0/1/0".ethernet-switching = {
interface-mode = "trunk";
vlans = [ "all" ];
};
"xe-0/1/1" = {
# netaccess01
enable = true;
ethernet-switching = {
enable = true;
interface-mode = "trunk";
vlans = [
"users"
"ap-staging"
"admin-ap"
"admin-core"
];
};
# netaccess01
"xe-0/1/1".ethernet-switching = {
interface-mode = "trunk";
vlans = [
"users"
"ap-staging"
"admin-ap"
"admin-core"
];
};
"ge-0/1/3" = {
# uplink
enable = true;
ethernet-switching = {
enable = true;
interface-mode = "trunk";
vlans = [ "uplink-cri" ];
};
# uplink
"ge-0/1/3".ethernet-switching = {
interface-mode = "trunk";
vlans = [ "uplink-cri" ];
};
"me0" = {
enable = true;
inet = {
enable = true;
address = [ "192.168.42.6/24" ];
};
};
"irb" = {
enable = true;
inet6 = {
enable = true;
address = [ "fd26:baf9:d250:8000::1001/64" ];
};
};
# management
"me0".inet.addresses = [ "192.168.42.6/24" ];
"irb".inet6.addresses = [ "fd26:baf9:d250:8000::1001/64" ];
};
};
netaccess01 = {
deployment.targetHost = "netaccess01.dgn";
imports = [ ./dgn-module.nix ];
imports = [ ./ex2300.nix ];
vlans = vlansPlan;
dgn-interfaces = {
@ -154,30 +117,15 @@ in
# "ge-0/0/4" = AP-staging;
# "ge-0/0/5" = AP-staging;
"xe-0/1/0" = {
enable = true;
ethernet-switching = {
enable = true;
interface-mode = "trunk";
vlans = [ "all" ];
};
# netcore02
"xe-0/1/0".ethernet-switching = {
interface-mode = "trunk";
vlans = [ "all" ];
};
"me0" = {
enable = true;
inet = {
enable = true;
address = [ "192.168.42.6/24" ];
};
};
"irb" = {
enable = true;
inet6 = {
enable = true;
address = [ "fd26:baf9:d250:8000::2001/64" ];
};
};
# management
"me0".inet.addresses = [ "192.168.42.6/24" ];
"irb".inet6.addresses = [ "fd26:baf9:d250:8000::2001/64" ];
};
};
}