From 2e6c72c093c8ec9a523c2dad289748f5cb09fb7e Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 20 Dec 2020 12:45:36 +0100 Subject: [PATCH] wireguard/celery fixes --- uncloud_net/models.py | 12 +++--------- uncloud_net/tasks.py | 11 ++++++++++- uncloud_net/views.py | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/uncloud_net/models.py b/uncloud_net/models.py index 92499dd..b4e1e8d 100644 --- a/uncloud_net/models.py +++ b/uncloud_net/models.py @@ -55,22 +55,16 @@ class WireGuardVPNPool(models.Model): @property def wireguard_config(self): - wireguard_config = [ - "[Interface]\nListenPort = 51820\nPrivateKey = {self.wireguard_private_key}\n".format( - privatekey=self.wireguard_private_key) - ] + wireguard_config = [ f"[Interface]\nListenPort = 51820\nPrivateKey = {self.wireguard_private_key}\n" ] peers = [] for vpn in self.wireguardvpn_set.all(): public_key = vpn.wireguard_public_key - peer_network = "{}/{}".format(vpn.address, self.subnetwork_mask) + peer_network = f"{vpn.address}/{self.subnetwork_mask}" owner = vpn.owner - peers.append("# Owner: {owner}\n[Peer]\nPublicKey = {public_key}\nAllowedIPs = {peer_network}\n\n".format( - owner=owner, - public_key=public_key, - peer_network=peer_network)) + peers.append(f"# Owner: {owner}\n[Peer]\nPublicKey = {public_key}\nAllowedIPs = {peer_network}\n\n") wireguard_config.extend(peers) diff --git a/uncloud_net/tasks.py b/uncloud_net/tasks.py index 5d1afe7..9c1071b 100644 --- a/uncloud_net/tasks.py +++ b/uncloud_net/tasks.py @@ -20,7 +20,12 @@ def configure_wireguard_server(wireguardvpnpool): server = wireguardvpnpool.vpn_server_hostname print(f"Configuring VPN server {server}") - cdist_configure_wireguard_server(config, server) + #res = cdist_configure_wireguard_server.delay(config, server) + res = cdist_configure_wireguard_server.apply_async((config, server), queue='cdist') + + print(f"res={res}") + res2= res.get() + print(f"res2={res2}") @shared_task @@ -33,5 +38,9 @@ def cdist_configure_wireguard_server(config, server): fname = f"/home/app/.cdist/type/__ungleich_wireguard/files/{server}" + print(os.uname()) with open(fname, "w") as fd: fd.write(config) + + + return "All good" diff --git a/uncloud_net/views.py b/uncloud_net/views.py index e06e9bd..72ff681 100644 --- a/uncloud_net/views.py +++ b/uncloud_net/views.py @@ -40,7 +40,7 @@ class WireGuardVPNViewSet(viewsets.ModelViewSet): public_key=serializer.validated_data['wireguard_public_key'], network_mask=serializer.validated_data['network_mask'] ) - configure_wireguard_server.apply_async((vpn.vpnpool,)) + configure_wireguard_server(vpn.vpnpool) return Response(WireGuardVPNSerializer(vpn).data)