@@ -324,6 +324,9 @@ def populateswitches(switchesfile):
324324 "num" : elems [1 ],
325325 "ipv6" : elems [3 ],
326326 "ipv6ptr" : ip6toptr (elems [3 ]),
327+ "switchtype" : elems [4 ],
328+ "hierarchy" : elems [5 ],
329+ "model" : elems [7 ],
327330 "fqdn" : name .lower () + ".scale.lan" ,
328331 "aliases" : roomalias (name ),
329332 }
@@ -381,6 +384,9 @@ def populateaps(aps_file, apuse_file):
381384 "configver" : str (row ["config_ver" ]),
382385 "fqdn" : name + ".scale.lan" ,
383386 "aliases" : [row ["serial" ].lower ()],
387+ "map_id" : str (row ["map_id" ]),
388+ "map_x" : str (row ["map_x" ]),
389+ "map_y" : str (row ["map_y" ]),
384390 }
385391 )
386392 return aps
@@ -467,11 +473,10 @@ def populateservers(serversfile, vlans):
467473 continue
468474
469475 vlan = ""
470- building = ""
476+ building = _building_from_vlans ( vlans , ipv6 = ipv6 )
471477 for vln in vlans :
472478 if ipv6 .find (vln ["ipv6prefix" ]) == 0 :
473479 vlan = vln ["name" ]
474- building = vln ["building" ]
475480
476481 servers .append (
477482 {
@@ -947,6 +952,24 @@ def generatekeaconfig(servers, aps, vlans, outputdir):
947952 f .write (json .dumps (conf_keav6_config , indent = 2 ))
948953
949954
955+ def _building_from_vlans (vlans , ipv6 = None , ipv4 = None ):
956+ """Look up building name from VLAN list by matching an IPv6 or IPv4 address."""
957+ for vlan in vlans :
958+ if ipv6 :
959+ net = ipaddress .ip_network (
960+ f"{ vlan ['ipv6prefix' ]} /{ vlan ['ipv6bitmask' ]} " , strict = False
961+ )
962+ if ipaddress .ip_address (ipv6 ) in net :
963+ return vlan ["building" ]
964+ if ipv4 and vlan ["ipv4prefix" ] != "0.0.0.0" :
965+ net = ipaddress .ip_network (
966+ f"{ vlan ['ipv4prefix' ]} /{ vlan ['ipv4bitmask' ]} " , strict = False
967+ )
968+ if ipaddress .ip_address (ipv4 ) in net :
969+ return vlan ["building" ]
970+ return ""
971+
972+
950973def _prom_exclude (name ):
951974 """Return True if the name should be excluded from prom configs."""
952975 return re .match (r"^(deceased|donotuse|massflash|spare|expob5|expoc4|expoc5)" , name )
@@ -1031,7 +1054,7 @@ def generatezones(switches, routers, pis, aps, servers, outputdir):
10311054 return True
10321055
10331056
1034- def generatewasgehtconfig (switches , routers , pis , aps , servers , outputdir ):
1057+ def generatewasgehtconfig (switches , routers , pis , aps , servers , vlans , outputdir ):
10351058 wasgehtconfig = {}
10361059 wasgehtconfig ["uplink" ] = {
10371060 "checks" : {
@@ -1045,11 +1068,16 @@ def generatewasgehtconfig(switches, routers, pis, aps, servers, outputdir):
10451068 }
10461069 }
10471070 for switch in switches :
1071+ if switch ["hierarchy" ].startswith ("Z" ):
1072+ continue
10481073 entry = {
10491074 "tags" : {
10501075 "type" : "switch" ,
10511076 "os" : "junos" ,
10521077 "num" : switch ["num" ],
1078+ "switchtype" : switch ["switchtype" ],
1079+ "model" : switch ["model" ],
1080+ "building" : _building_from_vlans (vlans , ipv6 = switch ["ipv6" ]),
10531081 ** (
10541082 {"aliases" : ", " .join (switch ["aliases" ])}
10551083 if switch ["aliases" ]
@@ -1097,6 +1125,7 @@ def generatewasgehtconfig(switches, routers, pis, aps, servers, outputdir):
10971125 "tags" : {
10981126 "type" : "router" ,
10991127 "os" : "nixos" ,
1128+ "building" : _building_from_vlans (vlans , ipv6 = router ["ipv6" ]),
11001129 },
11011130 "checks" : {
11021131 "ping" : {
@@ -1105,11 +1134,14 @@ def generatewasgehtconfig(switches, routers, pis, aps, servers, outputdir):
11051134 },
11061135 }
11071136 for pi in pis :
1137+ if pi ["name" ] == "pi-massflash" or pi ["name" ].startswith ("pi-reghelp" ):
1138+ continue
11081139 wasgehtconfig [pi ["name" ]] = {
11091140 "tags" : {
11101141 "type" : "pi" ,
11111142 "os" : "nixos" ,
11121143 "role" : "registration" if pi ["name" ].startswith ("pi-reg" ) else "sign" ,
1144+ "building" : _building_from_vlans (vlans , ipv6 = pi ["ipv6" ]),
11131145 },
11141146 "checks" : {
11151147 "ping" : {
@@ -1124,6 +1156,10 @@ def generatewasgehtconfig(switches, routers, pis, aps, servers, outputdir):
11241156 "os" : "openwrt" ,
11251157 "channels" : f"{ ap ['wifi2' ]} / { ap ['wifi5' ]} " ,
11261158 "config" : ap ["configver" ],
1159+ "building" : _building_from_vlans (vlans , ipv4 = ap ["ipv4" ]),
1160+ "map_id" : ap ["map_id" ],
1161+ "map_x" : ap ["map_x" ],
1162+ "map_y" : ap ["map_y" ],
11271163 ** ({"aliases" : ", " .join (ap ["aliases" ])} if ap ["aliases" ] else {}),
11281164 },
11291165 "checks" : {
@@ -1256,14 +1292,14 @@ def main():
12561292 elif subcomm == "prom" :
12571293 generatepromconfigs (switches , pis , aps , outputdir )
12581294 elif subcomm == "wasgeht" :
1259- generatewasgehtconfig (switches , routers , pis , aps , servers , outputdir )
1295+ generatewasgehtconfig (switches , routers , pis , aps , servers , vlans , outputdir )
12601296 elif subcomm == "allnet" :
12611297 generateallnetwork (switches , routers , outputdir )
12621298 elif subcomm == "all" :
12631299 generatekeaconfig (servers , aps , vlans , outputdir )
12641300 generatezones (switches , routers , pis , aps , servers , outputdir )
12651301 generatepromconfigs (switches , pis , aps , outputdir )
1266- generatewasgehtconfig (switches , routers , pis , aps , servers , outputdir )
1302+ generatewasgehtconfig (switches , routers , pis , aps , servers , vlans , outputdir )
12671303 generateallnetwork (switches , routers , outputdir )
12681304 elif subcomm == "debug" :
12691305 # overload outputdir as 2nd debug parameter
0 commit comments