skip machines without target_host when running clan machines update
All checks were successful
checks-impure / test (pull_request) Successful in 1m45s
checks / test (pull_request) Successful in 2m57s

This commit is contained in:
Jörg Thalheim 2024-02-06 14:45:21 +01:00
parent 71d14eb178
commit 91f26a4743
2 changed files with 17 additions and 4 deletions

View File

@ -49,9 +49,8 @@ class Machine:
@property
def target_host(self) -> str:
# deploymentAddress is deprecated.
val = (
self.deployment_info.get("targetHost")
or self.deployment_info["deploymentAddress"]
val = self.deployment_info.get("targetHost") or self.deployment_info.get(
"deploymentAddress"
)
if val is None:
msg = f"the 'clan.networking.targetHost' nixos option is not set for machine '{self.name}'"

View File

@ -4,6 +4,7 @@ import logging
import os
import shlex
import subprocess
import sys
from pathlib import Path
from ..cmd import run
@ -152,15 +153,28 @@ def get_all_machines(clan_dir: Path) -> HostGroup:
machines = json.loads(Path(machines_json.rstrip()).read_text())
hosts = []
ignored_machines = []
for name, machine_data in machines.items():
# very hacky. would be better to do a MachinesGroup instead
machine = Machine(name=name, flake=clan_dir, deployment_info=machine_data)
try:
machine.target_host
except ClanError:
ignored_machines.append(name)
continue
host = parse_deployment_address(
name,
host=machine.target_host,
meta={"machine": machine},
)
hosts.append(host)
if not hosts and ignored_machines != []:
print(
"WARNING: No machines to update. The following defined machines were ignored because they do not have `clan.networking.targetHost` nixos option set:",
file=sys.stderr,
)
for machine in ignored_machines:
print(machine, file=sys.stderr)
# very hacky. would be better to do a MachinesGroup instead
return HostGroup(hosts)