Can get NW filter source XML definition

This commit is contained in:
Pierre HUBERT 2024-01-02 15:52:04 +01:00
parent b4f65a6703
commit 06ddf57b5c
4 changed files with 35 additions and 0 deletions

View File

@ -642,3 +642,21 @@ impl Handler<DeleteNetworkFilter> for LibVirtActor {
Ok(()) Ok(())
} }
} }
#[derive(Message)]
#[rtype(result = "anyhow::Result<String>")]
pub struct GetSourceNetworkFilterXMLReq(pub XMLUuid);
impl Handler<GetSourceNetworkFilterXMLReq> for LibVirtActor {
type Result = anyhow::Result<String>;
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)?)
}
}

View File

@ -62,6 +62,12 @@ pub async fn get_single(client: LibVirtReq, req: web::Path<NetworkFilterID>) ->
Ok(HttpResponse::Ok().json(nwfilter)) 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<NetworkFilterID>) -> 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 /// Update the information about a single network filter
pub async fn update( pub async fn update(
client: LibVirtReq, client: LibVirtReq,

View File

@ -187,6 +187,13 @@ impl LibVirtClient {
self.0.send(libvirt_actor::GetNWFilterXMLReq(id)).await? 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<String> {
self.0
.send(libvirt_actor::GetSourceNetworkFilterXMLReq(id))
.await?
}
/// Update the information about a single domain /// Update the information about a single domain
pub async fn update_network_filter( pub async fn update_network_filter(
&self, &self,

View File

@ -252,6 +252,10 @@ async fn main() -> std::io::Result<()> {
"/api/nwfilter/{uid}", "/api/nwfilter/{uid}",
web::get().to(nwfilter_controller::get_single), web::get().to(nwfilter_controller::get_single),
) )
.route(
"/api/nwfilter/{uid}/src",
web::get().to(nwfilter_controller::single_src),
)
.route( .route(
"/api/nwfilter/{uid}", "/api/nwfilter/{uid}",
web::put().to(nwfilter_controller::update), web::put().to(nwfilter_controller::update),