fix templating

This commit is contained in:
Nico Schottelius 2020-12-26 14:45:28 +01:00
parent 93e5d39c7b
commit 74749bf07c
2 changed files with 4 additions and 9 deletions

View file

@ -11,11 +11,6 @@ import uuid
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@shared_task
def whereami():
print(os.uname())
return os.uname()
@shared_task @shared_task
def configure_wireguard_server_on_host(wg_name, config): def configure_wireguard_server_on_host(wg_name, config):
""" """
@ -25,16 +20,16 @@ def configure_wireguard_server_on_host(wg_name, config):
""" """
# Write config # Write config
fname = f"/etc/wireguard/{{wg_name}}.conf" fname = f"/etc/wireguard/{wg_name}.conf"
with open(fname, "w") as fd: with open(fname, "w") as fd:
fd.write(config) fd.write(config)
# Ensure the device exists # Ensure the device exists
subprocess.run(f"ip link show {{wg_name}} || sudo ip link add {{wg_name}} type wireguard", subprocess.run(f"ip link show {wg_name} || sudo ip link add {{wg_name}} type wireguard",
shell=True, check=True) shell=True, check=True)
# Ensure the config is correct # Ensure the config is correct
subprocess.run(f"sudo wg setconf {{wg_name}} {{fname}}", subprocess.run(f"sudo wg setconf {wg_name} {fname}",
shell=True, check=True) shell=True, check=True)

View file

@ -35,7 +35,7 @@ class WireGuardVPNViewSet(viewsets.ModelViewSet):
public_key=serializer.validated_data['wireguard_public_key'], public_key=serializer.validated_data['wireguard_public_key'],
network_mask=serializer.validated_data['network_mask'] network_mask=serializer.validated_data['network_mask']
) )
configure_wireguard_server(vpn.vpnpool)
return Response(WireGuardVPNSerializer(vpn).data) return Response(WireGuardVPNSerializer(vpn).data)