use crate::actors::libvirt_actor; use crate::actors::libvirt_actor::LibVirtActor; use crate::libvirt_lib_structures::{DomainState, DomainXML, DomainXMLUuid}; use crate::libvirt_rest_structures::HypervisorInfo; use actix::Addr; #[derive(Clone)] pub struct LibVirtClient(pub Addr); impl LibVirtClient { /// Get hypervisor info pub async fn get_info(&self) -> anyhow::Result { self.0.send(libvirt_actor::GetHypervisorInfo).await? } /// Get the full list of domain pub async fn get_full_list(&self) -> anyhow::Result> { let ids = self.0.send(libvirt_actor::GetDomainsListReq).await??; let mut info = Vec::with_capacity(ids.len()); for id in ids { info.push(self.get_single_domain(id).await?) } Ok(info) } /// Get the information about a single domain pub async fn get_single_domain(&self, id: DomainXMLUuid) -> anyhow::Result { self.0.send(libvirt_actor::GetDomainXMLReq(id)).await? } /// Update a domain pub async fn update_domain(&self, xml: DomainXML) -> anyhow::Result { self.0.send(libvirt_actor::DefineDomainReq(xml)).await? } /// Get the state of a domain pub async fn get_domain_state(&self, id: DomainXMLUuid) -> anyhow::Result { self.0.send(libvirt_actor::GetDomainStateReq(id)).await? } }