re-store controllmaster in various places where it got removed.
This commit is contained in:
@@ -4,6 +4,7 @@ from pathlib import Path
|
|||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
from clan_lib.machines.machines import Machine
|
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.completions import add_dynamic_completer, complete_machines
|
||||||
from clan_cli.ssh.upload import upload
|
from clan_cli.ssh.upload import upload
|
||||||
@@ -11,9 +12,7 @@ from clan_cli.ssh.upload import upload
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def upload_secrets(machine: Machine) -> None:
|
def upload_secrets(machine: Machine, host: Remote) -> None:
|
||||||
host = machine.target_host()
|
|
||||||
|
|
||||||
if not machine.secret_facts_store.needs_upload(host):
|
if not machine.secret_facts_store.needs_upload(host):
|
||||||
machine.info("Secrets already uploaded")
|
machine.info("Secrets already uploaded")
|
||||||
return
|
return
|
||||||
@@ -27,7 +26,8 @@ def upload_secrets(machine: Machine) -> None:
|
|||||||
|
|
||||||
def upload_command(args: argparse.Namespace) -> None:
|
def upload_command(args: argparse.Namespace) -> None:
|
||||||
machine = Machine(name=args.machine, flake=args.flake)
|
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:
|
def register_upload_parser(parser: argparse.ArgumentParser) -> None:
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ def ssh_shell_from_deploy(
|
|||||||
deploy_info: DeployInfo, runtime: AsyncRuntime, host_key_check: HostKeyCheck
|
deploy_info: DeployInfo, runtime: AsyncRuntime, host_key_check: HostKeyCheck
|
||||||
) -> None:
|
) -> None:
|
||||||
if host := find_reachable_host(deploy_info, host_key_check):
|
if host := find_reachable_host(deploy_info, host_key_check):
|
||||||
host.interactive_ssh()
|
host.interactive_ssh()
|
||||||
else:
|
else:
|
||||||
log.info("Could not reach host via clearnet 'addrs'")
|
log.info("Could not reach host via clearnet 'addrs'")
|
||||||
log.info(f"Trying to reach host via tor '{deploy_info.tor}'")
|
log.info(f"Trying to reach host via tor '{deploy_info.tor}'")
|
||||||
|
|||||||
@@ -98,12 +98,8 @@ def upload(
|
|||||||
raise ClanError(msg)
|
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.
|
# TODO accept `input` to be an IO object instead of bytes so that we don't have to read the tarfile into memory.
|
||||||
with (
|
with tar_path.open("rb") as f:
|
||||||
tar_path.open("rb") as f,
|
host.run(
|
||||||
host.ssh_control_master() as ssh,
|
|
||||||
ssh.become_root() as sudo_ssh,
|
|
||||||
):
|
|
||||||
sudo_ssh.run(
|
|
||||||
[
|
[
|
||||||
"bash",
|
"bash",
|
||||||
"-c",
|
"-c",
|
||||||
|
|||||||
@@ -149,15 +149,14 @@ class SecretStore(StoreBase):
|
|||||||
|
|
||||||
def needs_upload(self, host: Remote) -> bool:
|
def needs_upload(self, host: Remote) -> bool:
|
||||||
local_hash = self.generate_hash()
|
local_hash = self.generate_hash()
|
||||||
with host.ssh_control_master() as ssh:
|
remote_hash = host.run(
|
||||||
remote_hash = ssh.run(
|
# TODO get the path to the secrets from the machine
|
||||||
# TODO get the path to the secrets from the machine
|
[
|
||||||
[
|
"cat",
|
||||||
"cat",
|
f"{self.machine.deployment['password-store']['secretLocation']}/.{self._store_backend}_info",
|
||||||
f"{self.machine.deployment['password-store']['secretLocation']}/.{self._store_backend}_info",
|
],
|
||||||
],
|
RunOpts(log=Log.STDERR, check=False),
|
||||||
RunOpts(log=Log.STDERR, check=False),
|
).stdout.strip()
|
||||||
).stdout.strip()
|
|
||||||
|
|
||||||
if not remote_hash:
|
if not remote_hash:
|
||||||
print("remote hash is empty")
|
print("remote hash is empty")
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ def upload_command(args: argparse.Namespace) -> None:
|
|||||||
populate_secret_vars(machine, directory)
|
populate_secret_vars(machine, directory)
|
||||||
return
|
return
|
||||||
|
|
||||||
host = machine.target_host()
|
with machine.target_host().ssh_control_master() as host:
|
||||||
upload_secret_vars(machine, host)
|
upload_secret_vars(machine, host)
|
||||||
|
|
||||||
|
|
||||||
def register_upload_parser(parser: argparse.ArgumentParser) -> None:
|
def register_upload_parser(parser: argparse.ArgumentParser) -> None:
|
||||||
|
|||||||
@@ -17,11 +17,10 @@ def list_provider(machine: Machine, host: Remote, provider: str) -> list[Backup]
|
|||||||
results = []
|
results = []
|
||||||
backup_metadata = machine.eval_nix("config.clan.core.backups")
|
backup_metadata = machine.eval_nix("config.clan.core.backups")
|
||||||
list_command = backup_metadata["providers"][provider]["list"]
|
list_command = backup_metadata["providers"][provider]["list"]
|
||||||
with host.ssh_control_master() as ssh:
|
proc = host.run(
|
||||||
proc = ssh.run(
|
[list_command],
|
||||||
[list_command],
|
RunOpts(log=Log.NONE, check=False),
|
||||||
RunOpts(log=Log.NONE, check=False),
|
)
|
||||||
)
|
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
# TODO this should be a warning, only raise exception if no providers succeed
|
# TODO this should be a warning, only raise exception if no providers succeed
|
||||||
msg = f"Failed to list backups for provider {provider}:"
|
msg = f"Failed to list backups for provider {provider}:"
|
||||||
@@ -44,12 +43,12 @@ def list_provider(machine: Machine, host: Remote, provider: str) -> list[Backup]
|
|||||||
def list_backups(machine: Machine, provider: str | None = None) -> list[Backup]:
|
def list_backups(machine: Machine, provider: str | None = None) -> list[Backup]:
|
||||||
backup_metadata = machine.eval_nix("config.clan.core.backups")
|
backup_metadata = machine.eval_nix("config.clan.core.backups")
|
||||||
results = []
|
results = []
|
||||||
host = machine.target_host()
|
with machine.target_host().ssh_control_master() as host:
|
||||||
if provider is None:
|
if provider is None:
|
||||||
for _provider in backup_metadata["providers"]:
|
for _provider in backup_metadata["providers"]:
|
||||||
results += list_provider(machine, host, _provider)
|
results += list_provider(machine, host, _provider)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
results += list_provider(machine, host, provider)
|
results += list_provider(machine, host, provider)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ def restore_backup(
|
|||||||
service: str | None = None,
|
service: str | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
errors = []
|
errors = []
|
||||||
host = machine.target_host()
|
with machine.target_host().ssh_control_master() as host:
|
||||||
with host.ssh_control_master():
|
|
||||||
if service is None:
|
if service is None:
|
||||||
backup_folders = machine.eval_nix("config.clan.core.state")
|
backup_folders = machine.eval_nix("config.clan.core.state")
|
||||||
for _service in backup_folders:
|
for _service in backup_folders:
|
||||||
|
|||||||
Reference in New Issue
Block a user