fix(tess/morph): skip creating existing machine

This commit is contained in:
Johannes Kirschbauer
2025-06-11 16:50:44 +02:00
parent b6a0c6cb38
commit e80a3fd2fc
2 changed files with 30 additions and 26 deletions

View File

@@ -29,7 +29,8 @@ class CreateOptions:
@API.register
def create_machine(
opts: CreateOptions, commit: bool = True, _persist: bool = True
opts: CreateOptions,
commit: bool = True,
) -> None:
"""
Create a new machine in the clan directory.
@@ -60,10 +61,11 @@ def create_machine(
raise ClanError(msg, location="Create Machine")
with machine_template(
flake=opts.clan_dir, template_ident=opts.template, dst_machine_name=machine_name
flake=opts.clan_dir,
template_ident=opts.template,
dst_machine_name=machine_name,
) as _machine_dir:
# Write to the inventory if persist is true
if _persist:
target_host = opts.target_host
new_machine = opts.machine
new_machine["deploy"] = {"targetHost": target_host} # type: ignore

View File

@@ -11,6 +11,7 @@ from clan_lib.cmd import Log, RunOpts, run
from clan_lib.dirs import get_clan_flake_toplevel_or_env
from clan_lib.errors import ClanError
from clan_lib.flake import Flake
from clan_lib.machines.actions import list_machines
from clan_lib.machines.machines import Machine
from clan_lib.nix import nix_build, nix_command
from clan_lib.nix_models.clan import InventoryMachine
@@ -69,12 +70,13 @@ def morph_machine(
if name is None:
name = random_hostname()
if name not in list_machines(flake):
create_opts = CreateOptions(
template=template,
machine=InventoryMachine(name=name),
clan_dir=Flake(str(flakedir)),
)
create_machine(create_opts, commit=False, _persist=False)
create_machine(create_opts, commit=False)
machine = Machine(name=name, flake=Flake(str(flakedir)))