re-store controllmaster in various places where it got removed.

This commit is contained in:
Jörg Thalheim
2025-05-27 15:39:09 +02:00
parent f3cdcef523
commit ddab4b5b94
7 changed files with 28 additions and 35 deletions

View File

@@ -4,6 +4,7 @@ from pathlib import Path
from tempfile import TemporaryDirectory
from clan_lib.machines.machines import Machine
from clan_lib.ssh.remote import Remote
from clan_cli.completions import add_dynamic_completer, complete_machines
from clan_cli.ssh.upload import upload
@@ -11,9 +12,7 @@ from clan_cli.ssh.upload import upload
log = logging.getLogger(__name__)
def upload_secrets(machine: Machine) -> None:
host = machine.target_host()
def upload_secrets(machine: Machine, host: Remote) -> None:
if not machine.secret_facts_store.needs_upload(host):
machine.info("Secrets already uploaded")
return
@@ -27,7 +26,8 @@ def upload_secrets(machine: Machine) -> None:
def upload_command(args: argparse.Namespace) -> None:
machine = Machine(name=args.machine, flake=args.flake)
upload_secrets(machine)
with machine.target_host().ssh_control_master() as host:
upload_secrets(machine, host)
def register_upload_parser(parser: argparse.ArgumentParser) -> None:

View File

@@ -98,12 +98,8 @@ def upload(
raise ClanError(msg)
# TODO accept `input` to be an IO object instead of bytes so that we don't have to read the tarfile into memory.
with (
tar_path.open("rb") as f,
host.ssh_control_master() as ssh,
ssh.become_root() as sudo_ssh,
):
sudo_ssh.run(
with tar_path.open("rb") as f:
host.run(
[
"bash",
"-c",

View File

@@ -149,8 +149,7 @@ class SecretStore(StoreBase):
def needs_upload(self, host: Remote) -> bool:
local_hash = self.generate_hash()
with host.ssh_control_master() as ssh:
remote_hash = ssh.run(
remote_hash = host.run(
# TODO get the path to the secrets from the machine
[
"cat",

View File

@@ -28,7 +28,7 @@ def upload_command(args: argparse.Namespace) -> None:
populate_secret_vars(machine, directory)
return
host = machine.target_host()
with machine.target_host().ssh_control_master() as host:
upload_secret_vars(machine, host)

View File

@@ -17,8 +17,7 @@ def list_provider(machine: Machine, host: Remote, provider: str) -> list[Backup]
results = []
backup_metadata = machine.eval_nix("config.clan.core.backups")
list_command = backup_metadata["providers"][provider]["list"]
with host.ssh_control_master() as ssh:
proc = ssh.run(
proc = host.run(
[list_command],
RunOpts(log=Log.NONE, check=False),
)
@@ -44,7 +43,7 @@ def list_provider(machine: Machine, host: Remote, provider: str) -> list[Backup]
def list_backups(machine: Machine, provider: str | None = None) -> list[Backup]:
backup_metadata = machine.eval_nix("config.clan.core.backups")
results = []
host = machine.target_host()
with machine.target_host().ssh_control_master() as host:
if provider is None:
for _provider in backup_metadata["providers"]:
results += list_provider(machine, host, _provider)

View File

@@ -58,8 +58,7 @@ def restore_backup(
service: str | None = None,
) -> None:
errors = []
host = machine.target_host()
with host.ssh_control_master():
with machine.target_host().ssh_control_master() as host:
if service is None:
backup_folders = machine.eval_nix("config.clan.core.state")
for _service in backup_folders: