clan-cli: Fix bug where --host-key-check is not applied to build-host
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import shlex
|
import shlex
|
||||||
import sys
|
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:
|
def upload_sources(machine: Machine, always_upload_source: bool = False) -> str:
|
||||||
host = machine.build_host
|
host = machine.build_host
|
||||||
env = os.environ.copy()
|
env = host.nix_ssh_env()
|
||||||
env["NIX_SSHOPTS"] = " ".join(host.ssh_cmd_opts())
|
|
||||||
|
|
||||||
if not always_upload_source:
|
if not always_upload_source:
|
||||||
flake_url = (
|
flake_url = (
|
||||||
@@ -121,6 +119,8 @@ def deploy_machine(machines: MachineGroup) -> None:
|
|||||||
machine,
|
machine,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
env = host.nix_ssh_env()
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"nixos-rebuild",
|
"nixos-rebuild",
|
||||||
"switch",
|
"switch",
|
||||||
@@ -142,10 +142,10 @@ def deploy_machine(machines: MachineGroup) -> None:
|
|||||||
target_host = f"{target_host.user or 'root'}@{target_host.host}"
|
target_host = f"{target_host.user or 'root'}@{target_host.host}"
|
||||||
cmd.extend(["--target-host", target_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
|
# re-retry switch if the first time fails
|
||||||
if ret.returncode != 0:
|
if ret.returncode != 0:
|
||||||
ret = host.run(cmd)
|
ret = host.run(cmd, extra_env=env)
|
||||||
|
|
||||||
machines.run_function(deploy)
|
machines.run_function(deploy)
|
||||||
|
|
||||||
|
|||||||
@@ -143,6 +143,9 @@ class HostKeyCheck(Enum):
|
|||||||
description = "Choose from: " + ", ".join(HostKeyCheck.__members__)
|
description = "Choose from: " + ", ".join(HostKeyCheck.__members__)
|
||||||
raise ClanError(msg, description=description)
|
raise ClanError(msg, description=description)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return self.name.lower()
|
||||||
|
|
||||||
def to_ssh_opt(self) -> list[str]:
|
def to_ssh_opt(self) -> list[str]:
|
||||||
match self:
|
match self:
|
||||||
case HostKeyCheck.STRICT:
|
case HostKeyCheck.STRICT:
|
||||||
@@ -510,6 +513,11 @@ class Host:
|
|||||||
timeout=timeout,
|
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(
|
def ssh_cmd_opts(
|
||||||
self,
|
self,
|
||||||
verbose_ssh: bool = False,
|
verbose_ssh: bool = False,
|
||||||
|
|||||||
Reference in New Issue
Block a user