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