API: rename set_inventory
This commit is contained in:
@@ -7,7 +7,7 @@ from typing import Any, get_args, get_type_hints
|
||||
|
||||
from clan_cli.cmd import run_no_stdout
|
||||
from clan_cli.errors import ClanCmdError, ClanError
|
||||
from clan_cli.inventory import Inventory, load_inventory_json, save_inventory
|
||||
from clan_cli.inventory import Inventory, load_inventory_json, set_inventory
|
||||
from clan_cli.inventory.classes import Service
|
||||
from clan_cli.nix import nix_eval
|
||||
|
||||
@@ -187,7 +187,7 @@ def set_service_instance(
|
||||
|
||||
setattr(inventory.services, module_name, module_instance_map)
|
||||
|
||||
save_inventory(
|
||||
set_inventory(
|
||||
inventory, base_path, f"Update {module_name} instance {instance_name}"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from clan_cli.api import API
|
||||
from clan_cli.inventory import Meta, load_inventory_json, save_inventory
|
||||
from clan_cli.inventory import Meta, load_inventory_json, set_inventory
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -15,6 +15,6 @@ def update_clan_meta(options: UpdateOptions) -> Meta:
|
||||
inventory = load_inventory_json(options.directory)
|
||||
inventory.meta = options.meta
|
||||
|
||||
save_inventory(inventory, options.directory, "Update clan metadata")
|
||||
set_inventory(inventory, options.directory, "Update clan metadata")
|
||||
|
||||
return inventory.meta
|
||||
|
||||
@@ -58,6 +58,7 @@ default_inventory = Inventory(
|
||||
)
|
||||
|
||||
|
||||
@API.register
|
||||
def load_inventory_eval(flake_dir: str | Path) -> Inventory:
|
||||
"""
|
||||
Loads the actual inventory.
|
||||
@@ -89,6 +90,7 @@ def load_inventory_eval(flake_dir: str | Path) -> Inventory:
|
||||
return inventory
|
||||
|
||||
|
||||
@API.register
|
||||
def load_inventory_json(
|
||||
flake_dir: str | Path, default: Inventory = default_inventory
|
||||
) -> Inventory:
|
||||
@@ -116,7 +118,8 @@ def load_inventory_json(
|
||||
return inventory
|
||||
|
||||
|
||||
def save_inventory(inventory: Inventory, flake_dir: str | Path, message: str) -> None:
|
||||
@API.register
|
||||
def set_inventory(inventory: Inventory, flake_dir: str | Path, message: str) -> None:
|
||||
""" "
|
||||
Write the inventory to the flake directory
|
||||
and commit it to git with the given message
|
||||
@@ -143,4 +146,4 @@ def init_inventory(directory: str, init: Inventory | None = None) -> None:
|
||||
# Write inventory.json file
|
||||
if inventory is not None:
|
||||
# Persist creates a commit message for each change
|
||||
save_inventory(inventory, directory, "Init inventory")
|
||||
set_inventory(inventory, directory, "Init inventory")
|
||||
|
||||
@@ -10,7 +10,7 @@ from clan_cli.inventory import (
|
||||
MachineDeploy,
|
||||
load_inventory_eval,
|
||||
load_inventory_json,
|
||||
save_inventory,
|
||||
set_inventory,
|
||||
)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -34,7 +34,7 @@ def create_machine(flake: FlakeId, machine: Machine) -> None:
|
||||
print(f"Define machine {machine.name}", machine)
|
||||
|
||||
inventory.machines.update({machine.name: machine})
|
||||
save_inventory(inventory, flake.path, f"Create machine {machine.name}")
|
||||
set_inventory(inventory, flake.path, f"Create machine {machine.name}")
|
||||
|
||||
|
||||
def create_command(args: argparse.Namespace) -> None:
|
||||
|
||||
@@ -6,7 +6,7 @@ from clan_cli.clan_uri import FlakeId
|
||||
from clan_cli.completions import add_dynamic_completer, complete_machines
|
||||
from clan_cli.dirs import specific_machine_dir
|
||||
from clan_cli.errors import ClanError
|
||||
from clan_cli.inventory import load_inventory_json, save_inventory
|
||||
from clan_cli.inventory import load_inventory_json, set_inventory
|
||||
|
||||
|
||||
@API.register
|
||||
@@ -18,7 +18,7 @@ def delete_machine(flake: FlakeId, name: str) -> None:
|
||||
msg = f"Machine {name} does not exist"
|
||||
raise ClanError(msg)
|
||||
|
||||
save_inventory(inventory, flake.path, f"Delete machine {name}")
|
||||
set_inventory(inventory, flake.path, f"Delete machine {name}")
|
||||
|
||||
folder = specific_machine_dir(flake.path, name)
|
||||
if folder.exists():
|
||||
|
||||
@@ -8,7 +8,7 @@ from typing import Literal
|
||||
from clan_cli.api import API
|
||||
from clan_cli.cmd import run_no_stdout
|
||||
from clan_cli.errors import ClanCmdError, ClanError
|
||||
from clan_cli.inventory import Machine, load_inventory_eval, save_inventory
|
||||
from clan_cli.inventory import Machine, load_inventory_eval, set_inventory
|
||||
from clan_cli.nix import nix_eval, nix_shell
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -20,7 +20,7 @@ def set_machine(flake_url: str | Path, machine_name: str, machine: Machine) -> N
|
||||
|
||||
inventory.machines[machine_name] = machine
|
||||
|
||||
save_inventory(inventory, flake_url, "machines: edit '{machine_name}'")
|
||||
set_inventory(inventory, flake_url, "machines: edit '{machine_name}'")
|
||||
|
||||
|
||||
@API.register
|
||||
|
||||
@@ -8,7 +8,7 @@ from clan_cli.inventory import (
|
||||
Machine,
|
||||
MachineDeploy,
|
||||
load_inventory_json,
|
||||
save_inventory,
|
||||
set_inventory,
|
||||
)
|
||||
from clan_cli.machines.create import create_machine
|
||||
from clan_cli.nix import nix_eval, run_no_stdout
|
||||
@@ -74,7 +74,7 @@ def test_add_module_to_inventory(
|
||||
}
|
||||
}
|
||||
|
||||
save_inventory(inventory, base_path, "Add borgbackup service")
|
||||
set_inventory(inventory, base_path, "Add borgbackup service")
|
||||
|
||||
cmd = ["facts", "generate", "--flake", str(test_flake_with_core.path), "machine1"]
|
||||
cli.run(cmd)
|
||||
|
||||
Reference in New Issue
Block a user