clan_cli machines: use Flake instead of FlakeId
This commit is contained in:
@@ -5,10 +5,10 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.api import API
|
||||
from clan_cli.clan_uri import FlakeId
|
||||
from clan_cli.completions import add_dynamic_completer, complete_tags
|
||||
from clan_cli.dirs import get_clan_flake_toplevel_or_env
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.git import commit_file
|
||||
from clan_cli.inventory import Machine as InventoryMachine
|
||||
from clan_cli.inventory import (
|
||||
@@ -29,7 +29,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
@dataclass
|
||||
class CreateOptions:
|
||||
clan_dir: FlakeId
|
||||
clan_dir: Flake
|
||||
machine: InventoryMachine
|
||||
target_host: str | None = None
|
||||
input_prio: InputPrio | None = None
|
||||
@@ -38,7 +38,7 @@ class CreateOptions:
|
||||
|
||||
@API.register
|
||||
def create_machine(opts: CreateOptions) -> None:
|
||||
if not opts.clan_dir.is_local():
|
||||
if not opts.clan_dir.is_local:
|
||||
msg = f"Clan {opts.clan_dir} is not a local clan."
|
||||
description = "Import machine only works on local clans"
|
||||
raise ClanError(msg, description=description)
|
||||
@@ -127,7 +127,7 @@ def create_command(args: argparse.Namespace) -> None:
|
||||
clan_dir = args.flake
|
||||
else:
|
||||
tmp = get_clan_flake_toplevel_or_env()
|
||||
clan_dir = FlakeId(str(tmp)) if tmp else None
|
||||
clan_dir = Flake(str(tmp)) if tmp else None
|
||||
|
||||
if not clan_dir:
|
||||
msg = "No clan found."
|
||||
|
||||
@@ -3,7 +3,7 @@ import logging
|
||||
import shutil
|
||||
|
||||
from clan_cli.api import API
|
||||
from clan_cli.clan_uri import FlakeId
|
||||
from clan_cli.clan_uri import Flake
|
||||
from clan_cli.completions import add_dynamic_completer, complete_machines
|
||||
from clan_cli.dirs import specific_machine_dir
|
||||
from clan_cli.errors import ClanError
|
||||
@@ -13,7 +13,7 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@API.register
|
||||
def delete_machine(flake: FlakeId, name: str) -> None:
|
||||
def delete_machine(flake: Flake, name: str) -> None:
|
||||
inventory = get_inventory(flake.path)
|
||||
|
||||
if "machines" not in inventory:
|
||||
|
||||
@@ -6,11 +6,11 @@ from enum import Enum
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.api import API
|
||||
from clan_cli.clan_uri import FlakeId
|
||||
from clan_cli.cmd import RunOpts, run, run_no_stdout
|
||||
from clan_cli.completions import add_dynamic_completer, complete_machines
|
||||
from clan_cli.dirs import specific_machine_dir
|
||||
from clan_cli.errors import ClanCmdError, ClanError
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.git import commit_file
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.nix import nix_config, nix_eval, nix_shell
|
||||
@@ -102,7 +102,7 @@ def show_machine_hardware_platform(clan_dir: Path, machine_name: str) -> str | N
|
||||
|
||||
@dataclass
|
||||
class HardwareGenerateOptions:
|
||||
flake: FlakeId
|
||||
flake: Flake
|
||||
machine: str
|
||||
backend: HardwareConfig
|
||||
target_host: str | None = None
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from clan_cli.clan_uri import FlakeId
|
||||
from clan_cli.cmd import run
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.nix import nix_build, nix_config, nix_test_store
|
||||
|
||||
from .machines import Machine
|
||||
|
||||
|
||||
# function to speedup eval if we want to evaluate all machines
|
||||
def get_all_machines(flake: FlakeId, nix_options: list[str]) -> list[Machine]:
|
||||
def get_all_machines(flake: Flake, nix_options: list[str]) -> list[Machine]:
|
||||
config = nix_config()
|
||||
system = config["system"]
|
||||
json_path = Path(
|
||||
@@ -37,7 +37,7 @@ def get_all_machines(flake: FlakeId, nix_options: list[str]) -> list[Machine]:
|
||||
|
||||
|
||||
def get_selected_machines(
|
||||
flake: FlakeId, nix_options: list[str], machine_names: list[str]
|
||||
flake: Flake, nix_options: list[str], machine_names: list[str]
|
||||
) -> list[Machine]:
|
||||
machines = []
|
||||
for name in machine_names:
|
||||
|
||||
@@ -8,11 +8,11 @@ from tempfile import NamedTemporaryFile
|
||||
from time import time
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from clan_cli.clan_uri import FlakeId
|
||||
from clan_cli.cmd import RunOpts, run_no_stdout
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.facts import public_modules as facts_public_modules
|
||||
from clan_cli.facts import secret_modules as facts_secret_modules
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.nix import nix_build, nix_config, nix_eval, nix_metadata, nix_test_store
|
||||
from clan_cli.ssh.host import Host
|
||||
from clan_cli.ssh.host_key import HostKeyCheck
|
||||
@@ -28,7 +28,7 @@ if TYPE_CHECKING:
|
||||
@dataclass
|
||||
class Machine:
|
||||
name: str
|
||||
flake: FlakeId
|
||||
flake: Flake
|
||||
nix_options: list[str] = field(default_factory=list)
|
||||
cached_deployment: None | dict[str, Any] = None
|
||||
override_target_host: None | str = None
|
||||
@@ -201,12 +201,7 @@ class Machine:
|
||||
|
||||
@property
|
||||
def flake_dir(self) -> Path:
|
||||
if self.flake.is_local():
|
||||
return self.flake.path
|
||||
if self.flake.is_remote():
|
||||
return Path(nix_metadata(self.flake.url)["path"])
|
||||
msg = f"Unsupported flake url: {self.flake}"
|
||||
raise ClanError(msg)
|
||||
return self.flake.path
|
||||
|
||||
@property
|
||||
def target_host(self) -> Host:
|
||||
|
||||
@@ -8,7 +8,6 @@ import sys
|
||||
|
||||
from clan_cli.api import API
|
||||
from clan_cli.async_run import AsyncContext, AsyncOpts, AsyncRuntime, is_async_cancelled
|
||||
from clan_cli.clan_uri import FlakeId
|
||||
from clan_cli.cmd import MsgColor, RunOpts, run
|
||||
from clan_cli.colors import AnsiColor
|
||||
from clan_cli.completions import (
|
||||
@@ -18,6 +17,7 @@ from clan_cli.completions import (
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.facts.generate import generate_facts
|
||||
from clan_cli.facts.upload import upload_secrets
|
||||
from clan_cli.flake import Flake
|
||||
from clan_cli.inventory import Machine as InventoryMachine
|
||||
from clan_cli.machines.machines import Machine
|
||||
from clan_cli.nix import nix_command, nix_metadata
|
||||
@@ -46,7 +46,7 @@ def upload_sources(machine: Machine) -> str:
|
||||
env = host.nix_ssh_env(os.environ.copy())
|
||||
|
||||
flake_url = (
|
||||
str(machine.flake.path) if machine.flake.is_local() else machine.flake.url
|
||||
str(machine.flake.path) if machine.flake.is_local else machine.flake.identifier
|
||||
)
|
||||
flake_data = nix_metadata(flake_url)
|
||||
has_path_inputs = any(
|
||||
@@ -96,6 +96,7 @@ def update_machines(base_path: str, machines: list[InventoryMachine]) -> None:
|
||||
group_machines: list[Machine] = []
|
||||
|
||||
# Convert InventoryMachine to Machine
|
||||
flake = Flake(base_path)
|
||||
for machine in machines:
|
||||
name = machine.get("name")
|
||||
if not name:
|
||||
@@ -103,7 +104,7 @@ def update_machines(base_path: str, machines: list[InventoryMachine]) -> None:
|
||||
raise ClanError(msg)
|
||||
m = Machine(
|
||||
name,
|
||||
flake=FlakeId(base_path),
|
||||
flake=flake,
|
||||
)
|
||||
if not machine.get("deploy", {}).get("targetHost"):
|
||||
msg = f"'TargetHost' is not set for machine '{name}'"
|
||||
|
||||
Reference in New Issue
Block a user