46 lines
1 KiB
Python
46 lines
1 KiB
Python
from celery import shared_task
|
|
from .models import *
|
|
|
|
import os
|
|
|
|
@shared_task
|
|
def whereami():
|
|
print(os.uname())
|
|
return os.uname()
|
|
|
|
def configure_wireguard_server(wireguardvpnpool):
|
|
"""
|
|
- Create wireguard config (DB query -> string)
|
|
- Submit config to cdist worker
|
|
- Change config locally on worker / commit / shared
|
|
|
|
"""
|
|
|
|
config = wireguardvpnpool.wireguard_config
|
|
server = wireguardvpnpool.vpn_server_hostname
|
|
|
|
print(f"Configuring VPN server {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
|
|
def cdist_configure_wireguard_server(config, server):
|
|
"""
|
|
Create config and configure server.
|
|
|
|
To be executed on the cdist workers.
|
|
"""
|
|
|
|
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"
|