Merge pull request 'Inventory: init: deployment info for machines' (#1767) from hsjobeki/clan-core:hsjobeki-main into main
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
# ruff: noqa: N815
|
||||
# ruff: noqa: N806
|
||||
import json
|
||||
from dataclasses import asdict, dataclass, field, is_dataclass
|
||||
from pathlib import Path
|
||||
@@ -35,6 +37,15 @@ def dataclass_to_dict(obj: Any) -> Any:
|
||||
return obj
|
||||
|
||||
|
||||
@dataclass
|
||||
class DeploymentInfo:
|
||||
"""
|
||||
Deployment information for a machine.
|
||||
"""
|
||||
|
||||
targetHost: str | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Machine:
|
||||
"""
|
||||
@@ -49,19 +60,29 @@ class Machine:
|
||||
"""
|
||||
|
||||
name: str
|
||||
system: Literal["x86_64-linux"] | str | None = None
|
||||
deploy: DeploymentInfo = field(default_factory=DeploymentInfo)
|
||||
description: str | None = None
|
||||
icon: str | None = None
|
||||
tags: list[str] = field(default_factory=list)
|
||||
system: Literal["x86_64-linux"] | str | None = None
|
||||
|
||||
@staticmethod
|
||||
def from_dict(d: dict[str, Any]) -> "Machine":
|
||||
return Machine(**d)
|
||||
def from_dict(data: dict[str, Any]) -> "Machine":
|
||||
targetHost = data.get("deploy", {}).get("targetHost", None)
|
||||
return Machine(
|
||||
name=data["name"],
|
||||
description=data.get("description", None),
|
||||
icon=data.get("icon", None),
|
||||
tags=data.get("tags", []),
|
||||
system=data.get("system", None),
|
||||
deploy=DeploymentInfo(targetHost),
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class MachineServiceConfig:
|
||||
config: dict[str, Any] | None = None
|
||||
config: dict[str, Any] = field(default_factory=dict)
|
||||
imports: list[str] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -73,6 +94,8 @@ class ServiceMeta:
|
||||
|
||||
@dataclass
|
||||
class Role:
|
||||
config: dict[str, Any] = field(default_factory=dict)
|
||||
imports: list[str] = field(default_factory=list)
|
||||
machines: list[str] = field(default_factory=list)
|
||||
tags: list[str] = field(default_factory=list)
|
||||
|
||||
@@ -81,6 +104,8 @@ class Role:
|
||||
class Service:
|
||||
meta: ServiceMeta
|
||||
roles: dict[str, Role]
|
||||
config: dict[str, Any] = field(default_factory=dict)
|
||||
imports: list[str] = field(default_factory=list)
|
||||
machines: dict[str, MachineServiceConfig] = field(default_factory=dict)
|
||||
|
||||
@staticmethod
|
||||
@@ -96,6 +121,8 @@ class Service:
|
||||
if d.get("machines")
|
||||
else {}
|
||||
),
|
||||
config=d.get("config", {}),
|
||||
imports=d.get("imports", []),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ def substitute(
|
||||
line = line.replace(
|
||||
"git+https://git.clan.lol/clan/clan-core", str(clan_core_flake)
|
||||
)
|
||||
line = line.replace(
|
||||
"https://git.clan.lol/clan/clan-core/archive/main.tar.gz",
|
||||
str(clan_core_flake),
|
||||
)
|
||||
line = line.replace("__CLAN_SOPS_KEY_PATH__", sops_key)
|
||||
line = line.replace("__CLAN_SOPS_KEY_DIR__", str(flake))
|
||||
print(line, end="")
|
||||
|
||||
@@ -3,6 +3,7 @@ import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fixtures_flakes import substitute
|
||||
from helpers import cli
|
||||
|
||||
|
||||
@@ -17,7 +18,15 @@ def test_create_flake(
|
||||
|
||||
url = f"{clan_core}#default"
|
||||
cli.run(["flakes", "create", str(flake_dir), f"--url={url}"])
|
||||
|
||||
assert (flake_dir / ".clan-flake").exists()
|
||||
|
||||
# Replace the inputs.clan.url in the template flake.nix
|
||||
substitute(
|
||||
flake_dir / "flake.nix",
|
||||
clan_core,
|
||||
)
|
||||
|
||||
monkeypatch.chdir(flake_dir)
|
||||
cli.run(["machines", "create", "machine1"])
|
||||
capsys.readouterr() # flush cache
|
||||
@@ -55,6 +64,13 @@ def test_ui_template(
|
||||
flake_dir = temporary_home / "test-flake"
|
||||
url = f"{clan_core}#minimal"
|
||||
cli.run(["flakes", "create", str(flake_dir), f"--url={url}"])
|
||||
|
||||
# Replace the inputs.clan.url in the template flake.nix
|
||||
substitute(
|
||||
flake_dir / "flake.nix",
|
||||
clan_core,
|
||||
)
|
||||
|
||||
monkeypatch.chdir(flake_dir)
|
||||
cli.run(["machines", "create", "machine1"])
|
||||
capsys.readouterr() # flush cache
|
||||
|
||||
Reference in New Issue
Block a user