VirtWeb/virtweb_backend/src/libvirt_client.rs

41 lines
1.4 KiB
Rust
Raw Normal View History

2023-09-06 16:54:38 +00:00
use crate::actors::libvirt_actor;
2023-10-04 09:18:50 +00:00
use crate::actors::libvirt_actor::LibVirtActor;
2023-10-09 16:45:41 +00:00
use crate::libvirt_lib_structures::{DomainState, DomainXML, DomainXMLUuid};
2023-10-04 09:18:50 +00:00
use crate::libvirt_rest_structures::HypervisorInfo;
2023-09-06 16:54:38 +00:00
use actix::Addr;
#[derive(Clone)]
pub struct LibVirtClient(pub Addr<LibVirtActor>);
impl LibVirtClient {
/// Get hypervisor info
pub async fn get_info(&self) -> anyhow::Result<HypervisorInfo> {
self.0.send(libvirt_actor::GetHypervisorInfo).await?
}
2023-10-04 09:18:50 +00:00
2023-10-09 17:16:33 +00:00
/// Get the full list of domain
pub async fn get_full_list(&self) -> anyhow::Result<Vec<DomainXML>> {
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)
}
2023-10-04 17:03:20 +00:00
/// Get the information about a single domain
pub async fn get_single_domain(&self, id: DomainXMLUuid) -> anyhow::Result<DomainXML> {
self.0.send(libvirt_actor::GetDomainXMLReq(id)).await?
}
2023-10-04 09:18:50 +00:00
/// Update a domain
pub async fn update_domain(&self, xml: DomainXML) -> anyhow::Result<DomainXMLUuid> {
self.0.send(libvirt_actor::DefineDomainReq(xml)).await?
}
2023-10-09 16:45:41 +00:00
/// Get the state of a domain
pub async fn get_domain_state(&self, id: DomainXMLUuid) -> anyhow::Result<DomainState> {
self.0.send(libvirt_actor::GetDomainStateReq(id)).await?
}
2023-09-06 16:54:38 +00:00
}