from ipaddress import IPv4Network AS_NUMBERS = { # 4290xxxxxx 'home': 4290000138, 'htz-cloud': 4290000137, 'ionos': 4290000002, 'glauca': 4290207960, } WG_AUTOGEN_NODES = [ # only ever append to this list. If a node vanishes, set its name to # `None`. You may remove nodes from the end of this, though it's not # recommended to do so. None, # fkusei-locutus never used this 'home.router', 'htz-cloud.wireguard', 'icinga2', None, # daisy ] WG_AUTOGEN_SETTINGS = { # special settings to apply when peering with a specific node 'home.router': { 'firewall': {'versatel'}, 'no_autoconnect': True, 'persistent_keepalive': False, }, } def get_subnet_for_connection(repo, peer_a, peer_b): assert peer_a in WG_AUTOGEN_NODES assert peer_b in WG_AUTOGEN_NODES pos_peer_a = WG_AUTOGEN_NODES.index(peer_a) pos_peer_b = WG_AUTOGEN_NODES.index(peer_b) vpn_subnet = list(IPv4Network('169.254.0.0/16').subnets(new_prefix=24))[pos_peer_a] return list(IPv4Network(vpn_subnet).subnets(new_prefix=31))[pos_peer_b]