share filtering logic
This commit is contained in:
parent
5486d923bd
commit
2bf137847d
1 changed files with 10 additions and 2 deletions
|
|
@ -137,8 +137,8 @@ def matrix_workers_to_sd(tailnet, device, workers) -> List[Dict]:
|
||||||
return target_groups
|
return target_groups
|
||||||
|
|
||||||
|
|
||||||
async def matrix_sd(tailnet, devices) -> List[Dict]:
|
def filter_devices(devices) -> List[Dict]:
|
||||||
sd: List[Dict] = []
|
devices_filtered = []
|
||||||
for device in devices:
|
for device in devices:
|
||||||
hostname = device.get("hostname", None)
|
hostname = device.get("hostname", None)
|
||||||
if not hostname:
|
if not hostname:
|
||||||
|
|
@ -150,6 +150,13 @@ async def matrix_sd(tailnet, devices) -> List[Dict]:
|
||||||
extra={"device": device},
|
extra={"device": device},
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
devices_filtered.append(device)
|
||||||
|
return devices_filtered
|
||||||
|
|
||||||
|
|
||||||
|
async def matrix_sd(tailnet, devices) -> List[Dict]:
|
||||||
|
sd: List[Dict] = []
|
||||||
|
for device in devices:
|
||||||
if MATRIX_TAG not in device["tags"]:
|
if MATRIX_TAG not in device["tags"]:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
|
@ -190,6 +197,7 @@ async def poll_sd(settings: Settings):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
devices = await tailscale_devices(settings)
|
devices = await tailscale_devices(settings)
|
||||||
|
devices = filter_devices(devices)
|
||||||
device_targets = plain_devices_sd(settings.tailnet, devices)
|
device_targets = plain_devices_sd(settings.tailnet, devices)
|
||||||
matrix_targets = await matrix_sd(settings.tailnet, devices)
|
matrix_targets = await matrix_sd(settings.tailnet, devices)
|
||||||
CACHE_SD = matrix_targets + device_targets
|
CACHE_SD = matrix_targets + device_targets
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue