clan_lib: implement check_zerotier_running for network overview

This commit is contained in:
Qubasa
2025-09-16 21:12:22 +02:00
parent 104058b79c
commit 9b39ca42e0
2 changed files with 30 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ from dataclasses import dataclass
from clan_lib.errors import ClanError
from clan_lib.network import Network, NetworkTechnologyBase, Peer
from clan_lib.network.zerotier.lib import check_zerotier_running
from clan_lib.ssh.remote import Remote
log = logging.getLogger(__name__)
@@ -14,7 +15,7 @@ log = logging.getLogger(__name__)
@dataclass(frozen=True)
class NetworkTechnology(NetworkTechnologyBase):
def is_running(self) -> bool:
return True
return check_zerotier_running()
def ping(self, remote: Remote) -> None | float:
if self.is_running():
@@ -32,6 +33,7 @@ class NetworkTechnology(NetworkTechnologyBase):
@contextmanager
def connection(self, network: Network) -> Iterator[Network]:
# TODO: Implement userspace ZeroTier service start/stop
yield network
def remote(self, peer: Peer) -> "Remote":

View File

@@ -0,0 +1,27 @@
import contextlib
import json
import urllib.request
from typing import TypedDict
class ZeroTierConfig(TypedDict):
clock: int
online: bool
version: str
versionBuild: int
versionMajor: int
versionMinor: int
versionRev: int
def get_zerotier_health() -> ZeroTierConfig:
# Placeholder for actual ZeroTier running check
res = urllib.request.urlopen("http://localhost:9993/health")
return json.load(res)
def check_zerotier_running() -> bool:
with contextlib.suppress(urllib.error.URLError):
get_zerotier_health()
return True
return False