various fixes

This commit is contained in:
Jörg Thalheim
2025-08-26 12:59:49 +02:00
parent 1dda60847e
commit 63697ac4b1
5 changed files with 12 additions and 12 deletions

View File

@@ -1,12 +1,13 @@
from __future__ import annotations
import argparse
import logging
from typing import TYPE_CHECKING
from clan_lib.templates import list_templates
if TYPE_CHECKING:
import argparse
from clan_lib.nix_models.clan import TemplateClanType
log = logging.getLogger(__name__)

View File

@@ -277,9 +277,9 @@ def construct_value(
inner_types = unwrap_union_type(t)
# Construct the field value
errors = []
for t in inner_types:
for inner_type in inner_types:
try:
return construct_value(t, field_value, loc)
return construct_value(inner_type, field_value, loc)
except ClanError as exc:
errors.append(exc)
continue
@@ -392,7 +392,7 @@ def construct_dataclass[T: Any](
field_values[field.name] = None
else:
field_values[field.name] = construct_value(
cast(type, field.type), field_value
cast("type", field.type), field_value
)
# Check that all required field are present.

View File

@@ -38,8 +38,7 @@ def get_clan_details(flake: Flake) -> InventoryMeta:
@API.register
def get_clan_details_schema(flake: Flake) -> dict[str, FieldSchema]:
"""
Get attributes for each field of the clan.
"""Get attributes for each field of the clan.
This function checks which fields of the 'clan' resource are readonly and provides a reason if so.
@@ -48,8 +47,8 @@ def get_clan_details_schema(flake: Flake) -> dict[str, FieldSchema]:
Returns:
dict[str, FieldSchema]: A map from field-names to { 'readonly' (bool) and 'reason' (str or None ) }
"""
"""
inventory_store = InventoryStore(flake)
write_info = inventory_store.get_writeability()

View File

@@ -140,14 +140,16 @@ def run_machine_update(
"""
with ExitStack() as stack:
_target_host: Host = cast(
Host, stack.enter_context(target_host.host_connection())
"Host", stack.enter_context(target_host.host_connection())
)
_build_host: Host
# If no build host is specified, use the target host as the build host.
if build_host is None:
_build_host = _target_host
else:
_build_host = cast(Host, stack.enter_context(build_host.host_connection()))
_build_host = cast(
"Host", stack.enter_context(build_host.host_connection())
)
# Some operations require root privileges on the target host.
target_host_root = stack.enter_context(_target_host.become_root())

View File

@@ -14,15 +14,13 @@ class TagList:
@API.register
def list_tags(flake: Flake) -> TagList:
"""
List all tags of a clan.
"""List all tags of a clan.
Returns:
- 'options' - Existing Tags that can be added to machines
- 'special' - Prefined Tags that are special and cannot be added to machines, they can be used in roles and refer to a fixed set of machines.
"""
inventory_store = InventoryStore(flake=flake)
inventory = inventory_store.read()