Fix(machines/create): check if machine is already created
This commit is contained in:
@@ -106,10 +106,18 @@ def create_machine(opts: CreateOptions, commit: bool = True) -> None:
|
|||||||
target_host = opts.target_host
|
target_host = opts.target_host
|
||||||
|
|
||||||
new_machine = opts.machine
|
new_machine = opts.machine
|
||||||
new_machine["deploy"] = {"targetHost": target_host} # type: ignore
|
new_machine["deploy"] = {"targetHost": target_host} # type: ignore
|
||||||
|
|
||||||
inventory_store = InventoryStore(opts.clan_dir)
|
inventory_store = InventoryStore(opts.clan_dir)
|
||||||
inventory = inventory_store.read()
|
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)
|
||||||
|
|
||||||
apply_patch(
|
apply_patch(
|
||||||
inventory,
|
inventory,
|
||||||
f"machines.{machine_name}",
|
f"machines.{machine_name}",
|
||||||
@@ -153,7 +161,7 @@ def create_command(args: argparse.Namespace) -> None:
|
|||||||
machine = InventoryMachine(
|
machine = InventoryMachine(
|
||||||
name=args.machine_name,
|
name=args.machine_name,
|
||||||
tags=args.tags,
|
tags=args.tags,
|
||||||
deploy=MachineDeploy(),
|
deploy=MachineDeploy(targetHost=args.target_host),
|
||||||
)
|
)
|
||||||
opts = CreateOptions(
|
opts = CreateOptions(
|
||||||
input_prio=input_prio,
|
input_prio=input_prio,
|
||||||
|
|||||||
Reference in New Issue
Block a user