Can create networks

This commit is contained in:
2023-10-31 09:26:42 +01:00
parent 335aec788e
commit f2237d4f2f
12 changed files with 328 additions and 65 deletions

View File

@ -1,6 +1,6 @@
use crate::actors::libvirt_actor;
use crate::actors::libvirt_actor::LibVirtActor;
use crate::libvirt_lib_structures::{DomainState, DomainXML, DomainXMLUuid};
use crate::libvirt_lib_structures::{DomainState, DomainXML, NetworkXML, XMLUuid};
use crate::libvirt_rest_structures::HypervisorInfo;
use actix::Addr;
@ -24,74 +24,76 @@ impl LibVirtClient {
}
/// Get the information about a single domain
pub async fn get_single_domain(&self, id: DomainXMLUuid) -> anyhow::Result<DomainXML> {
pub async fn get_single_domain(&self, id: XMLUuid) -> anyhow::Result<DomainXML> {
self.0.send(libvirt_actor::GetDomainXMLReq(id)).await?
}
/// Update a domain
pub async fn update_domain(&self, xml: DomainXML) -> anyhow::Result<DomainXMLUuid> {
pub async fn update_domain(&self, xml: DomainXML) -> anyhow::Result<XMLUuid> {
self.0.send(libvirt_actor::DefineDomainReq(xml)).await?
}
/// Delete a domain
pub async fn delete_domain(&self, id: DomainXMLUuid, keep_files: bool) -> anyhow::Result<()> {
pub async fn delete_domain(&self, id: XMLUuid, keep_files: bool) -> anyhow::Result<()> {
self.0
.send(libvirt_actor::DeleteDomainReq { id, keep_files })
.await?
}
/// Get the state of a domain
pub async fn get_domain_state(&self, id: DomainXMLUuid) -> anyhow::Result<DomainState> {
pub async fn get_domain_state(&self, id: XMLUuid) -> anyhow::Result<DomainState> {
self.0.send(libvirt_actor::GetDomainStateReq(id)).await?
}
/// Start a domain
pub async fn start_domain(&self, id: DomainXMLUuid) -> anyhow::Result<()> {
pub async fn start_domain(&self, id: XMLUuid) -> anyhow::Result<()> {
self.0.send(libvirt_actor::StartDomainReq(id)).await?
}
/// Shutdown a domain
pub async fn shutdown_domain(&self, id: DomainXMLUuid) -> anyhow::Result<()> {
pub async fn shutdown_domain(&self, id: XMLUuid) -> anyhow::Result<()> {
self.0.send(libvirt_actor::ShutdownDomainReq(id)).await?
}
/// Kill a domain
pub async fn kill_domain(&self, id: DomainXMLUuid) -> anyhow::Result<()> {
pub async fn kill_domain(&self, id: XMLUuid) -> anyhow::Result<()> {
self.0.send(libvirt_actor::KillDomainReq(id)).await?
}
/// Reset a domain
pub async fn reset_domain(&self, id: DomainXMLUuid) -> anyhow::Result<()> {
pub async fn reset_domain(&self, id: XMLUuid) -> anyhow::Result<()> {
self.0.send(libvirt_actor::ResetDomainReq(id)).await?
}
/// Suspend a domain
pub async fn suspend_domain(&self, id: DomainXMLUuid) -> anyhow::Result<()> {
pub async fn suspend_domain(&self, id: XMLUuid) -> anyhow::Result<()> {
self.0.send(libvirt_actor::SuspendDomainReq(id)).await?
}
/// Resume a domain
pub async fn resume_domain(&self, id: DomainXMLUuid) -> anyhow::Result<()> {
pub async fn resume_domain(&self, id: XMLUuid) -> anyhow::Result<()> {
self.0.send(libvirt_actor::ResumeDomainReq(id)).await?
}
/// Take a screenshot of the domain
pub async fn screenshot_domain(&self, id: DomainXMLUuid) -> anyhow::Result<Vec<u8>> {
pub async fn screenshot_domain(&self, id: XMLUuid) -> anyhow::Result<Vec<u8>> {
self.0.send(libvirt_actor::ScreenshotDomainReq(id)).await?
}
/// Get auto-start status of a domain
pub async fn is_domain_autostart(&self, id: DomainXMLUuid) -> anyhow::Result<bool> {
pub async fn is_domain_autostart(&self, id: XMLUuid) -> anyhow::Result<bool> {
self.0.send(libvirt_actor::IsDomainAutostart(id)).await?
}
pub async fn set_domain_autostart(
&self,
id: DomainXMLUuid,
autostart: bool,
) -> anyhow::Result<()> {
/// Update autostart value of a domain
pub async fn set_domain_autostart(&self, id: XMLUuid, autostart: bool) -> anyhow::Result<()> {
self.0
.send(libvirt_actor::SetDomainAutostart(id, autostart))
.await?
}
/// Update a network configuration
pub async fn update_network(&self, network: NetworkXML) -> anyhow::Result<XMLUuid> {
self.0.send(libvirt_actor::DefineNetwork(network)).await?
}
}