various fixes
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from clan_lib.templates import list_templates
|
from clan_lib.templates import list_templates
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
import argparse
|
||||||
|
|
||||||
from clan_lib.nix_models.clan import TemplateClanType
|
from clan_lib.nix_models.clan import TemplateClanType
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|||||||
@@ -277,9 +277,9 @@ def construct_value(
|
|||||||
inner_types = unwrap_union_type(t)
|
inner_types = unwrap_union_type(t)
|
||||||
# Construct the field value
|
# Construct the field value
|
||||||
errors = []
|
errors = []
|
||||||
for t in inner_types:
|
for inner_type in inner_types:
|
||||||
try:
|
try:
|
||||||
return construct_value(t, field_value, loc)
|
return construct_value(inner_type, field_value, loc)
|
||||||
except ClanError as exc:
|
except ClanError as exc:
|
||||||
errors.append(exc)
|
errors.append(exc)
|
||||||
continue
|
continue
|
||||||
@@ -392,7 +392,7 @@ def construct_dataclass[T: Any](
|
|||||||
field_values[field.name] = None
|
field_values[field.name] = None
|
||||||
else:
|
else:
|
||||||
field_values[field.name] = construct_value(
|
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.
|
# Check that all required field are present.
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ def get_clan_details(flake: Flake) -> InventoryMeta:
|
|||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def get_clan_details_schema(flake: Flake) -> dict[str, FieldSchema]:
|
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.
|
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:
|
Returns:
|
||||||
dict[str, FieldSchema]: A map from field-names to { 'readonly' (bool) and 'reason' (str or None ) }
|
dict[str, FieldSchema]: A map from field-names to { 'readonly' (bool) and 'reason' (str or None ) }
|
||||||
"""
|
|
||||||
|
|
||||||
|
"""
|
||||||
inventory_store = InventoryStore(flake)
|
inventory_store = InventoryStore(flake)
|
||||||
write_info = inventory_store.get_writeability()
|
write_info = inventory_store.get_writeability()
|
||||||
|
|
||||||
|
|||||||
@@ -140,14 +140,16 @@ def run_machine_update(
|
|||||||
"""
|
"""
|
||||||
with ExitStack() as stack:
|
with ExitStack() as stack:
|
||||||
_target_host: Host = cast(
|
_target_host: Host = cast(
|
||||||
Host, stack.enter_context(target_host.host_connection())
|
"Host", stack.enter_context(target_host.host_connection())
|
||||||
)
|
)
|
||||||
_build_host: Host
|
_build_host: Host
|
||||||
# If no build host is specified, use the target host as the build host.
|
# If no build host is specified, use the target host as the build host.
|
||||||
if build_host is None:
|
if build_host is None:
|
||||||
_build_host = _target_host
|
_build_host = _target_host
|
||||||
else:
|
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.
|
# Some operations require root privileges on the target host.
|
||||||
target_host_root = stack.enter_context(_target_host.become_root())
|
target_host_root = stack.enter_context(_target_host.become_root())
|
||||||
|
|||||||
@@ -14,15 +14,13 @@ class TagList:
|
|||||||
|
|
||||||
@API.register
|
@API.register
|
||||||
def list_tags(flake: Flake) -> TagList:
|
def list_tags(flake: Flake) -> TagList:
|
||||||
"""
|
"""List all tags of a clan.
|
||||||
List all tags of a clan.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
- 'options' - Existing Tags that can be added to machines
|
- '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.
|
- '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_store = InventoryStore(flake=flake)
|
||||||
inventory = inventory_store.read()
|
inventory = inventory_store.read()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user