2021-04-01 16:27:31 +02:00
|
|
|
from ipaddress import ip_network
|
|
|
|
|
2021-04-02 18:57:13 +02:00
|
|
|
repo.libs.tools.require_bundle(node, 'systemd-networkd')
|
2020-11-21 15:38:38 +01:00
|
|
|
|
|
|
|
files = {
|
2021-09-29 19:27:13 +02:00
|
|
|
'/usr/local/share/icinga/plugins/check_wireguard_connected': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-03-10 20:36:20 +01:00
|
|
|
deps = set()
|
|
|
|
|
|
|
|
if node.has_bundle('apt'):
|
|
|
|
deps.add('pkg_apt:wireguard')
|
|
|
|
|
2023-09-09 13:54:27 +02:00
|
|
|
for peer, config in sorted(node.metadata.get('wireguard/peers', {}).items()):
|
|
|
|
files[f'/etc/systemd/network/wg_{config["iface"]}.netdev'] = {
|
2020-11-21 15:38:38 +01:00
|
|
|
'content_type': 'mako',
|
2021-09-29 19:27:13 +02:00
|
|
|
'source': 'wg.netdev',
|
2022-05-16 10:48:26 +02:00
|
|
|
'owner': 'systemd-network',
|
|
|
|
'mode': '0600',
|
2021-04-01 16:27:31 +02:00
|
|
|
'context': {
|
2021-09-29 19:27:13 +02:00
|
|
|
'endpoint': config.get('endpoint'),
|
2023-09-09 13:54:27 +02:00
|
|
|
'iface': config['iface'],
|
2021-09-29 19:27:13 +02:00
|
|
|
'peer': peer,
|
|
|
|
'port': config['my_port'],
|
|
|
|
'privatekey': node.metadata.get('wireguard/privatekey'),
|
|
|
|
'psk': config['psk'],
|
|
|
|
'pubkey': config['pubkey'],
|
2023-12-10 14:48:24 +01:00
|
|
|
'specials': repo.libs.s2s.WG_AUTOGEN_SETTINGS.get(peer, {}),
|
2020-11-21 15:38:38 +01:00
|
|
|
},
|
2022-03-10 20:36:20 +01:00
|
|
|
'needs': deps,
|
2020-11-21 15:38:38 +01:00
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:systemd-networkd:restart',
|
|
|
|
},
|
2020-11-27 03:09:37 +01:00
|
|
|
}
|