Parse NW filters XML structure

This commit is contained in:
2023-12-28 15:12:38 +01:00
parent b4f765d486
commit 3849b0d51d
9 changed files with 588 additions and 4 deletions

View File

@ -1,5 +1,7 @@
use crate::app_config::AppConfig;
use crate::libvirt_lib_structures::{DomainState, DomainXML, NetworkXML, XMLUuid};
use crate::libvirt_lib_structures::{
DomainState, DomainXML, NetworkFilterXML, NetworkXML, XMLUuid,
};
use crate::libvirt_rest_structures::*;
use actix::{Actor, Context, Handler, Message};
use image::ImageOutputFormat;
@ -7,6 +9,7 @@ use std::io::Cursor;
use virt::connect::Connect;
use virt::domain::Domain;
use virt::network::Network;
use virt::nwfilter::NWFilter;
use virt::stream::Stream;
use virt::sys;
use virt::sys::VIR_DOMAIN_XML_SECURE;
@ -549,3 +552,39 @@ impl Handler<StopNetwork> for LibVirtActor {
Ok(())
}
}
#[derive(Message)]
#[rtype(result = "anyhow::Result<Vec<XMLUuid>>")]
pub struct GetNWFiltersListReq;
impl Handler<GetNWFiltersListReq> for LibVirtActor {
type Result = anyhow::Result<Vec<XMLUuid>>;
fn handle(&mut self, _msg: GetNWFiltersListReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Get full list of network filters");
let networks = self.m.list_all_nw_filters(0)?;
let mut ids = Vec::with_capacity(networks.len());
for d in networks {
ids.push(XMLUuid::parse_from_str(&d.get_uuid_string()?)?);
}
Ok(ids)
}
}
#[derive(Message)]
#[rtype(result = "anyhow::Result<NetworkFilterXML>")]
pub struct GetNWFilterXMLReq(pub XMLUuid);
impl Handler<GetNWFilterXMLReq> for LibVirtActor {
type Result = anyhow::Result<NetworkFilterXML>;
fn handle(&mut self, msg: GetNWFilterXMLReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Get network filter XML:\n{}", msg.0.as_string());
let filter = NWFilter::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
let xml = filter.get_xml_desc(0)?;
log::debug!("XML = {}", xml);
NetworkFilterXML::parse_xml(xml)
}
}