++celery/tasks
This commit is contained in:
parent
63191c0a88
commit
5e870f04b1
5 changed files with 63 additions and 9 deletions
|
|
@ -1,8 +1,14 @@
|
|||
from celery import shared_task
|
||||
from .models import *
|
||||
|
||||
from uncloud.models import UncloudTask
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@shared_task
|
||||
def whereami():
|
||||
|
|
@ -20,9 +26,11 @@ def configure_wireguard_server(wireguardvpnpool):
|
|||
config = wireguardvpnpool.wireguard_config
|
||||
server = wireguardvpnpool.vpn_server_hostname
|
||||
|
||||
print(f"Configuring VPN server {server} (async)")
|
||||
# cdist_configure_wireguard_server.apply_async((config, server), queue='cdist')
|
||||
cdist_configure_wireguard_server.apply_async((config, server))
|
||||
log.info(f"Configuring VPN server {server} (async)")
|
||||
|
||||
task_id = uuid.UUID(cdist_configure_wireguard_server.apply_async((config, server)).id)
|
||||
UncloudTasks.objects.create(task_id=task_id)
|
||||
|
||||
|
||||
@shared_task
|
||||
def cdist_configure_wireguard_server(config, server):
|
||||
|
|
@ -35,15 +43,17 @@ def cdist_configure_wireguard_server(config, server):
|
|||
dirname= "/home/app/.cdist/type/__ungleich_wireguard/files/"
|
||||
fname = os.path.join(dirname,server)
|
||||
|
||||
print(f"Configuring VPN server {server} (on cdist host)")
|
||||
log.info(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)
|
||||
log.debug("git committing wireguard changes")
|
||||
subprocess.run(f"cd /aa{dirname} && git pull && git add {server} && git commit -m 'Updating config for ${server}' && git push",
|
||||
shell=True, check=True)
|
||||
|
||||
subprocess.run(f"cdist config -vv {server}", shell=True)
|
||||
log.debug(f"Configuring VPN server {server} with cdist")
|
||||
subprocess.run(f"cdist config {server}", shell=True, check=True)
|
||||
|
||||
# FIXME:
|
||||
# ensure logs are on the server
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue