Can view from web UI XML definition of domains

This commit is contained in:
2023-12-08 18:14:01 +01:00
parent 74b77be013
commit 82447a0018
13 changed files with 632 additions and 135 deletions

@ -5,7 +5,10 @@ import { AsyncWidget } from "../widgets/AsyncWidget";
import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer";
import { VMDetails } from "../widgets/vms/VMDetails";
import { VMStatusWidget } from "../widgets/vms/VMStatusWidget";
import { Button } from "@mui/material";
import { Button, IconButton } from "@mui/material";
import Icon from "@mdi/react";
import { mdiXml } from "@mdi/js";
import { RouterLink } from "../widgets/RouterLink";
export function VMRoute(): React.ReactElement {
const { uuid } = useParams();
@ -35,9 +38,15 @@ function VMRouteBody(p: { vm: VMInfo }): React.ReactElement {
<VirtWebRouteContainer
label={`VM ${p.vm.name}`}
actions={
<span>
<span style={{ display: "inline-flex", alignItems: "center" }}>
<VMStatusWidget vm={p.vm} onChange={setState} />
<RouterLink to={p.vm.XMLURL}>
<IconButton size="small">
<Icon path={mdiXml} style={{ width: "1rem" }} />
</IconButton>
</RouterLink>
{(state === "Shutdown" || state === "Shutoff") && (
<Button
variant="contained"

@ -0,0 +1,60 @@
import React from "react";
import { useParams } from "react-router-dom";
import { Light as SyntaxHighlighter } from "react-syntax-highlighter";
import xml from "react-syntax-highlighter/dist/esm/languages/hljs/xml";
import { dracula } from "react-syntax-highlighter/dist/esm/styles/hljs";
import xmlFormat from "xml-formatter";
import { VMApi, VMInfo } from "../api/VMApi";
import { AsyncWidget } from "../widgets/AsyncWidget";
import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer";
import { IconButton } from "@mui/material";
import { RouterLink } from "../widgets/RouterLink";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
SyntaxHighlighter.registerLanguage("xml", xml);
export function VMXMLRoute(): React.ReactElement {
const { uuid } = useParams();
const [vm, setVM] = React.useState<VMInfo | undefined>();
const [src, setSrc] = React.useState<string | undefined>();
const load = async () => {
setVM(await VMApi.GetSingle(uuid!));
setSrc(await VMApi.GetSingleXML(uuid!));
};
return (
<AsyncWidget
loadKey={uuid}
load={load}
errMsg="Failed to load VM information!"
build={() => <XMLRouteInner vm={vm!} src={src!} />}
/>
);
}
function XMLRouteInner(p: { vm: VMInfo; src: string }): React.ReactElement {
const xml = xmlFormat(p.src);
return (
<VirtWebRouteContainer
label={`XML definition of ${p.vm.name}`}
actions={
<RouterLink to={p.vm.ViewURL}>
<IconButton>
<ArrowBackIcon />
</IconButton>
</RouterLink>
}
>
<SyntaxHighlighter
language="xml"
style={dracula}
customStyle={{ fontSize: "120%" }}
>
{xml}
</SyntaxHighlighter>
</VirtWebRouteContainer>
);
}

@ -94,7 +94,7 @@ function VNCInner(p: { vm: VMInfo }): React.ReactElement {
return <p>Please wait, connecting to the machine...</p>;
return (
<div ref={vncRef}>
<div ref={vncRef} style={{ display: "flex" }}>
{/* Controls */}
<div>
<IconButton onClick={goBack}>