Can shutdown, kill, suspend, resume, reset a domain

This commit is contained in:
2023-10-11 18:23:45 +02:00
parent 0c7128e6eb
commit c5c46fbcd8
4 changed files with 166 additions and 0 deletions

@ -75,3 +75,58 @@ pub async fn start(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpRe
}
})
}
/// Shutdown a VM
pub async fn shutdown(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
Ok(match client.shutdown_domain(id.uid).await {
Ok(_) => HttpResponse::Ok().json("Domain shutdown"),
Err(e) => {
log::error!("Failed to shutdown domain {:?} ! {e}", id.uid);
HttpResponse::InternalServerError().json("Failed to shutdown domain!")
}
})
}
/// Kill a VM
pub async fn kill(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
Ok(match client.kill_domain(id.uid).await {
Ok(_) => HttpResponse::Ok().json("Domain killed"),
Err(e) => {
log::error!("Failed to kill domain {:?} ! {e}", id.uid);
HttpResponse::InternalServerError().json("Failed to kill domain!")
}
})
}
/// Reset a VM
pub async fn reset(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
Ok(match client.reset_domain(id.uid).await {
Ok(_) => HttpResponse::Ok().json("Domain reseted"),
Err(e) => {
log::error!("Failed to reset domain {:?} ! {e}", id.uid);
HttpResponse::InternalServerError().json("Failed to reset domain!")
}
})
}
/// Suspend a VM
pub async fn suspend(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
Ok(match client.suspend_domain(id.uid).await {
Ok(_) => HttpResponse::Ok().json("Domain suspended"),
Err(e) => {
log::error!("Failed to suspend domain {:?} ! {e}", id.uid);
HttpResponse::InternalServerError().json("Failed to suspend domain!")
}
})
}
/// Resume a VM
pub async fn resume(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
Ok(match client.resume_domain(id.uid).await {
Ok(_) => HttpResponse::Ok().json("Domain resumed"),
Err(e) => {
log::error!("Failed to resume domain {:?} ! {e}", id.uid);
HttpResponse::InternalServerError().json("Failed to resume domain!")
}
})
}