Can get domain info

This commit is contained in:
2023-10-04 19:03:20 +02:00
parent 2bc64442f4
commit ce393995f9
6 changed files with 154 additions and 13 deletions

View File

@ -4,6 +4,7 @@ use crate::libvirt_rest_structures::*;
use actix::{Actor, Context, Handler, Message};
use virt::connect::Connect;
use virt::domain::Domain;
use virt::sys::VIR_DOMAIN_XML_SECURE;
pub struct LibVirtActor {
m: Connect,
@ -57,6 +58,22 @@ impl Handler<GetHypervisorInfo> for LibVirtActor {
}
}
#[derive(Message)]
#[rtype(result = "anyhow::Result<DomainXML>")]
pub struct GetDomainXMLReq(pub DomainXMLUuid);
impl Handler<GetDomainXMLReq> for LibVirtActor {
type Result = anyhow::Result<DomainXML>;
fn handle(&mut self, msg: GetDomainXMLReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Get domain XML:\n{}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
let xml = domain.get_xml_desc(VIR_DOMAIN_XML_SECURE)?;
log::debug!("XML = {}", xml);
Ok(serde_xml_rs::from_str(&xml)?)
}
}
#[derive(Message)]
#[rtype(result = "anyhow::Result<DomainXMLUuid>")]
pub struct DefineDomainReq(pub DomainXML);