From 06ddf57b5cf96acbb74296caf4cc435130dccda7 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Tue, 2 Jan 2024 15:52:04 +0100 Subject: [PATCH] Can get NW filter source XML definition --- virtweb_backend/src/actors/libvirt_actor.rs | 18 ++++++++++++++++++ .../src/controllers/nwfilter_controller.rs | 6 ++++++ virtweb_backend/src/libvirt_client.rs | 7 +++++++ virtweb_backend/src/main.rs | 4 ++++ 4 files changed, 35 insertions(+) diff --git a/virtweb_backend/src/actors/libvirt_actor.rs b/virtweb_backend/src/actors/libvirt_actor.rs index 99d30ce..75c488f 100644 --- a/virtweb_backend/src/actors/libvirt_actor.rs +++ b/virtweb_backend/src/actors/libvirt_actor.rs @@ -642,3 +642,21 @@ impl Handler for LibVirtActor { Ok(()) } } + +#[derive(Message)] +#[rtype(result = "anyhow::Result")] +pub struct GetSourceNetworkFilterXMLReq(pub XMLUuid); + +impl Handler for LibVirtActor { + type Result = anyhow::Result; + + fn handle( + &mut self, + msg: GetSourceNetworkFilterXMLReq, + _ctx: &mut Self::Context, + ) -> Self::Result { + log::debug!("Get nw filter source XML:\n{}", msg.0.as_string()); + let nwfilter = NWFilter::lookup_by_uuid_string(&self.m, &msg.0.as_string())?; + Ok(nwfilter.get_xml_desc(0)?) + } +} diff --git a/virtweb_backend/src/controllers/nwfilter_controller.rs b/virtweb_backend/src/controllers/nwfilter_controller.rs index 39a51f0..8bda625 100644 --- a/virtweb_backend/src/controllers/nwfilter_controller.rs +++ b/virtweb_backend/src/controllers/nwfilter_controller.rs @@ -62,6 +62,12 @@ pub async fn get_single(client: LibVirtReq, req: web::Path) -> Ok(HttpResponse::Ok().json(nwfilter)) } +/// Get the XML source description of a single network filter +pub async fn single_src(client: LibVirtReq, req: web::Path) -> HttpResult { + let xml = client.get_single_network_filter_xml(req.uid).await?; + Ok(HttpResponse::Ok().content_type("application/xml").body(xml)) +} + /// Update the information about a single network filter pub async fn update( client: LibVirtReq, diff --git a/virtweb_backend/src/libvirt_client.rs b/virtweb_backend/src/libvirt_client.rs index ea10a9a..640a74f 100644 --- a/virtweb_backend/src/libvirt_client.rs +++ b/virtweb_backend/src/libvirt_client.rs @@ -187,6 +187,13 @@ impl LibVirtClient { self.0.send(libvirt_actor::GetNWFilterXMLReq(id)).await? } + /// Get the source XML configuration of a single network filter + pub async fn get_single_network_filter_xml(&self, id: XMLUuid) -> anyhow::Result { + self.0 + .send(libvirt_actor::GetSourceNetworkFilterXMLReq(id)) + .await? + } + /// Update the information about a single domain pub async fn update_network_filter( &self, diff --git a/virtweb_backend/src/main.rs b/virtweb_backend/src/main.rs index 52b427c..e50b230 100644 --- a/virtweb_backend/src/main.rs +++ b/virtweb_backend/src/main.rs @@ -252,6 +252,10 @@ async fn main() -> std::io::Result<()> { "/api/nwfilter/{uid}", web::get().to(nwfilter_controller::get_single), ) + .route( + "/api/nwfilter/{uid}/src", + web::get().to(nwfilter_controller::single_src), + ) .route( "/api/nwfilter/{uid}", web::put().to(nwfilter_controller::update),