lib/config/options: add assertions for switch links
This commit is contained in:
parent
0b1219ff7e
commit
00c57c88bf
|
@ -246,7 +246,7 @@
|
||||||
links = {
|
links = {
|
||||||
switch-d1 = {
|
switch-d1 = {
|
||||||
group = "1";
|
group = "1";
|
||||||
ports = [ "1" ];
|
ports = [ "12" ];
|
||||||
};
|
};
|
||||||
ap3.ports = [ "1" ];
|
ap3.ports = [ "1" ];
|
||||||
ap59.ports = [ "2" ];
|
ap59.ports = [ "2" ];
|
||||||
|
|
|
@ -680,5 +680,45 @@ in
|
||||||
in map (vlan: {
|
in map (vlan: {
|
||||||
assertion = builtins.length vlanNets.${vlan} == 1;
|
assertion = builtins.length vlanNets.${vlan} == 1;
|
||||||
message = "VLAN ${vlan} is used by more than one network: ${lib.concatStringsSep " " vlanNets.${vlan}}";
|
message = "VLAN ${vlan} is used by more than one network: ${lib.concatStringsSep " " vlanNets.${vlan}}";
|
||||||
}) (builtins.attrNames vlanNets));
|
}) (builtins.attrNames vlanNets))
|
||||||
|
++
|
||||||
|
# Duplicate switch port check
|
||||||
|
builtins.concatMap (hostName:
|
||||||
|
let
|
||||||
|
ports = lib.unique (
|
||||||
|
builtins.concatMap (linkName:
|
||||||
|
config.site.hosts.${hostName}.links.${linkName}.ports
|
||||||
|
) (builtins.attrNames config.site.hosts.${hostName}.links)
|
||||||
|
);
|
||||||
|
linksOfPort = port:
|
||||||
|
builtins.attrNames (
|
||||||
|
lib.filterAttrs (_: { ports, ... }: builtins.elem port ports)
|
||||||
|
config.site.hosts.${hostName}.links
|
||||||
|
);
|
||||||
|
in map (port: {
|
||||||
|
assertion = builtins.length (linksOfPort port) == 1;
|
||||||
|
message = "${hostName}: port ${port} is used in more than one link: ${lib.concatStringsSep " " (linksOfPort port)}";
|
||||||
|
}) ports
|
||||||
|
) (builtins.attrNames config.site.hosts)
|
||||||
|
++
|
||||||
|
# Duplicate switch port group check
|
||||||
|
builtins.concatMap (hostName:
|
||||||
|
let
|
||||||
|
groups = lib.unique (
|
||||||
|
builtins.filter builtins.isString (
|
||||||
|
builtins.map (linkName:
|
||||||
|
config.site.hosts.${hostName}.links.${linkName}.group
|
||||||
|
) (builtins.attrNames config.site.hosts.${hostName}.links)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
linksOfGroup = wantedGroup:
|
||||||
|
builtins.attrNames (
|
||||||
|
lib.filterAttrs (_: { group, ... }: group == wantedGroup)
|
||||||
|
config.site.hosts.${hostName}.links
|
||||||
|
);
|
||||||
|
in map (group: {
|
||||||
|
assertion = builtins.length (linksOfGroup group) == 1;
|
||||||
|
message = "${hostName}: group ${group} is used in more than one link: ${lib.concatStringsSep " " (linksOfGroup group)}";
|
||||||
|
}) groups
|
||||||
|
) (builtins.attrNames config.site.hosts);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue