clan-cli: Fix bug where --host-key-check is not applied to build-host

This commit is contained in:
Qubasa
2024-10-08 03:02:59 +02:00
parent 1090289416
commit b05fd96c0c
2 changed files with 13 additions and 5 deletions

View File

@@ -1,7 +1,6 @@
import argparse
import json
import logging
import os
import shlex
import sys
@@ -33,8 +32,7 @@ def is_path_input(node: dict[str, dict[str, str]]) -> bool:
def upload_sources(machine: Machine, always_upload_source: bool = False) -> str:
host = machine.build_host
env = os.environ.copy()
env["NIX_SSHOPTS"] = " ".join(host.ssh_cmd_opts())
env = host.nix_ssh_env()
if not always_upload_source:
flake_url = (
@@ -121,6 +119,8 @@ def deploy_machine(machines: MachineGroup) -> None:
machine,
)
env = host.nix_ssh_env()
cmd = [
"nixos-rebuild",
"switch",
@@ -142,10 +142,10 @@ def deploy_machine(machines: MachineGroup) -> None:
target_host = f"{target_host.user or 'root'}@{target_host.host}"
cmd.extend(["--target-host", target_host])
ret = host.run(cmd, check=False)
ret = host.run(cmd, extra_env=env, check=False)
# re-retry switch if the first time fails
if ret.returncode != 0:
ret = host.run(cmd)
ret = host.run(cmd, extra_env=env)
machines.run_function(deploy)

View File

@@ -143,6 +143,9 @@ class HostKeyCheck(Enum):
description = "Choose from: " + ", ".join(HostKeyCheck.__members__)
raise ClanError(msg, description=description)
def __str__(self) -> str:
return self.name.lower()
def to_ssh_opt(self) -> list[str]:
match self:
case HostKeyCheck.STRICT:
@@ -510,6 +513,11 @@ class Host:
timeout=timeout,
)
def nix_ssh_env(self) -> dict[str, str]:
env = os.environ.copy()
env["NIX_SSHOPTS"] = " ".join(self.ssh_cmd_opts())
return env
def ssh_cmd_opts(
self,
verbose_ssh: bool = False,