Can get XML network definition
This commit is contained in:
parent
2d5dc9237e
commit
375bdb1a46
@ -452,6 +452,20 @@ impl Handler<GetNetworkXMLReq> for LibVirtActor {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<String>")]
|
||||
pub struct GetSourceNetworkXMLReq(pub XMLUuid);
|
||||
|
||||
impl Handler<GetSourceNetworkXMLReq> for LibVirtActor {
|
||||
type Result = anyhow::Result<String>;
|
||||
|
||||
fn handle(&mut self, msg: GetSourceNetworkXMLReq, _ctx: &mut Self::Context) -> Self::Result {
|
||||
log::debug!("Get network XML:\n{}", msg.0.as_string());
|
||||
let network = Network::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
|
||||
Ok(network.get_xml_desc(0)?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<()>")]
|
||||
pub struct DeleteNetwork(pub XMLUuid);
|
||||
|
@ -42,6 +42,12 @@ pub async fn get_single(client: LibVirtReq, req: web::Path<NetworkID>) -> HttpRe
|
||||
Ok(HttpResponse::Ok().json(network))
|
||||
}
|
||||
|
||||
/// Get the XML source description of a single network
|
||||
pub async fn single_src(client: LibVirtReq, req: web::Path<NetworkID>) -> HttpResult {
|
||||
let xml = client.get_single_network_xml(req.uid).await?;
|
||||
Ok(HttpResponse::Ok().content_type("application/xml").body(xml))
|
||||
}
|
||||
|
||||
/// Update the information about a single network
|
||||
pub async fn update(
|
||||
client: LibVirtReq,
|
||||
|
@ -119,6 +119,13 @@ impl LibVirtClient {
|
||||
self.0.send(libvirt_actor::GetNetworkXMLReq(id)).await?
|
||||
}
|
||||
|
||||
/// Get the source XML configuration of a single network
|
||||
pub async fn get_single_network_xml(&self, id: XMLUuid) -> anyhow::Result<String> {
|
||||
self.0
|
||||
.send(libvirt_actor::GetSourceNetworkXMLReq(id))
|
||||
.await?
|
||||
}
|
||||
|
||||
/// Delete a network
|
||||
pub async fn delete_network(&self, id: XMLUuid) -> anyhow::Result<()> {
|
||||
self.0.send(libvirt_actor::DeleteNetwork(id)).await?
|
||||
|
@ -199,6 +199,10 @@ async fn main() -> std::io::Result<()> {
|
||||
"/api/network/{uid}",
|
||||
web::get().to(network_controller::get_single),
|
||||
)
|
||||
.route(
|
||||
"/api/network/{uid}/src",
|
||||
web::get().to(network_controller::single_src),
|
||||
)
|
||||
.route(
|
||||
"/api/network/{uid}",
|
||||
web::put().to(network_controller::update),
|
||||
|
@ -26,6 +26,7 @@ import { BaseAuthenticatedPage } from "./widgets/BaseAuthenticatedPage";
|
||||
import { BaseLoginPage } from "./widgets/BaseLoginPage";
|
||||
import { ViewNetworkRoute } from "./routes/ViewNetworkRoute";
|
||||
import { VMXMLRoute } from "./routes/VMXMLRoute";
|
||||
import { NetXMLRoute } from "./routes/NetXMLRoute";
|
||||
|
||||
interface AuthContext {
|
||||
signedIn: boolean;
|
||||
@ -59,6 +60,7 @@ export function App() {
|
||||
<Route path="net/new" element={<CreateNetworkRoute />} />
|
||||
<Route path="net/:uuid" element={<ViewNetworkRoute />} />
|
||||
<Route path="net/:uuid/edit" element={<EditNetworkRoute />} />
|
||||
<Route path="net/:uuid/xml" element={<NetXMLRoute />} />
|
||||
|
||||
<Route path="sysinfo" element={<SysInfoRoute />} />
|
||||
<Route path="*" element={<NotFoundRoute />} />
|
||||
|
@ -25,6 +25,10 @@ export function NetworkURL(n: NetworkInfo, edit: boolean = false): string {
|
||||
return `/net/${n.uuid}${edit ? "/edit" : ""}`;
|
||||
}
|
||||
|
||||
export function NetworkXMLURL(n: NetworkInfo): string {
|
||||
return `/net/${n.uuid}/xml`;
|
||||
}
|
||||
|
||||
export class NetworkApi {
|
||||
/**
|
||||
* Create a new network
|
||||
@ -63,6 +67,18 @@ export class NetworkApi {
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source XML configuration of a network for debugging purposes
|
||||
*/
|
||||
static async GetSingleXML(uuid: string): Promise<string> {
|
||||
return (
|
||||
await APIClient.exec({
|
||||
uri: `/network/${uuid}/src`,
|
||||
method: "GET",
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of network
|
||||
*/
|
||||
|
50
virtweb_frontend/src/routes/NetXMLRoute.tsx
Normal file
50
virtweb_frontend/src/routes/NetXMLRoute.tsx
Normal file
@ -0,0 +1,50 @@
|
||||
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
|
||||
import { IconButton } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { NetworkApi, NetworkInfo, NetworkURL } from "../api/NetworksApi";
|
||||
import { AsyncWidget } from "../widgets/AsyncWidget";
|
||||
import { RouterLink } from "../widgets/RouterLink";
|
||||
import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer";
|
||||
import { XMLWidget } from "../widgets/XMLWidget";
|
||||
|
||||
export function NetXMLRoute(): React.ReactElement {
|
||||
const { uuid } = useParams();
|
||||
|
||||
const [net, setNet] = React.useState<NetworkInfo | undefined>();
|
||||
const [src, setSrc] = React.useState<string | undefined>();
|
||||
|
||||
const load = async () => {
|
||||
setNet(await NetworkApi.GetSingle(uuid!));
|
||||
setSrc(await NetworkApi.GetSingleXML(uuid!));
|
||||
};
|
||||
|
||||
return (
|
||||
<AsyncWidget
|
||||
loadKey={uuid}
|
||||
load={load}
|
||||
errMsg="Failed to load network information!"
|
||||
build={() => <XMLRouteInner net={net!} src={src!} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function XMLRouteInner(p: {
|
||||
net: NetworkInfo;
|
||||
src: string;
|
||||
}): React.ReactElement {
|
||||
return (
|
||||
<VirtWebRouteContainer
|
||||
label={`XML definition of ${p.net.name}`}
|
||||
actions={
|
||||
<RouterLink to={NetworkURL(p.net)}>
|
||||
<IconButton>
|
||||
<ArrowBackIcon />
|
||||
</IconButton>
|
||||
</RouterLink>
|
||||
}
|
||||
>
|
||||
<XMLWidget src={p.src} />
|
||||
</VirtWebRouteContainer>
|
||||
);
|
||||
}
|
@ -43,7 +43,7 @@ function VMRouteBody(p: { vm: VMInfo }): React.ReactElement {
|
||||
|
||||
<RouterLink to={p.vm.XMLURL}>
|
||||
<IconButton size="small">
|
||||
<Icon path={mdiXml} style={{ width: "1rem" }} />
|
||||
<Icon path={mdiXml} style={{ width: "1em" }} />
|
||||
</IconButton>
|
||||
</RouterLink>
|
||||
|
||||
|
@ -1,17 +1,12 @@
|
||||
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);
|
||||
import { XMLWidget } from "../widgets/XMLWidget";
|
||||
|
||||
export function VMXMLRoute(): React.ReactElement {
|
||||
const { uuid } = useParams();
|
||||
@ -35,8 +30,6 @@ export function VMXMLRoute(): React.ReactElement {
|
||||
}
|
||||
|
||||
function XMLRouteInner(p: { vm: VMInfo; src: string }): React.ReactElement {
|
||||
const xml = xmlFormat(p.src);
|
||||
|
||||
return (
|
||||
<VirtWebRouteContainer
|
||||
label={`XML definition of ${p.vm.name}`}
|
||||
@ -48,13 +41,7 @@ function XMLRouteInner(p: { vm: VMInfo; src: string }): React.ReactElement {
|
||||
</RouterLink>
|
||||
}
|
||||
>
|
||||
<SyntaxHighlighter
|
||||
language="xml"
|
||||
style={dracula}
|
||||
customStyle={{ fontSize: "120%" }}
|
||||
>
|
||||
{xml}
|
||||
</SyntaxHighlighter>
|
||||
<XMLWidget src={p.src} />
|
||||
</VirtWebRouteContainer>
|
||||
);
|
||||
}
|
||||
|
@ -1,14 +1,18 @@
|
||||
import { mdiXml } from "@mdi/js";
|
||||
import Icon from "@mdi/react";
|
||||
import { Button, IconButton } from "@mui/material";
|
||||
import React from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import {
|
||||
NetworkApi,
|
||||
NetworkInfo,
|
||||
NetworkStatus,
|
||||
NetworkURL,
|
||||
NetworkXMLURL,
|
||||
} from "../api/NetworksApi";
|
||||
import { AsyncWidget } from "../widgets/AsyncWidget";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { RouterLink } from "../widgets/RouterLink";
|
||||
import { VirtWebRouteContainer } from "../widgets/VirtWebRouteContainer";
|
||||
import { Button } from "@mui/material";
|
||||
import { NetworkDetails } from "../widgets/net/NetworkDetails";
|
||||
import { NetworkStatusWidget } from "../widgets/net/NetworkStatusWidget";
|
||||
|
||||
@ -46,6 +50,12 @@ function ViewNetworkRouteInner(p: {
|
||||
<span>
|
||||
<NetworkStatusWidget net={p.network} onChange={setNetStatus} />
|
||||
|
||||
<RouterLink to={NetworkXMLURL(p.network)}>
|
||||
<IconButton size="small">
|
||||
<Icon path={mdiXml} style={{ width: "1em" }} />
|
||||
</IconButton>
|
||||
</RouterLink>
|
||||
|
||||
{netStatus === "Stopped" && (
|
||||
<Button
|
||||
variant="contained"
|
||||
|
21
virtweb_frontend/src/widgets/XMLWidget.tsx
Normal file
21
virtweb_frontend/src/widgets/XMLWidget.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
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 { Light as SyntaxHighlighter } from "react-syntax-highlighter";
|
||||
|
||||
SyntaxHighlighter.registerLanguage("xml", xml);
|
||||
|
||||
export function XMLWidget(p: { src: string }): React.ReactElement {
|
||||
const xml = xmlFormat(p.src);
|
||||
|
||||
return (
|
||||
<SyntaxHighlighter
|
||||
language="xml"
|
||||
style={dracula}
|
||||
customStyle={{ fontSize: "120%" }}
|
||||
>
|
||||
{xml}
|
||||
</SyntaxHighlighter>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user