Add REST route to get networks list
This commit is contained in:
@ -377,3 +377,39 @@ impl Handler<DefineNetwork> for LibVirtActor {
|
||||
XMLUuid::parse_from_str(&network.get_uuid_string()?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<Vec<XMLUuid>>")]
|
||||
pub struct GetNetworksListReq;
|
||||
|
||||
impl Handler<GetNetworksListReq> for LibVirtActor {
|
||||
type Result = anyhow::Result<Vec<XMLUuid>>;
|
||||
|
||||
fn handle(&mut self, _msg: GetNetworksListReq, _ctx: &mut Self::Context) -> Self::Result {
|
||||
log::debug!("Get full list of networks");
|
||||
let networks = self.m.list_all_networks(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<NetworkXML>")]
|
||||
pub struct GetNetworkXMLReq(pub XMLUuid);
|
||||
|
||||
impl Handler<GetNetworkXMLReq> for LibVirtActor {
|
||||
type Result = anyhow::Result<NetworkXML>;
|
||||
|
||||
fn handle(&mut self, msg: GetNetworkXMLReq, _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())?;
|
||||
let xml = network.get_xml_desc(0)?;
|
||||
log::debug!("XML = {}", xml);
|
||||
Ok(serde_xml_rs::from_str(&xml)?)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user