From 91a9fb23be9676e04c0a575f2bd990c18b9f9aac Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Fri, 13 Sep 2024 16:09:45 +0200 Subject: [PATCH] API: rename set_inventory --- pkgs/clan-cli/clan_cli/api/modules.py | 4 ++-- pkgs/clan-cli/clan_cli/clan/update.py | 4 ++-- pkgs/clan-cli/clan_cli/inventory/__init__.py | 7 +++++-- pkgs/clan-cli/clan_cli/machines/create.py | 4 ++-- pkgs/clan-cli/clan_cli/machines/delete.py | 4 ++-- pkgs/clan-cli/clan_cli/machines/list.py | 4 ++-- pkgs/clan-cli/tests/test_modules.py | 4 ++-- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/api/modules.py b/pkgs/clan-cli/clan_cli/api/modules.py index 0decdde15..2cf51abac 100644 --- a/pkgs/clan-cli/clan_cli/api/modules.py +++ b/pkgs/clan-cli/clan_cli/api/modules.py @@ -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}" ) diff --git a/pkgs/clan-cli/clan_cli/clan/update.py b/pkgs/clan-cli/clan_cli/clan/update.py index 65ff096f6..822246615 100644 --- a/pkgs/clan-cli/clan_cli/clan/update.py +++ b/pkgs/clan-cli/clan_cli/clan/update.py @@ -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 diff --git a/pkgs/clan-cli/clan_cli/inventory/__init__.py b/pkgs/clan-cli/clan_cli/inventory/__init__.py index 019be0713..006036d5a 100644 --- a/pkgs/clan-cli/clan_cli/inventory/__init__.py +++ b/pkgs/clan-cli/clan_cli/inventory/__init__.py @@ -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") diff --git a/pkgs/clan-cli/clan_cli/machines/create.py b/pkgs/clan-cli/clan_cli/machines/create.py index a5319c7fe..814d46416 100644 --- a/pkgs/clan-cli/clan_cli/machines/create.py +++ b/pkgs/clan-cli/clan_cli/machines/create.py @@ -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: diff --git a/pkgs/clan-cli/clan_cli/machines/delete.py b/pkgs/clan-cli/clan_cli/machines/delete.py index 1da35a616..09f13147e 100644 --- a/pkgs/clan-cli/clan_cli/machines/delete.py +++ b/pkgs/clan-cli/clan_cli/machines/delete.py @@ -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(): diff --git a/pkgs/clan-cli/clan_cli/machines/list.py b/pkgs/clan-cli/clan_cli/machines/list.py index 5ccb66cb5..98c1e3b42 100644 --- a/pkgs/clan-cli/clan_cli/machines/list.py +++ b/pkgs/clan-cli/clan_cli/machines/list.py @@ -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 diff --git a/pkgs/clan-cli/tests/test_modules.py b/pkgs/clan-cli/tests/test_modules.py index 45c507d8b..a8c9889f1 100644 --- a/pkgs/clan-cli/tests/test_modules.py +++ b/pkgs/clan-cli/tests/test_modules.py @@ -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)