Can shutdown, kill, suspend, resume, reset a domain
This commit is contained in:
virtweb_backend/src
@ -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!")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user