Add API v2 endpoints to manage cluster workers and the primary WireGuard

This commit is contained in:
Eduardo Silva
2026-11-23 14:29:26 -03:00
parent 2aa740eaaf
commit 9ccb8c58df
10 changed files with 490 additions and 9 deletions
+4 -6
View File
@@ -23,7 +23,8 @@ from vpn_invite.models import PeerInvite
from wgwadmlibrary.tools import user_has_access_to_peer
from wireguard.models import Peer, PeerAllowedIP, WireGuardInstance
from wireguard_tools.functions import (
CLUSTER_WIREGUARD_CONFIG_DIR, WIREGUARD_CONFIG_DIR, get_instance_config_dir, sync_interface_routes
CLUSTER_WIREGUARD_CONFIG_DIR, WIREGUARD_CONFIG_DIR, get_instance_config_dir, stop_primary_interfaces,
sync_interface_routes,
)
@@ -341,11 +342,8 @@ def restart_wireguard_interfaces(request):
if not (user_acl.enable_reload if mode == 'reload' else user_acl.enable_restart):
return render(request, 'access_denied.html', {'page_title': 'Access Denied'})
# WireGuard is disabled on the primary server in mirror mode: only the cluster workers run the instances
for interface_name in running_interfaces:
if re.fullmatch(r'wg[0-9]+', interface_name) and os.path.isfile(os.path.join(config_dir, f'{interface_name}.conf')):
stop_result = subprocess.run(['wg-quick', 'down', interface_name], capture_output=True, text=True)
if stop_result.returncode != 0:
messages.warning(request, _("Error stopping") + f" {interface_name}|{stop_result.stderr}")
for interface_name, error in stop_primary_interfaces():
messages.warning(request, _("Error stopping") + f" {interface_name}|{error}")
messages.info(request, _(
"WireGuard disabled on the primary server|The interfaces of this server are stopped. Cluster workers "
"keep serving the peers."