Created first domain

This commit is contained in:
2023-10-04 11:18:50 +02:00
parent 7073b9b7f1
commit 2bc64442f4
12 changed files with 314 additions and 28 deletions

View File

@ -1,6 +1,9 @@
use crate::app_config::AppConfig;
use crate::libvirt_lib_structures::{DomainXML, DomainXMLUuid};
use crate::libvirt_rest_structures::*;
use actix::{Actor, Context, Handler, Message};
use virt::connect::Connect;
use virt::domain::Domain;
pub struct LibVirtActor {
m: Connect,
@ -28,30 +31,6 @@ impl Actor for LibVirtActor {
#[rtype(result = "anyhow::Result<HypervisorInfo>")]
pub struct GetHypervisorInfo;
#[derive(serde::Serialize)]
pub struct HypervisorInfo {
pub r#type: String,
pub hyp_version: u32,
pub lib_version: u32,
pub capabilities: String,
pub free_memory: u64,
pub hostname: String,
pub node: HypervisorNodeInfo,
}
#[derive(serde::Serialize)]
pub struct HypervisorNodeInfo {
pub cpu_model: String,
/// Memory size in kilobytes
pub memory_size: u64,
pub number_of_active_cpus: u32,
pub cpu_frequency_mhz: u32,
pub number_of_numa_cell: u32,
pub number_of_cpu_socket_per_node: u32,
pub number_of_core_per_sockets: u32,
pub number_of_threads_per_core: u32,
}
impl Handler<GetHypervisorInfo> for LibVirtActor {
type Result = anyhow::Result<HypervisorInfo>;
@ -77,3 +56,18 @@ impl Handler<GetHypervisorInfo> for LibVirtActor {
})
}
}
#[derive(Message)]
#[rtype(result = "anyhow::Result<DomainXMLUuid>")]
pub struct DefineDomainReq(pub DomainXML);
impl Handler<DefineDomainReq> for LibVirtActor {
type Result = anyhow::Result<DomainXMLUuid>;
fn handle(&mut self, msg: DefineDomainReq, _ctx: &mut Self::Context) -> Self::Result {
let xml = serde_xml_rs::to_string(&msg.0)?;
log::debug!("Define domain:\n{}", xml);
let domain = Domain::define_xml(&self.m, &xml)?;
DomainXMLUuid::parse_from_str(&domain.get_uuid_string()?)
}
}