bundlewrap/bundles/wireguard/items.py

37 lines
1 KiB
Python
Raw Normal View History

2021-04-01 14:27:31 +00:00
from ipaddress import ip_network
repo.libs.tools.require_bundle(node, 'systemd-networkd')
files = {
'/usr/local/share/icinga/plugins/check_wireguard_connected': {
'mode': '0755',
},
}
deps = set()
if node.has_bundle('apt'):
deps.add('pkg_apt:wireguard')
for peer, config in sorted(node.metadata.get('wireguard/peers', {}).items()):
files[f'/etc/systemd/network/wg_{config["iface"]}.netdev'] = {
'content_type': 'mako',
'source': 'wg.netdev',
'owner': 'systemd-network',
'mode': '0600',
2021-04-01 14:27:31 +00:00
'context': {
'endpoint': config.get('endpoint'),
'iface': config['iface'],
'peer': peer,
'port': config['my_port'],
'privatekey': node.metadata.get('wireguard/privatekey'),
'psk': config.get('psk'),
'pubkey': config['pubkey'],
'specials': repo.libs.s2s.WG_AUTOGEN_SETTINGS.get(peer, {}),
},
'needs': deps,
'triggers': {
'svc_systemd:systemd-networkd:restart',
},
}