diff --git a/pkgs/clan-cli/clan_cli/machines/machines.py b/pkgs/clan-cli/clan_cli/machines/machines.py index b1c7eeee..d928b3ee 100644 --- a/pkgs/clan-cli/clan_cli/machines/machines.py +++ b/pkgs/clan-cli/clan_cli/machines/machines.py @@ -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}'" diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index d613c106..13fc925e 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -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)