Can get domain state through a dedicated route

This commit is contained in:
Pierre HUBERT 2023-10-13 15:30:32 +02:00
parent 0a00e43216
commit 52d7e35d10
2 changed files with 17 additions and 0 deletions

View File

@ -131,6 +131,22 @@ pub async fn resume(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpR
})
}
#[derive(serde::Serialize)]
struct DomainStateRes {
state: DomainState,
}
/// Get the state of a VM
pub async fn state(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
Ok(match client.get_domain_state(id.uid).await {
Ok(s) => HttpResponse::Ok().json(DomainStateRes { state: s }),
Err(e) => {
log::error!("Failed to get domain state {:?} ! {e}", id.uid);
HttpResponse::InternalServerError().json("Failed to get domain state!")
}
})
}
/// Take a screenshot of a VM
pub async fn screenshot(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
Ok(match client.screenshot_domain(id.uid).await {

View File

@ -150,6 +150,7 @@ async fn main() -> std::io::Result<()> {
web::get().to(vm_controller::suspend),
)
.route("/api/vm/{uid}/resume", web::get().to(vm_controller::resume))
.route("/api/vm/{uid}/state", web::get().to(vm_controller::state))
.route(
"/api/vm/{uid}/screenshot",
web::get().to(vm_controller::screenshot),