From 91f26a4743ab408b9f0fca3770b7f69c69e7186c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 6 Feb 2024 14:45:21 +0100 Subject: [PATCH] skip machines without target_host when running `clan machines update` --- pkgs/clan-cli/clan_cli/machines/machines.py | 5 ++--- pkgs/clan-cli/clan_cli/machines/update.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) 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)