diff --git a/virtweb_backend/src/actors/libvirt_actor.rs b/virtweb_backend/src/actors/libvirt_actor.rs index 3c26928..d5e668a 100644 --- a/virtweb_backend/src/actors/libvirt_actor.rs +++ b/virtweb_backend/src/actors/libvirt_actor.rs @@ -452,6 +452,20 @@ impl Handler for LibVirtActor { } } +#[derive(Message)] +#[rtype(result = "anyhow::Result")] +pub struct GetSourceNetworkXMLReq(pub XMLUuid); + +impl Handler for LibVirtActor { + type Result = anyhow::Result; + + 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); diff --git a/virtweb_backend/src/controllers/network_controller.rs b/virtweb_backend/src/controllers/network_controller.rs index 90154c1..0bd9559 100644 --- a/virtweb_backend/src/controllers/network_controller.rs +++ b/virtweb_backend/src/controllers/network_controller.rs @@ -42,6 +42,12 @@ pub async fn get_single(client: LibVirtReq, req: web::Path) -> 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) -> 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, diff --git a/virtweb_backend/src/libvirt_client.rs b/virtweb_backend/src/libvirt_client.rs index e5e2aca..56d11b3 100644 --- a/virtweb_backend/src/libvirt_client.rs +++ b/virtweb_backend/src/libvirt_client.rs @@ -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 { + 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? diff --git a/virtweb_backend/src/main.rs b/virtweb_backend/src/main.rs index 9b3a349..39749fa 100644 --- a/virtweb_backend/src/main.rs +++ b/virtweb_backend/src/main.rs @@ -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), diff --git a/virtweb_frontend/src/App.tsx b/virtweb_frontend/src/App.tsx index 89286d4..977649c 100644 --- a/virtweb_frontend/src/App.tsx +++ b/virtweb_frontend/src/App.tsx @@ -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() { } /> } /> } /> + } /> } /> } /> diff --git a/virtweb_frontend/src/api/NetworksApi.ts b/virtweb_frontend/src/api/NetworksApi.ts index 044a9e3..9b76cde 100644 --- a/virtweb_frontend/src/api/NetworksApi.ts +++ b/virtweb_frontend/src/api/NetworksApi.ts @@ -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 { + return ( + await APIClient.exec({ + uri: `/network/${uuid}/src`, + method: "GET", + }) + ).data; + } + /** * Get the status of network */ diff --git a/virtweb_frontend/src/routes/NetXMLRoute.tsx b/virtweb_frontend/src/routes/NetXMLRoute.tsx new file mode 100644 index 0000000..97e27a3 --- /dev/null +++ b/virtweb_frontend/src/routes/NetXMLRoute.tsx @@ -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(); + const [src, setSrc] = React.useState(); + + const load = async () => { + setNet(await NetworkApi.GetSingle(uuid!)); + setSrc(await NetworkApi.GetSingleXML(uuid!)); + }; + + return ( + } + /> + ); +} + +function XMLRouteInner(p: { + net: NetworkInfo; + src: string; +}): React.ReactElement { + return ( + + + + + + } + > + + + ); +} diff --git a/virtweb_frontend/src/routes/VMRoute.tsx b/virtweb_frontend/src/routes/VMRoute.tsx index 5e93cbd..4134866 100644 --- a/virtweb_frontend/src/routes/VMRoute.tsx +++ b/virtweb_frontend/src/routes/VMRoute.tsx @@ -43,7 +43,7 @@ function VMRouteBody(p: { vm: VMInfo }): React.ReactElement { - + diff --git a/virtweb_frontend/src/routes/VMXMLRoute.tsx b/virtweb_frontend/src/routes/VMXMLRoute.tsx index d1e6ff2..7392503 100644 --- a/virtweb_frontend/src/routes/VMXMLRoute.tsx +++ b/virtweb_frontend/src/routes/VMXMLRoute.tsx @@ -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 ( } > - - {xml} - + ); } diff --git a/virtweb_frontend/src/routes/ViewNetworkRoute.tsx b/virtweb_frontend/src/routes/ViewNetworkRoute.tsx index 0517d5f..1fbb22f 100644 --- a/virtweb_frontend/src/routes/ViewNetworkRoute.tsx +++ b/virtweb_frontend/src/routes/ViewNetworkRoute.tsx @@ -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: { + + + + + + {netStatus === "Stopped" && (