refactor: replace eval_nix/build_nix with machine.select()

- Remove nix(), eval_nix(), and build_nix() methods from Machine class
- Add select() method that handles machine-specific attribute prefixes
- Update all usages to use machine.select() directly
- Handle Path conversion and tmp_store logic at call sites
- This simplifies the Machine API and prepares for deployment.json removal
This commit is contained in:
lassulus
2025-06-29 16:35:19 +02:00
parent b51dddaffc
commit 286c75a142
11 changed files with 44 additions and 60 deletions

View File

@@ -4,7 +4,7 @@ from clan_lib.machines.machines import Machine
def create_backup(machine: Machine, provider: str | None = None) -> None:
machine.info(f"creating backup for {machine.name}")
backup_scripts = machine.eval_nix("config.clan.core.backups")
backup_scripts = machine.select("config.clan.core.backups")
host = machine.target_host()
if provider is None:
if not backup_scripts["providers"]:

View File

@@ -15,7 +15,7 @@ class Backup:
def list_provider(machine: Machine, host: Remote, provider: str) -> list[Backup]:
results = []
backup_metadata = machine.eval_nix("config.clan.core.backups")
backup_metadata = machine.select("config.clan.core.backups")
list_command = backup_metadata["providers"][provider]["list"]
proc = host.run(
[list_command],
@@ -41,7 +41,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")
backup_metadata = machine.select("config.clan.core.backups")
results = []
with machine.target_host().ssh_control_master() as host:
if provider is None:

View File

@@ -7,8 +7,8 @@ from clan_lib.ssh.remote import Remote
def restore_service(
machine: Machine, host: Remote, name: str, provider: str, service: str
) -> None:
backup_metadata = machine.eval_nix("config.clan.core.backups")
backup_folders = machine.eval_nix("config.clan.core.state")
backup_metadata = machine.select("config.clan.core.backups")
backup_folders = machine.select("config.clan.core.state")
if service not in backup_folders:
msg = f"Service {service} not found in configuration. Available services are: {', '.join(backup_folders.keys())}"
@@ -60,7 +60,7 @@ def restore_backup(
errors = []
with machine.target_host().ssh_control_master() as host:
if service is None:
backup_folders = machine.eval_nix("config.clan.core.state")
backup_folders = machine.select("config.clan.core.state")
for _service in backup_folders:
try:
restore_service(machine, host, name, provider, _service)