diff --git a/pkgs/clan-app/ui/src/components/machine-list-item/index.tsx b/pkgs/clan-app/ui/src/components/machine-list-item/index.tsx index 9398392a5..b0881bf79 100644 --- a/pkgs/clan-app/ui/src/components/machine-list-item/index.tsx +++ b/pkgs/clan-app/ui/src/components/machine-list-item/index.tsx @@ -47,6 +47,27 @@ export const MachineListItem = (props: MachineListItemProps) => { ); return; } + const target_host = await callApi("get_host", { + field: "targetHost", + flake: { identifier: active_clan }, + name: name, + }).promise; + + if (target_host.status == "error") { + console.error("No target host found for the machine"); + return; + } + + if (target_host.data === null) { + console.error("No target host found for the machine"); + return; + } + + if (!target_host.data!.data) { + console.error("No target host found for the machine"); + return; + } + setInstalling(true); await callApi("install_machine", { opts: { @@ -55,15 +76,14 @@ export const MachineListItem = (props: MachineListItemProps) => { flake: { identifier: active_clan, }, - override_target_host: info?.deploy.targetHost, }, no_reboot: true, debug: true, nix_options: [], password: null, }, - }).promise; - setInstalling(false); + target_host: target_host.data!.data, + }).promise.finally(() => setInstalling(false)); }; const handleUpdate = async () => { @@ -83,14 +103,53 @@ export const MachineListItem = (props: MachineListItemProps) => { return; } setUpdating(true); + + const target_host = await callApi("get_host", { + field: "targetHost", + flake: { identifier: active_clan }, + name: name, + }).promise; + + if (target_host.status == "error") { + console.error("No target host found for the machine"); + return; + } + + if (target_host.data === null) { + console.error("No target host found for the machine"); + return; + } + + if (!target_host.data!.data) { + console.error("No target host found for the machine"); + return; + } + + const build_host = await callApi("get_host", { + field: "buildHost", + flake: { identifier: active_clan }, + name: name, + }).promise; + + if (build_host.status == "error") { + console.error("No target host found for the machine"); + return; + } + + if (build_host.data === null) { + console.error("No target host found for the machine"); + return; + } + await callApi("deploy_machine", { machine: { name: name, flake: { identifier: active_clan, }, - override_target_host: info?.deploy.targetHost, }, + target_host: target_host.data!.data, + build_host: build_host.data?.data || null, }).promise; setUpdating(false); diff --git a/pkgs/clan-app/ui/src/routes/machines/details.tsx b/pkgs/clan-app/ui/src/routes/machines/details.tsx index d6be7f3a1..beb6c601c 100644 --- a/pkgs/clan-app/ui/src/routes/machines/details.tsx +++ b/pkgs/clan-app/ui/src/routes/machines/details.tsx @@ -135,6 +135,27 @@ const InstallMachine = (props: InstallMachineProps) => { setProgressText("Installing machine ... (2/5)"); + const target_host = await callApi("get_host", { + field: "targetHost", + flake: { identifier: curr_uri }, + name: props.name, + }).promise; + + if (target_host.status == "error") { + console.error("No target host found for the machine"); + return; + } + + if (target_host.data === null) { + console.error("No target host found for the machine"); + return; + } + + if (!target_host.data!.data) { + console.error("No target host found for the machine"); + return; + } + const installPromise = callApi("install_machine", { opts: { machine: { @@ -142,11 +163,11 @@ const InstallMachine = (props: InstallMachineProps) => { flake: { identifier: curr_uri, }, - override_target_host: target, private_key: values.sshKey?.name, }, password: "", }, + target_host: target_host.data!.data, }); // Next step @@ -480,6 +501,49 @@ const MachineForm = (props: MachineDetailsProps) => { const target = targetHost(); + const active_clan = activeClanURI(); + if (!active_clan) { + console.error("No active clan selected"); + return; + } + + const target_host = await callApi("get_host", { + field: "targetHost", + flake: { identifier: active_clan }, + name: machine, + }).promise; + + if (target_host.status == "error") { + console.error("No target host found for the machine"); + return; + } + + if (target_host.data === null) { + console.error("No target host found for the machine"); + return; + } + + if (!target_host.data!.data) { + console.error("No target host found for the machine"); + return; + } + + const build_host = await callApi("get_host", { + field: "buildHost", + flake: { identifier: active_clan }, + name: machine, + }).promise; + + if (build_host.status == "error") { + console.error("No target host found for the machine"); + return; + } + + if (build_host.data === null) { + console.error("No target host found for the machine"); + return; + } + setIsUpdating(true); const r = await callApi("deploy_machine", { machine: { @@ -487,8 +551,9 @@ const MachineForm = (props: MachineDetailsProps) => { flake: { identifier: curr_uri, }, - override_target_host: target, }, + target_host: target_host.data!.data, + build_host: build_host.data!.data, }).promise; }; diff --git a/pkgs/clan-app/ui/src/routes/machines/install/hardware-step.tsx b/pkgs/clan-app/ui/src/routes/machines/install/hardware-step.tsx index 4c998d28a..d9f9140f6 100644 --- a/pkgs/clan-app/ui/src/routes/machines/install/hardware-step.tsx +++ b/pkgs/clan-app/ui/src/routes/machines/install/hardware-step.tsx @@ -90,11 +90,37 @@ export const HWStep = (props: StepProps) => { return; } + const active_clan = activeClanURI(); + if (!active_clan) { + console.error("No active clan selected"); + return; + } + + const target_host = await callApi("get_host", { + field: "targetHost", + flake: { identifier: active_clan }, + name: props.machine_id, + }).promise; + + if (target_host.status == "error") { + console.error("No target host found for the machine"); + return; + } + + if (target_host.data === null) { + console.error("No target host found for the machine"); + return; + } + + if (!target_host.data!.data) { + console.error("No target host found for the machine"); + return; + } + const r = await callApi("generate_machine_hardware_info", { opts: { machine: { name: props.machine_id, - override_target_host: target, private_key: sshFile?.name, flake: { identifier: curr_uri, @@ -102,6 +128,7 @@ export const HWStep = (props: StepProps) => { }, backend: "nixos-facter", }, + target_host: target_host.data!.data, }); // TODO: refresh the machine details