fix(morph/test): temporary workaround for morph test
This commit is contained in:
@@ -40,7 +40,19 @@ class CreateOptions:
|
||||
|
||||
|
||||
@API.register
|
||||
def create_machine(opts: CreateOptions, commit: bool = True) -> None:
|
||||
def create_machine(
|
||||
opts: CreateOptions, commit: bool = True, _persist: bool = True
|
||||
) -> None:
|
||||
"""
|
||||
Create a new machine in the clan directory.
|
||||
|
||||
This function will create a new machine based on a template.
|
||||
|
||||
:param opts: Options for creating the machine, including clan directory, machine details, and template name.
|
||||
:param commit: Whether to commit the changes to the git repository.
|
||||
:param _persist: Temporary workaround for 'morph'. Whether to persist the changes to the inventory store.
|
||||
"""
|
||||
|
||||
if not opts.clan_dir.is_local:
|
||||
msg = f"Clan {opts.clan_dir} is not a local clan."
|
||||
description = "Import machine only works on local clans"
|
||||
@@ -91,9 +103,7 @@ def create_machine(opts: CreateOptions, commit: bool = True) -> None:
|
||||
|
||||
if dst.exists():
|
||||
msg = f"Machine {machine_name} already exists in {clan_dir}"
|
||||
description = (
|
||||
"Please remove the existing machine folder"
|
||||
)
|
||||
description = "Please remove the existing machine folder"
|
||||
raise ClanError(msg, description=description)
|
||||
|
||||
# TODO(@Qubasa): move this into the template handler
|
||||
@@ -105,27 +115,27 @@ def create_machine(opts: CreateOptions, commit: bool = True) -> None:
|
||||
# TODO(@Qubasa): move this into the template handler
|
||||
copy_from_nixstore(src, dst)
|
||||
|
||||
target_host = opts.target_host
|
||||
if _persist:
|
||||
target_host = opts.target_host
|
||||
new_machine = opts.machine
|
||||
new_machine["deploy"] = {"targetHost": target_host} # type: ignore
|
||||
|
||||
new_machine = opts.machine
|
||||
new_machine["deploy"] = {"targetHost": target_host} # type: ignore
|
||||
inventory_store = InventoryStore(opts.clan_dir)
|
||||
inventory = inventory_store.read()
|
||||
|
||||
inventory_store = InventoryStore(opts.clan_dir)
|
||||
inventory = inventory_store.read()
|
||||
if machine_name in inventory.get("machines", {}):
|
||||
msg = f"Machine {machine_name} already exists in inventory"
|
||||
description = (
|
||||
"Please delete the existing machine or import with a different name"
|
||||
)
|
||||
raise ClanError(msg, description=description)
|
||||
|
||||
if machine_name in inventory.get("machines", {}):
|
||||
msg = f"Machine {machine_name} already exists in inventory"
|
||||
description = (
|
||||
"Please delete the existing machine or import with a different name"
|
||||
apply_patch(
|
||||
inventory,
|
||||
f"machines.{machine_name}",
|
||||
new_machine,
|
||||
)
|
||||
raise ClanError(msg, description=description)
|
||||
|
||||
apply_patch(
|
||||
inventory,
|
||||
f"machines.{machine_name}",
|
||||
new_machine,
|
||||
)
|
||||
inventory_store.write(inventory, message=f"machine '{machine_name}'")
|
||||
inventory_store.write(inventory, message=f"machine '{machine_name}'")
|
||||
|
||||
# Commit at the end in that order to avoid committing halve-baked machines
|
||||
# TODO: automatic rollbacks if something goes wrong
|
||||
|
||||
@@ -74,7 +74,7 @@ def morph_machine(
|
||||
machine=InventoryMachine(name=name),
|
||||
clan_dir=Flake(str(flakedir)),
|
||||
)
|
||||
create_machine(create_opts, commit=False)
|
||||
create_machine(create_opts, commit=False, _persist=False)
|
||||
|
||||
machine = Machine(name=name, flake=Flake(str(flakedir)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user