From 31955ca7382b1456574e9941ddc64446337720cc Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 6 May 2024 19:09:20 +0200 Subject: [PATCH] Can perform all actions on VM --- remote_frontend/src/api/VMApi.ts | 21 +++++++++ .../src/widgets/VirtualMachinesWidget.tsx | 43 +++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/remote_frontend/src/api/VMApi.ts b/remote_frontend/src/api/VMApi.ts index f84c471..fa58303 100644 --- a/remote_frontend/src/api/VMApi.ts +++ b/remote_frontend/src/api/VMApi.ts @@ -52,6 +52,20 @@ export class VMApi { await APIClient.exec({ method: "GET", uri: `/vm/${vm.uiid}/start` }); } + /** + * Request to suspend VM + */ + static async SuspendVM(vm: VMInfo): Promise { + await APIClient.exec({ method: "GET", uri: `/vm/${vm.uiid}/suspend` }); + } + + /** + * Request to resume VM + */ + static async ResumeVM(vm: VMInfo): Promise { + await APIClient.exec({ method: "GET", uri: `/vm/${vm.uiid}/resume` }); + } + /** * Request to shutdown VM */ @@ -65,4 +79,11 @@ export class VMApi { static async KillVM(vm: VMInfo): Promise { await APIClient.exec({ method: "GET", uri: `/vm/${vm.uiid}/kill` }); } + + /** + * Request to reset VM + */ + static async ResetVM(vm: VMInfo): Promise { + await APIClient.exec({ method: "GET", uri: `/vm/${vm.uiid}/reset` }); + } } diff --git a/remote_frontend/src/widgets/VirtualMachinesWidget.tsx b/remote_frontend/src/widgets/VirtualMachinesWidget.tsx index 0884ed8..a4c0de7 100644 --- a/remote_frontend/src/widgets/VirtualMachinesWidget.tsx +++ b/remote_frontend/src/widgets/VirtualMachinesWidget.tsx @@ -10,17 +10,18 @@ import { Tooltip, } from "@fluentui/react-components"; import { + ArrowResetRegular, DesktopRegular, - FluentIcon, + PauseRegular, Play16Regular, PowerRegular, StopRegular, } from "@fluentui/react-icons"; import React from "react"; import { VMApi, VMInfo, VMState } from "../api/VMApi"; +import { useToast } from "../hooks/providers/ToastProvider"; import { AsyncWidget } from "./AsyncWidget"; import { SectionContainer } from "./SectionContainer"; -import { useToast } from "../hooks/providers/ToastProvider"; export function VirtualMachinesWidget(): React.ReactElement { const [list, setList] = React.useState(); @@ -85,7 +86,7 @@ function VMWidget(p: { vm: VMInfo }): React.ReactElement { style={{ width: "400px", maxWidth: "49%", - height: "220px", + height: "250px", margin: "10px", display: "flex", flexDirection: "column", @@ -109,7 +110,7 @@ function VMWidget(p: { vm: VMInfo }): React.ReactElement {

{p.vm.description}

- + + } + enabled={p.vm.can_resume} + currState={state} + possibleStates={["Paused", "PowerManagementSuspended"]} + onClick={VMApi.ResumeVM} + /> + } + enabled={p.vm.can_suspend} + currState={state} + possibleStates={["Running"]} + onClick={VMApi.SuspendVM} + /> + } + enabled={p.vm.can_reset} + currState={state} + possibleStates={[ + "Running", + "Paused", + "PowerManagementSuspended", + "Blocked", + ]} + onClick={VMApi.ResetVM} + /> );