QoL module
This commit is contained in:
parent
64915f75de
commit
0585581455
4 changed files with 112 additions and 60 deletions
60
dgn-module.nix
Normal file
60
dgn-module.nix
Normal file
|
@ -0,0 +1,60 @@
|
|||
{ config, lib, ... }:
|
||||
with lib;
|
||||
let
|
||||
intf-mod =
|
||||
{ name, ... }:
|
||||
{
|
||||
options = {
|
||||
enable = mkEnableOption "The interface ${name}.";
|
||||
poe = mkEnableOption "The PoE on interface ${name}.";
|
||||
ethernet-switching = {
|
||||
enable = mkEnableOption "The ethernet switching on interface ${name}.";
|
||||
interface-mode = mkOption {
|
||||
type = types.enum [
|
||||
"trunk"
|
||||
"access"
|
||||
];
|
||||
};
|
||||
vlans = mkOption {
|
||||
type = types.listOf (types.either types.str types.ints.unsigned);
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
inet = {
|
||||
enable = mkEnableOption "The ipv4 on the interface ${name}.";
|
||||
address = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
inet6 = {
|
||||
enable = mkEnableOption "The ipv6 on the interface ${name}.";
|
||||
address = mkOption {
|
||||
type = types.listOf types.str;
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
cfg = config.dgn-interfaces;
|
||||
intf-list = config.netconf.mandatoryInterfaces;
|
||||
in
|
||||
{
|
||||
options.dgn-interfaces = mkOption {
|
||||
type = types.attrsOf (types.submodule intf-mod);
|
||||
default = { };
|
||||
};
|
||||
config = {
|
||||
interfaces = mapAttrs (_: intf: {
|
||||
inherit (intf) enable;
|
||||
unit."0".family = {
|
||||
inherit (intf) inet inet6 ethernet-switching;
|
||||
};
|
||||
}) cfg;
|
||||
poe.interfaces = filterAttrs (
|
||||
name: _: config.netconf.mandatoryInterfaces.${name}.supportPoE or false
|
||||
) (mapAttrs (_: intf: { enable = intf.poe; }) cfg);
|
||||
protocols.rstp = attrNames (filterAttrs (_: intf: intf.ethernet-switching.enable) cfg);
|
||||
};
|
||||
}
|
23
ex2300.nix
23
ex2300.nix
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
netconf.mandatoryInterfaces = [
|
||||
{ lib, ... }:
|
||||
let
|
||||
poe = [
|
||||
"ge-0/0/0"
|
||||
"ge-0/0/1"
|
||||
"ge-0/0/2"
|
||||
|
@ -48,7 +49,8 @@
|
|||
"ge-0/0/45"
|
||||
"ge-0/0/46"
|
||||
"ge-0/0/47"
|
||||
|
||||
];
|
||||
non_poe = [
|
||||
"ge-0/1/0"
|
||||
"ge-0/1/1"
|
||||
"ge-0/1/2"
|
||||
|
@ -59,4 +61,19 @@
|
|||
"xe-0/1/2"
|
||||
"xe-0/1/3"
|
||||
];
|
||||
in
|
||||
{
|
||||
netconf.mandatoryInterfaces =
|
||||
lib.listToAttrs (
|
||||
map (name: {
|
||||
inherit name;
|
||||
value.supportPoE = true;
|
||||
}) poe
|
||||
)
|
||||
// lib.listToAttrs (
|
||||
map (name: {
|
||||
inherit name;
|
||||
value.supportPoE = false;
|
||||
}) non_poe
|
||||
);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,13 @@
|
|||
...
|
||||
}:
|
||||
with lib;
|
||||
let
|
||||
mandatory.options = {
|
||||
supportPoE = mkOption {
|
||||
type = types.bool;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./protocols.nix
|
||||
|
@ -17,16 +24,15 @@ with lib;
|
|||
type = types.str;
|
||||
readOnly = true;
|
||||
};
|
||||
netconf.mandatoryInterfaces = mkOption { type = types.listOf types.str; };
|
||||
netconf.mandatoryInterfaces = mkOption { type = types.attrsOf (types.submodule mandatory); };
|
||||
};
|
||||
config.interfaces =
|
||||
let
|
||||
mkIntf = name: {
|
||||
inherit name;
|
||||
value.enable = mkDefault false;
|
||||
mkIntf = _: _: {
|
||||
enable = mkDefault false;
|
||||
};
|
||||
in
|
||||
listToAttrs (map mkIntf config.netconf.mandatoryInterfaces);
|
||||
mapAttrs mkIntf config.netconf.mandatoryInterfaces;
|
||||
config.netconf.xmls.configuration = ''
|
||||
<configuration>
|
||||
${config.netconf.xmls.interfaces}
|
||||
|
|
|
@ -18,7 +18,7 @@ let
|
|||
};
|
||||
AP = {
|
||||
enable = true;
|
||||
unit."0".family.ethernet-switching = {
|
||||
ethernet-switching = {
|
||||
enable = true;
|
||||
interface-mode = "trunk";
|
||||
vlans = [
|
||||
|
@ -29,7 +29,8 @@ let
|
|||
};
|
||||
AP-staging = {
|
||||
enable = true;
|
||||
unit."0".family.ethernet-switching = {
|
||||
poe = true;
|
||||
ethernet-switching = {
|
||||
enable = true;
|
||||
interface-mode = "access";
|
||||
vlans = [ "ap-staging" ];
|
||||
|
@ -39,35 +40,9 @@ in
|
|||
{
|
||||
netcore02 = {
|
||||
deployment.targetHost = "netcore02.dgn";
|
||||
imports = [ ./dgn-module.nix ];
|
||||
vlans = vlansPlan;
|
||||
protocols.rstp = [
|
||||
# "ge-0/0/0"
|
||||
# "ge-0/0/1"
|
||||
# "ge-0/0/2"
|
||||
# "ge-0/0/3"
|
||||
# "ge-0/0/4"
|
||||
# "ge-0/0/5"
|
||||
# "ge-0/0/6"
|
||||
# "ge-0/0/7"
|
||||
# "ge-0/0/8"
|
||||
# "ge-0/0/9"
|
||||
# "ge-0/0/10"
|
||||
# "ge-0/0/11"
|
||||
# "ge-0/0/12"
|
||||
# "ge-0/0/13"
|
||||
# "ge-0/0/14"
|
||||
# "ge-0/0/15"
|
||||
# "ge-0/0/16"
|
||||
# "ge-0/0/17"
|
||||
"ge-0/0/42"
|
||||
"ge-0/0/43"
|
||||
"ge-0/0/47"
|
||||
|
||||
"xe-0/1/0"
|
||||
"xe-0/1/1"
|
||||
"ge-0/1/3"
|
||||
];
|
||||
interfaces = {
|
||||
dgn-interfaces = {
|
||||
# "ge-0/0/0" = AP-staging;
|
||||
# "ge-0/0/1" = AP-staging;
|
||||
# "ge-0/0/2" = AP-staging;
|
||||
|
@ -89,7 +64,7 @@ in
|
|||
|
||||
"ge-0/0/42" = {
|
||||
enable = true;
|
||||
unit."0".family.ethernet-switching = {
|
||||
ethernet-switching = {
|
||||
enable = true;
|
||||
interface-mode = "trunk";
|
||||
vlans = [ "all" ];
|
||||
|
@ -99,7 +74,7 @@ in
|
|||
"ge-0/0/46" = {
|
||||
# uplink oob
|
||||
enable = true;
|
||||
unit."0".family.ethernet-switching = {
|
||||
ethernet-switching = {
|
||||
enable = true;
|
||||
interface-mode = "access";
|
||||
vlans = [ 500 ];
|
||||
|
@ -108,7 +83,7 @@ in
|
|||
"ge-0/0/47" = {
|
||||
# ilo
|
||||
enable = true;
|
||||
unit."0".family.ethernet-switching = {
|
||||
ethernet-switching = {
|
||||
enable = true;
|
||||
interface-mode = "access";
|
||||
vlans = [ "admin-core" ];
|
||||
|
@ -116,16 +91,18 @@ in
|
|||
};
|
||||
|
||||
"xe-0/1/0" = {
|
||||
# router
|
||||
enable = true;
|
||||
unit."0".family.ethernet-switching = {
|
||||
ethernet-switching = {
|
||||
enable = true;
|
||||
interface-mode = "trunk";
|
||||
vlans = [ "all" ];
|
||||
};
|
||||
};
|
||||
"xe-0/1/1" = {
|
||||
# netaccess01
|
||||
enable = true;
|
||||
unit."0".family.ethernet-switching = {
|
||||
ethernet-switching = {
|
||||
enable = true;
|
||||
interface-mode = "trunk";
|
||||
vlans = [
|
||||
|
@ -137,8 +114,9 @@ in
|
|||
};
|
||||
};
|
||||
"ge-0/1/3" = {
|
||||
# uplink
|
||||
enable = true;
|
||||
unit."0".family.ethernet-switching = {
|
||||
ethernet-switching = {
|
||||
enable = true;
|
||||
interface-mode = "trunk";
|
||||
vlans = [ "uplink-cri" ];
|
||||
|
@ -147,7 +125,7 @@ in
|
|||
|
||||
"me0" = {
|
||||
enable = true;
|
||||
unit."0".family.inet = {
|
||||
inet = {
|
||||
enable = true;
|
||||
address = [ "192.168.42.6/24" ];
|
||||
};
|
||||
|
@ -155,7 +133,7 @@ in
|
|||
|
||||
"irb" = {
|
||||
enable = true;
|
||||
unit."0".family.inet6 = {
|
||||
inet6 = {
|
||||
enable = true;
|
||||
address = [ "fd26:baf9:d250:8000::1001/64" ];
|
||||
};
|
||||
|
@ -165,19 +143,10 @@ in
|
|||
netaccess01 = {
|
||||
deployment.targetHost = "netaccess01.dgn";
|
||||
|
||||
imports = [ ./dgn-module.nix ];
|
||||
vlans = vlansPlan;
|
||||
|
||||
protocols.rstp = [
|
||||
# "ge-0/0/0"
|
||||
# "ge-0/0/1"
|
||||
# "ge-0/0/2"
|
||||
# "ge-0/0/3"
|
||||
# "ge-0/0/4"
|
||||
# "ge-0/0/5"
|
||||
|
||||
"xe-0/1/0"
|
||||
];
|
||||
interfaces = {
|
||||
dgn-interfaces = {
|
||||
# "ge-0/0/0" = AP-staging;
|
||||
# "ge-0/0/1" = AP-staging;
|
||||
# "ge-0/0/2" = AP-staging;
|
||||
|
@ -187,7 +156,7 @@ in
|
|||
|
||||
"xe-0/1/0" = {
|
||||
enable = true;
|
||||
unit."0".family.ethernet-switching = {
|
||||
ethernet-switching = {
|
||||
enable = true;
|
||||
interface-mode = "trunk";
|
||||
vlans = [ "all" ];
|
||||
|
@ -196,7 +165,7 @@ in
|
|||
|
||||
"me0" = {
|
||||
enable = true;
|
||||
unit."0".family.inet = {
|
||||
inet = {
|
||||
enable = true;
|
||||
address = [ "192.168.42.6/24" ];
|
||||
};
|
||||
|
@ -204,7 +173,7 @@ in
|
|||
|
||||
"irb" = {
|
||||
enable = true;
|
||||
unit."0".family.inet6 = {
|
||||
inet6 = {
|
||||
enable = true;
|
||||
address = [ "fd26:baf9:d250:8000::2001/64" ];
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue