{
const [confirmDisk, setConfirmDisk] = createSignal(!hasDisk());
+ const hwInfoQuery = createQuery(() => ({
+ queryKey: [
+ activeURI(),
+ "machine",
+ props.name,
+ "show_machine_hardware_info",
+ ],
+ queryFn: async () => {
+ const curr = activeURI();
+ if (curr && props.name) {
+ const result = await callApi("show_machine_hardware_info", {
+ clan_dir: curr,
+ machine_name: props.name,
+ });
+ if (result.status === "error") throw new Error("Failed to fetch data");
+ return result.data || null;
+ }
+ return null;
+ },
+ }));
+
const handleInstall = async (values: InstallForm) => {
console.log("Installing", values);
const curr_uri = activeURI();
@@ -72,6 +93,9 @@ const InstallMachine = (props: InstallMachineProps) => {
return;
}
+ const loading_toast = toast.loading(
+ "Installing machine. Grab coffee (15min)...",
+ );
const r = await callApi("install_machine", {
opts: {
flake: {
@@ -82,6 +106,7 @@ const InstallMachine = (props: InstallMachineProps) => {
},
password: "",
});
+ toast.dismiss(loading_toast);
if (r.status === "error") {
toast.error("Failed to install machine");
@@ -91,7 +116,8 @@ const InstallMachine = (props: InstallMachineProps) => {
}
};
- const handleDiskConfirm = async () => {
+ const handleDiskConfirm = async (e: Event) => {
+ e.preventDefault();
const curr_uri = activeURI();
const disk = getValue(formStore, "disk");
const disk_id = props.disks.find((d) => d.name === disk)?.id_link;
@@ -112,14 +138,86 @@ const InstallMachine = (props: InstallMachineProps) => {
setConfirmDisk(true);
}
};
+
+ const generateReport = async (e: Event) => {
+ e.preventDefault();
+ const curr_uri = activeURI();
+ if (!curr_uri || !props.name) {
+ return;
+ }
+
+ const loading_toast = toast.loading("Generating hardware report...");
+ const r = await callApi("generate_machine_hardware_info", {
+ clan_dir: { loc: curr_uri },
+ machine_name: props.name,
+ keyfile: props.sshKey?.name,
+ hostname: props.targetHost,
+ });
+ toast.dismiss(loading_toast);
+ hwInfoQuery.refetch();
+
+ if (r.status === "error") {
+ toast.error(`Failed to generate report. ${r.errors[0].message}`);
+ }
+ if (r.status === "success") {
+ toast.success("Report generated successfully");
+ }
+ };
return (
<>