From 03c0b344461437ba93f33b517cee6c6cd6ca4b17 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 20 Dec 2020 13:00:36 +0100 Subject: [PATCH] ++config vpn server --- uncloud/settings.py | 2 +- uncloud_net/tasks.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/uncloud/settings.py b/uncloud/settings.py index ae73e72..ea90c22 100644 --- a/uncloud/settings.py +++ b/uncloud/settings.py @@ -221,7 +221,7 @@ CELERY_BROKER_URL = 'redis://:uncloud.example.com:6379/0' CELERY_RESULT_BACKEND = 'redis://:uncloud.example.com:6379/0' CELERY_TASK_ROUTES = { - re.compile(r'cdist.*'): { 'queue': 'cdist' } + re.compile(r'.*.tasks.cdist.*'): { 'queue': 'cdist' } # cdist tasks go into cdist queue } # CELERY_TASK_CREATE_MISSING_QUEUES = False diff --git a/uncloud_net/tasks.py b/uncloud_net/tasks.py index 4a82910..81be402 100644 --- a/uncloud_net/tasks.py +++ b/uncloud_net/tasks.py @@ -2,6 +2,7 @@ from celery import shared_task from .models import * import os +import subprocess @shared_task def whereami(): @@ -31,12 +32,20 @@ def cdist_configure_wireguard_server(config, server): To be executed on the cdist workers. """ - fname = f"/home/app/.cdist/type/__ungleich_wireguard/files/{server}" + dirname= "/home/app/.cdist/type/__ungleich_wireguard/files/" + fname = os.path.join(dirname,server) - print(os.uname()) print(f"Configuring VPN server {server} (on cdist host)") with open(fname, "w") as fd: fd.write(config) + subprocess.run(f"cd ${dirname} && git pull && git add {server} && git commit -m 'Updating config for ${server}' && git push", + shell=True) + + subprocess.run(f"cdist config -vv {server}", shell=True) + + # FIXME: + # ensure logs are on the server + # ensure exit codes are known return "All good"