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 @property
def target_host(self) -> str: def target_host(self) -> str:
# deploymentAddress is deprecated. # deploymentAddress is deprecated.
val = ( val = self.deployment_info.get("targetHost") or self.deployment_info.get(
self.deployment_info.get("targetHost") "deploymentAddress"
or self.deployment_info["deploymentAddress"]
) )
if val is None: if val is None:
msg = f"the 'clan.networking.targetHost' nixos option is not set for machine '{self.name}'" 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 os
import shlex import shlex
import subprocess import subprocess
import sys
from pathlib import Path from pathlib import Path
from ..cmd import run 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()) machines = json.loads(Path(machines_json.rstrip()).read_text())
hosts = [] hosts = []
ignored_machines = []
for name, machine_data in machines.items(): 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) 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( host = parse_deployment_address(
name, name,
host=machine.target_host, host=machine.target_host,
meta={"machine": machine}, meta={"machine": machine},
) )
hosts.append(host) 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) return HostGroup(hosts)