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

@ -1,4 +1,5 @@
use crate::controllers::{HttpResult, LibVirtReq};
use crate::libvirt_lib_structures::DomainXMLUuid;
use crate::libvirt_rest_structures::VMInfo;
use actix_web::{web, HttpResponse};
@ -15,3 +16,21 @@ pub async fn create(client: LibVirtReq, req: web::Json<VMInfo>) -> HttpResult {
Ok(HttpResponse::Ok().json(id))
}
#[derive(serde::Deserialize)]
pub struct SingleVMUUidReq {
uid: DomainXMLUuid,
}
/// Get the information about a single VM
pub async fn get_single(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
let info = match client.get_single_domain(id.uid).await {
Ok(i) => i,
Err(e) => {
log::error!("Failed to get domain info! {e}");
return Ok(HttpResponse::InternalServerError().json(e.to_string()));
}
};
Ok(HttpResponse::Ok().json(VMInfo::from_domain(info)?))
}