Merge pull request 'UI: Resolve some more install blockers' (#4657) from feat-ui into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/4657
This commit is contained in:
@@ -504,9 +504,9 @@ def _generate_vars_for_machine(
|
||||
@API.register
|
||||
def run_generators(
|
||||
machine_name: str,
|
||||
generators: list[str],
|
||||
all_prompt_values: dict[str, dict[str, str]],
|
||||
base_dir: Path,
|
||||
generators: list[str] | None = None,
|
||||
no_sandbox: bool = False,
|
||||
) -> bool:
|
||||
"""Run the specified generators for a machine.
|
||||
@@ -526,16 +526,20 @@ def run_generators(
|
||||
from clan_lib.machines.machines import Machine
|
||||
|
||||
machine = Machine(name=machine_name, flake=Flake(str(base_dir)))
|
||||
generators_set = set(generators)
|
||||
generators_ = [
|
||||
g
|
||||
for g in Generator.get_machine_generators(machine_name, machine.flake)
|
||||
if g.name in generators_set
|
||||
]
|
||||
|
||||
if not generators:
|
||||
filtered_generators = Generator.get_machine_generators(
|
||||
machine_name, machine.flake
|
||||
)
|
||||
else:
|
||||
generators_set = set(generators)
|
||||
filtered_generators = [
|
||||
g
|
||||
for g in Generator.get_machine_generators(machine_name, machine.flake)
|
||||
if g.name in generators_set
|
||||
]
|
||||
return _generate_vars_for_machine(
|
||||
machine=machine,
|
||||
generators=generators_,
|
||||
generators=filtered_generators,
|
||||
all_prompt_values=all_prompt_values,
|
||||
no_sandbox=no_sandbox,
|
||||
)
|
||||
|
||||
@@ -3,9 +3,9 @@ import logging
|
||||
import sys
|
||||
import termios
|
||||
import tty
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, field
|
||||
from getpass import getpass
|
||||
from typing import Any
|
||||
from typing import Any, TypedDict
|
||||
|
||||
from clan_lib.errors import ClanError
|
||||
|
||||
@@ -22,6 +22,13 @@ class PromptType(enum.Enum):
|
||||
MULTILINE_HIDDEN = "multiline-hidden"
|
||||
|
||||
|
||||
class Display(TypedDict):
|
||||
label: str | None
|
||||
group: str | None
|
||||
helperText: str | None
|
||||
required: bool
|
||||
|
||||
|
||||
@dataclass
|
||||
class Prompt:
|
||||
name: str
|
||||
@@ -30,6 +37,16 @@ class Prompt:
|
||||
|
||||
persist: bool = False
|
||||
previous_value: str | None = None
|
||||
display: Display = field(
|
||||
default_factory=lambda: Display(
|
||||
{
|
||||
"label": None,
|
||||
"group": None,
|
||||
"helperText": None,
|
||||
"required": False,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_nix(cls: type["Prompt"], data: dict[str, Any]) -> "Prompt":
|
||||
@@ -38,6 +55,7 @@ class Prompt:
|
||||
description=data.get("description", data["name"]),
|
||||
prompt_type=PromptType(data.get("type", "line")),
|
||||
persist=data.get("persist", False),
|
||||
display=data.get("display", {}),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,14 @@ from typing import Any, TypedDict
|
||||
|
||||
from clan_lib.api import API
|
||||
from clan_lib.errors import ClanError
|
||||
from clan_lib.flake import Flake
|
||||
from clan_lib.nix_models.clan import InventoryInstanceModuleType
|
||||
from clan_lib.flake.flake import Flake
|
||||
from clan_lib.nix_models.clan import (
|
||||
InventoryInstance,
|
||||
InventoryInstanceModuleType,
|
||||
InventoryInstanceRolesType,
|
||||
)
|
||||
from clan_lib.persist.inventory_store import InventoryStore
|
||||
from clan_lib.persist.util import set_value_by_path
|
||||
|
||||
|
||||
class CategoryInfo(TypedDict):
|
||||
@@ -246,6 +252,57 @@ def get_service_module_schema(
|
||||
)
|
||||
|
||||
|
||||
@API.register
|
||||
def create_service_instance(
|
||||
flake: Flake,
|
||||
module_ref: InventoryInstanceModuleType,
|
||||
roles: InventoryInstanceRolesType,
|
||||
) -> None:
|
||||
"""
|
||||
Show information about a module
|
||||
"""
|
||||
input_name, module_name = check_service_module_ref(flake, module_ref)
|
||||
|
||||
inventory_store = InventoryStore(flake)
|
||||
|
||||
inventory = inventory_store.read()
|
||||
|
||||
# TODO: Multiple instances support
|
||||
instance_name = module_name
|
||||
curr_instances = inventory.get("instances", {})
|
||||
|
||||
if instance_name in curr_instances:
|
||||
msg = f"Instance '{instance_name}' already exists in the inventory"
|
||||
raise ClanError(msg)
|
||||
|
||||
# TODO: Check the roles against the schema
|
||||
schema = get_service_module_schema(flake, module_ref)
|
||||
for role_name, _role in roles.items():
|
||||
if role_name not in schema:
|
||||
msg = f"Role '{role_name}' is not defined in the module schema"
|
||||
raise ClanError(msg)
|
||||
|
||||
# TODO: Validate roles against the schema
|
||||
|
||||
# Create a new instance with the given roles
|
||||
new_instance: InventoryInstance = {
|
||||
"module": {
|
||||
"name": module_name,
|
||||
"input": input_name,
|
||||
},
|
||||
"roles": roles,
|
||||
}
|
||||
|
||||
set_value_by_path(inventory, f"instances.{instance_name}", new_instance)
|
||||
inventory_store.write(
|
||||
inventory,
|
||||
message=f"Add service instance '{instance_name}' with module '{module_name} from {input_name}'",
|
||||
commit=True,
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
|
||||
@dataclass
|
||||
class LegacyModuleInfo:
|
||||
description: str
|
||||
|
||||
Reference in New Issue
Block a user