prevent nesting of services

This commit is contained in:
Abel Luck 2023-11-06 13:14:58 +01:00
parent 292abae384
commit 5da9d04d7e

View file

@ -55,7 +55,7 @@ settings = Settings() # type: ignore[call-arg]
CACHE_SD = [] CACHE_SD = []
async def tailscale_devices() -> List: async def tailscale_devices() -> List[Dict]:
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
try: try:
# https://github.com/tailscale/tailscale/blob/main/api.md#tailnet-devices-get # https://github.com/tailscale/tailscale/blob/main/api.md#tailnet-devices-get
@ -107,7 +107,7 @@ async def matrix_node_sd(device) -> Dict:
return group_by_type(data) return group_by_type(data)
def matrix_workers_to_sd(tailnet, device, workers) -> List: def matrix_workers_to_sd(tailnet, device, workers) -> List[Dict]:
if len(workers) == 0: if len(workers) == 0:
return [] return []
ipv4 = ipv4_only(device["addresses"])[0] ipv4 = ipv4_only(device["addresses"])[0]
@ -134,8 +134,8 @@ def matrix_workers_to_sd(tailnet, device, workers) -> List:
return target_groups return target_groups
async def matrix_sd(tailnet, devices) -> List: async def matrix_sd(tailnet, devices) -> List[Dict]:
sd = [] sd: List[Dict] = []
for device in devices: for device in devices:
if MATRIX_TAG not in device["tags"]: if MATRIX_TAG not in device["tags"]:
continue continue
@ -150,12 +150,12 @@ async def matrix_sd(tailnet, devices) -> List:
workers = {} workers = {}
targets = matrix_workers_to_sd(tailnet, device, workers) targets = matrix_workers_to_sd(tailnet, device, workers)
if targets: if targets:
sd.append(targets) sd = sd + targets
log.info(f"Found {len(sd)} matrix servcies") log.info(f"Found {len(sd)} matrix servcies")
return sd return sd
def plain_devices_sd(tailnet, devices) -> List: def plain_devices_sd(tailnet, devices) -> List[Dict]:
sd = [] sd = []
for device in devices: for device in devices:
targets = ipv4_only(device["addresses"]) targets = ipv4_only(device["addresses"])