Parse NW filters XML structure
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user