config/server: derive bridge interfaces from containers

This commit is contained in:
Astro 2021-11-13 02:40:56 +01:00
parent 32db7a7d23
commit 84e166fc47

View File

@ -1,123 +1,32 @@
{ config, lib, ... }:
let
containers = lib.filterAttrs (_: { role, ... }:
role == "container"
) config.site.hosts;
bridgeInterfaces = builtins.foldl' (result: { interfaces, ... }:
result // builtins.mapAttrs (_: _: {
type = "bridge";
}) (
lib.filterAttrs (_: { type, ... }:
builtins.elem type [ "veth" "bridge" ]
) interfaces
)
) {} (builtins.attrValues containers);
makeServer = name: {
interfaces = bridgeInterfaces;
model = "pc";
role = "server";
};
in
{
site = {
hosts = {
server1 = {
interfaces = {
c3d2.type = "bridge";
cluster.type = "bridge";
core.type = "bridge";
mgmt.type = "bridge";
priv1.type = "bridge";
priv10.type = "bridge";
priv11.type = "bridge";
priv12.type = "bridge";
priv13.type = "bridge";
priv14.type = "bridge";
priv15.type = "bridge";
priv16.type = "bridge";
priv17.type = "bridge";
priv18.type = "bridge";
priv19.type = "bridge";
priv2.type = "bridge";
priv20.type = "bridge";
priv21.type = "bridge";
priv22.type = "bridge";
priv23.type = "bridge";
priv24.type = "bridge";
priv25.type = "bridge";
priv26.type = "bridge";
priv27.type = "bridge";
priv28.type = "bridge";
priv29.type = "bridge";
priv3.type = "bridge";
priv30.type = "bridge";
priv31.type = "bridge";
priv32.type = "bridge";
priv33.type = "bridge";
priv34.type = "bridge";
priv35.type = "bridge";
priv36.type = "bridge";
priv37.type = "bridge";
priv38.type = "bridge";
priv39.type = "bridge";
priv4.type = "bridge";
priv40.type = "bridge";
priv41.type = "bridge";
priv42.type = "bridge";
priv5.type = "bridge";
priv6.type = "bridge";
priv7.type = "bridge";
priv8.type = "bridge";
priv9.type = "bridge";
pub.type = "bridge";
serv.type = "bridge";
up1.type = "bridge";
up2.type = "bridge";
up3.type = "bridge";
up4.type = "bridge";
};
model = "pc";
role = "server";
};
server2 = {
interfaces = {
c3d2.type = "bridge";
cluster.type = "bridge";
core.type = "bridge";
mgmt.type = "bridge";
priv1.type = "bridge";
priv10.type = "bridge";
priv11.type = "bridge";
priv12.type = "bridge";
priv13.type = "bridge";
priv14.type = "bridge";
priv15.type = "bridge";
priv16.type = "bridge";
priv17.type = "bridge";
priv18.type = "bridge";
priv19.type = "bridge";
priv2.type = "bridge";
priv20.type = "bridge";
priv21.type = "bridge";
priv22.type = "bridge";
priv23.type = "bridge";
priv24.type = "bridge";
priv25.type = "bridge";
priv26.type = "bridge";
priv27.type = "bridge";
priv28.type = "bridge";
priv29.type = "bridge";
priv3.type = "bridge";
priv30.type = "bridge";
priv31.type = "bridge";
priv32.type = "bridge";
priv33.type = "bridge";
priv34.type = "bridge";
priv35.type = "bridge";
priv36.type = "bridge";
priv37.type = "bridge";
priv38.type = "bridge";
priv39.type = "bridge";
priv4.type = "bridge";
priv40.type = "bridge";
priv41.type = "bridge";
priv42.type = "bridge";
priv5.type = "bridge";
priv6.type = "bridge";
priv7.type = "bridge";
priv8.type = "bridge";
priv9.type = "bridge";
pub.type = "bridge";
serv.type = "bridge";
up1.type = "bridge";
up2.type = "bridge";
up3.type = "bridge";
up4.type = "bridge";
};
model = "pc";
role = "server";
};
server1 = makeServer "server1";
server2 = makeServer "server2";
};
sshPubKeys = [
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDOFs2LdK23ysS0SSkXZuULUOCZHe1ZxvfOKj002J6rkvAaDLar9g5aKuiIV70ZR33A2rchoLMiM4pLLwoSAPJg1FgIgJjU+DFoWtiW+IjzKXdHHVspb2iOIhpfbfk8WC5HZ/6fPz4RUqadGQ43ImnMhSN0ge3s/oM48hpc96ne6tH+mGiugdPx8097NE9yTqJHi8deBhi3daeJH4eQeg66Fi+kDIAZv5TJ0Oca5h7PBd253/vf3l21jRH8u1D1trALv9KStGycTk5Nwih+OHx+Rnvue/B/nxgAz4I3mmQa+jhRlGaQVG0MtOBRY3Ae7ZNqhjuefDUCM2hwG70toU9xDUw0AihC2ownY+P2PjssoG1O8f/D7ilw7qrXJHEeM8HwzqMH8X4ELYHaHTwjeWfZTTFev1Djr969LjdS1UZzqCZHO0jmQ5Pa3eXw8xcoprtt620kYLTKSMs6exLstE48o57Yqfn+eTJDy7EkcjiLN6GNIi42b9Z73xXNpZx1WR9O6OulJf/6pWgrApasvxiGmxxILq98s1/VnZkOFXR8JXnpvKHEIOIr3bFQu3GLCrzY2Yuh4NL5wy6lcZNTr/0rr6AO24IbEWM7TApbXnKA5XQhAbThrVsuFBdT3+bBP2nedvWQ0W+Q6SUf+8T2o5InnFqs5ABnTixBItiWw+9BiQ== root@server1"
];