Merge pull request 'clan-app: Fix machine update cancel task' (#3622) from Qubasa/clan-core:fix_cancellation into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3622
This commit is contained in:
Luis Hebendanz
2025-05-13 12:19:35 +00:00
3 changed files with 32 additions and 74 deletions

View File

@@ -19,8 +19,6 @@ from clan_cli.completions import (
from clan_cli.errors import ClanError
from clan_cli.facts.generate import generate_facts
from clan_cli.facts.upload import upload_secrets
from clan_cli.flake import Flake
from clan_cli.inventory import Machine as InventoryMachine
from clan_cli.machines.list import list_machines
from clan_cli.machines.machines import Machine
from clan_cli.nix import nix_command, nix_config, nix_metadata
@@ -103,29 +101,6 @@ def upload_sources(machine: Machine, host: Host) -> str:
@API.register
def update_machines(base_path: str, machines: list[InventoryMachine]) -> None:
group_machines: list[Machine] = []
# Convert InventoryMachine to Machine
flake = Flake(base_path)
for machine in machines:
name = machine.get("name")
# prefer target host set via inventory, but fallback to the one set in the machine
target_host = machine.get("deploy", {}).get("targetHost")
if not name:
msg = "Machine name is not set"
raise ClanError(msg)
m = Machine(
name,
flake=flake,
override_target_host=target_host,
)
group_machines.append(m)
deploy_machines(group_machines)
def deploy_machine(machine: Machine) -> None:
with ExitStack() as stack:
target_host = stack.enter_context(machine.target_host())

View File

@@ -37,38 +37,31 @@ export const MachineListItem = (props: MachineListItemProps) => {
const active_clan = activeURI();
if (!active_clan) {
toast.error("No active clan selected");
console.error("No active clan selected");
return;
}
if (!info?.deploy?.targetHost) {
toast.error(
console.error(
"Machine does not have a target host. Specify where the machine should be deployed.",
);
return;
}
setInstalling(true);
await toast.promise(
callApi("install_machine", {
opts: {
machine: {
name: name,
flake: {
identifier: active_clan,
},
override_target_host: info?.deploy.targetHost,
await callApi("install_machine", {
opts: {
machine: {
name: name,
flake: {
identifier: active_clan,
},
no_reboot: true,
debug: true,
nix_options: [],
password: null,
override_target_host: info?.deploy.targetHost,
},
}),
{
loading: "Installing...",
success: "Installed",
error: "Failed to install",
no_reboot: true,
debug: true,
nix_options: [],
password: null,
},
);
});
setInstalling(false);
};
@@ -79,34 +72,26 @@ export const MachineListItem = (props: MachineListItemProps) => {
const active_clan = activeURI();
if (!active_clan) {
toast.error("No active clan selected");
console.error("No active clan selected");
return;
}
if (!info?.deploy.targetHost) {
toast.error(
console.error(
"Machine does not have a target host. Specify where the machine should be deployed.",
);
return;
}
setUpdating(true);
await toast.promise(
callApi("update_machines", {
base_path: active_clan,
machines: [
{
name: name,
deploy: {
targetHost: info?.deploy.targetHost,
},
},
],
}),
{
loading: "Updating...",
success: "Updated",
error: "Failed to update",
await callApi("deploy_machine", {
machine: {
name: name,
flake: {
identifier: active_clan,
},
override_target_host: info?.deploy.targetHost,
},
);
});
setUpdating(false);
};
return (

View File

@@ -457,16 +457,14 @@ const MachineForm = (props: MachineDetailsProps) => {
const target = targetHost();
setIsUpdating(true);
const r = await callApi("update_machines", {
base_path: curr_uri,
machines: [
{
name: machine,
deploy: {
targetHost: target,
},
const r = await callApi("deploy_machine", {
machine: {
name: machine,
flake: {
identifier: curr_uri,
},
],
override_target_host: target,
},
});
};