make machine class now a dataclass

This commit is contained in:
Jörg Thalheim
2024-07-02 14:06:31 +02:00
parent cc583dd79e
commit b4698528ef
23 changed files with 125 additions and 128 deletions

View File

@@ -2,6 +2,7 @@ import argparse
import importlib
import logging
from ..clan_uri import FlakeId
from ..completions import add_dynamic_completer, complete_machines
from ..machines.machines import Machine
@@ -49,7 +50,7 @@ def check_secrets(machine: Machine, service: None | str = None) -> bool:
def check_command(args: argparse.Namespace) -> None:
machine = Machine(
name=args.machine,
flake=args.flake,
flake=FlakeId(args.flake),
)
check_secrets(machine, service=args.service)

View File

@@ -3,6 +3,7 @@ import importlib
import json
import logging
from ..clan_uri import FlakeId
from ..completions import add_dynamic_completer, complete_machines
from ..machines.machines import Machine
@@ -26,7 +27,7 @@ def get_all_facts(machine: Machine) -> dict:
def get_command(args: argparse.Namespace) -> None:
machine = Machine(name=args.machine, flake=args.flake)
machine = Machine(name=args.machine, flake=FlakeId(args.flake))
# the raw_facts are bytestrings making them not json serializable
raw_facts = get_all_facts(machine)

View File

@@ -12,9 +12,13 @@ class FactStore(FactStoreBase):
self.works_remotely = False
def set(self, service: str, name: str, value: bytes) -> Path | None:
if isinstance(self.machine.flake, Path):
if self.machine.flake.is_local():
fact_path = (
self.machine.flake / "machines" / self.machine.name / "facts" / name
self.machine.flake.path
/ "machines"
/ self.machine.name
/ "facts"
/ name
)
fact_path.parent.mkdir(parents=True, exist_ok=True)
fact_path.touch()

View File

@@ -4,6 +4,7 @@ import logging
from pathlib import Path
from tempfile import TemporaryDirectory
from ..clan_uri import FlakeId
from ..cmd import Log, run
from ..completions import add_dynamic_completer, complete_machines
from ..machines.machines import Machine
@@ -44,7 +45,7 @@ def upload_secrets(machine: Machine) -> None:
def upload_command(args: argparse.Namespace) -> None:
machine = Machine(name=args.machine, flake=args.flake)
machine = Machine(name=args.machine, flake=FlakeId(args.flake))
upload_secrets(machine)