Return VM state

This commit is contained in:
2023-10-09 18:45:41 +02:00
parent ce393995f9
commit b69c97e6fe
4 changed files with 62 additions and 4 deletions

View File

@ -1,8 +1,15 @@
use crate::controllers::{HttpResult, LibVirtReq};
use crate::libvirt_lib_structures::DomainXMLUuid;
use crate::libvirt_lib_structures::{DomainState, DomainXMLUuid};
use crate::libvirt_rest_structures::VMInfo;
use actix_web::{web, HttpResponse};
#[derive(serde::Serialize)]
struct VMInfoAndState {
#[serde(flatten)]
info: VMInfo,
state: DomainState,
}
/// Create a new VM
pub async fn create(client: LibVirtReq, req: web::Json<VMInfo>) -> HttpResult {
let domain = match req.0.to_domain() {
@ -32,5 +39,10 @@ pub async fn get_single(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> H
}
};
Ok(HttpResponse::Ok().json(VMInfo::from_domain(info)?))
let state = client.get_domain_state(id.uid).await?;
Ok(HttpResponse::Ok().json(VMInfoAndState {
info: VMInfo::from_domain(info)?,
state,
}))
}