Update addressing lib to remove making the hosts list optional.
This commit is contained in:
parent
e5326f0af6
commit
1b23a16e9f
2 changed files with 50 additions and 53 deletions
|
|
@ -270,19 +270,18 @@ let
|
||||||
spec.domain or (throw "metatron-addressing: spec.domain is required for FQDN generation");
|
spec.domain or (throw "metatron-addressing: spec.domain is required for FQDN generation");
|
||||||
in
|
in
|
||||||
concatMapAttrs
|
concatMapAttrs
|
||||||
(locationName: locCfg:
|
(locationName: locationCfg:
|
||||||
let
|
let
|
||||||
loc = locationId locationName;
|
loc = locationId locationName;
|
||||||
locCode = mkLocationCode locationName;
|
locCode = mkLocationCode locationName;
|
||||||
|
|
||||||
# Strip meta-level hints; what’s left are subnets (main, dmz, etc.)
|
# Only treat attributes that are attrsets with a `hosts` attr as subnets
|
||||||
subnets =
|
subnets =
|
||||||
builtins.removeAttrs locCfg [ "owner" "admins" "users" ];
|
lib.filterAttrs (_: v: builtins.isAttrs v && v ? hosts) locationCfg;
|
||||||
in
|
in
|
||||||
concatMapAttrs
|
concatMapAttrs
|
||||||
(typeName: subnetCfg:
|
(typeName: subnetCfg:
|
||||||
let
|
let
|
||||||
# New shape: subnetCfg.hosts = { hostName = { role = "..."; ... }; ... }
|
|
||||||
hostsForSubnet = subnetCfg.hosts or { };
|
hostsForSubnet = subnetCfg.hosts or { };
|
||||||
|
|
||||||
# Only treat non-underscore-prefixed keys as hosts
|
# Only treat non-underscore-prefixed keys as hosts
|
||||||
|
|
@ -347,7 +346,7 @@ let
|
||||||
subnets)
|
subnets)
|
||||||
locations;
|
locations;
|
||||||
|
|
||||||
# Subnet map: { "home-dmz" = { cidr = "..."; vlan = ...; zone = "..."; ... }; ... }
|
# Subnet map: { "home-dmz" = "10.1.0.0/19"; "home-main" = "..."; ... }
|
||||||
mkSubnetsFromSpec =
|
mkSubnetsFromSpec =
|
||||||
spec:
|
spec:
|
||||||
let
|
let
|
||||||
|
|
@ -358,20 +357,18 @@ let
|
||||||
spec.domain or (throw "metatron-addressing: spec.domain is required");
|
spec.domain or (throw "metatron-addressing: spec.domain is required");
|
||||||
in
|
in
|
||||||
concatMapAttrs
|
concatMapAttrs
|
||||||
(locationName: locCfg:
|
(locationName: locationCfg:
|
||||||
let
|
let
|
||||||
loc = locationId locationName;
|
loc = locationId locationName;
|
||||||
locCode = mkLocationCode locationName;
|
locCode = mkLocationCode locationName;
|
||||||
|
|
||||||
# Strip meta-level hints; remaining attrs are subnets
|
# Only attributes with `hosts` are subnets
|
||||||
subnets =
|
subnets =
|
||||||
builtins.removeAttrs locCfg [ "owner" "admins" "users" ];
|
lib.filterAttrs (_: v: builtins.isAttrs v && v ? hosts) locationCfg;
|
||||||
in
|
in
|
||||||
mapAttrs'
|
mapAttrs'
|
||||||
(typeName: subnetCfg:
|
(typeName: subnetCfg:
|
||||||
let
|
let
|
||||||
hostsForSubnet = subnetCfg.hosts or { };
|
|
||||||
|
|
||||||
cidr = mkSubnetNamed { location = loc; inherit typeName; };
|
cidr = mkSubnetNamed { location = loc; inherit typeName; };
|
||||||
|
|
||||||
subnetSlug =
|
subnetSlug =
|
||||||
|
|
@ -382,21 +379,42 @@ let
|
||||||
zone = "${subnetSlug}.${locCode}.${domain}";
|
zone = "${subnetSlug}.${locCode}.${domain}";
|
||||||
|
|
||||||
vlan =
|
vlan =
|
||||||
# Priority: explicit vlan on subnet > old-style _vlan > computed
|
|
||||||
subnetCfg.vlan or
|
subnetCfg.vlan or
|
||||||
hostsForSubnet._vlan or
|
subnetCfg._vlan or
|
||||||
(mkVlanNamed { location = loc; inherit typeName; });
|
(mkVlanNamed { location = loc; inherit typeName; });
|
||||||
|
|
||||||
|
dhcpCfg = subnetCfg.dhcp or null;
|
||||||
|
|
||||||
|
dhcpRange =
|
||||||
|
if dhcpCfg == null then null else {
|
||||||
|
startIp = mkIpNamed {
|
||||||
|
location = loc;
|
||||||
|
inherit typeName;
|
||||||
|
roleName = "pool";
|
||||||
|
host = dhcpCfg.start;
|
||||||
|
};
|
||||||
|
endIp = mkIpNamed {
|
||||||
|
location = loc;
|
||||||
|
inherit typeName;
|
||||||
|
roleName = "pool";
|
||||||
|
host = dhcpCfg.end;
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
nameValuePair
|
nameValuePair
|
||||||
"${locationName}-${typeName}"
|
"${locationName}-${typeName}"
|
||||||
{
|
(
|
||||||
inherit cidr locationName typeName zone vlan;
|
{
|
||||||
})
|
inherit cidr locationName typeName zone vlan;
|
||||||
|
}
|
||||||
|
// optionalAttrs (dhcpCfg != null) {
|
||||||
|
dhcp = dhcpCfg;
|
||||||
|
dhcpRange = dhcpRange;
|
||||||
|
}
|
||||||
|
))
|
||||||
subnets)
|
subnets)
|
||||||
locations;
|
locations;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Combined view, if you want both
|
# Combined view, if you want both
|
||||||
mkNetworkFromSpec =
|
mkNetworkFromSpec =
|
||||||
spec:
|
spec:
|
||||||
|
|
|
||||||
51
meta.nix
51
meta.nix
|
|
@ -84,6 +84,11 @@
|
||||||
main = {
|
main = {
|
||||||
vlan = 10;
|
vlan = 10;
|
||||||
|
|
||||||
|
dhcp = {
|
||||||
|
start = 1;
|
||||||
|
end = 1;
|
||||||
|
};
|
||||||
|
|
||||||
hosts = {
|
hosts = {
|
||||||
europa = {
|
europa = {
|
||||||
role = "router";
|
role = "router";
|
||||||
|
|
@ -131,40 +136,21 @@
|
||||||
role = "phone";
|
role = "phone";
|
||||||
hw-address = "80:5e:c0:de:3d:66";
|
hw-address = "80:5e:c0:de:3d:66";
|
||||||
};
|
};
|
||||||
|
|
||||||
home-main-dhcp-start = {
|
|
||||||
role = "pool";
|
|
||||||
hostId = 1;
|
|
||||||
dns = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
home-main-dhcp-end = {
|
|
||||||
role = "pool";
|
|
||||||
hostId = 250;
|
|
||||||
dns = false;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
guest = {
|
guest = {
|
||||||
vlan = 20;
|
vlan = 20;
|
||||||
|
|
||||||
|
dhcp = {
|
||||||
|
start = 1;
|
||||||
|
end = 250;
|
||||||
|
};
|
||||||
|
|
||||||
hosts = {
|
hosts = {
|
||||||
europa-guest = {
|
europa-guest = {
|
||||||
role = "router";
|
role = "router";
|
||||||
};
|
};
|
||||||
|
|
||||||
home-guest-dhcp-start = {
|
|
||||||
role = "pool";
|
|
||||||
hostId = 1;
|
|
||||||
dns = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
home-guest-dhcp-end = {
|
|
||||||
role = "pool";
|
|
||||||
hostId = 250;
|
|
||||||
dns = false;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -223,6 +209,11 @@
|
||||||
storage = {
|
storage = {
|
||||||
vlan = 40;
|
vlan = 40;
|
||||||
|
|
||||||
|
dhcp = {
|
||||||
|
start = 1;
|
||||||
|
end = 250;
|
||||||
|
};
|
||||||
|
|
||||||
hosts = {
|
hosts = {
|
||||||
europa-storage = {
|
europa-storage = {
|
||||||
role = "router";
|
role = "router";
|
||||||
|
|
@ -232,18 +223,6 @@
|
||||||
role = "nas";
|
role = "nas";
|
||||||
aliases = [ "storage.kasear.net" ];
|
aliases = [ "storage.kasear.net" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
home-storage-dhcp-start = {
|
|
||||||
role = "pool";
|
|
||||||
hostId = 1;
|
|
||||||
dns = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
home-storage-dhcp-end = {
|
|
||||||
role = "pool";
|
|
||||||
hostId = 250;
|
|
||||||
dns = false;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue