Files
VirtWebRemote/remote_backend/src/controllers/vm_controller.rs
Pierre HUBERT 77b1117fa1
All checks were successful
continuous-integration/drone/push Build is passing
Update VirteWebRemote backend dependencies
2025-03-28 16:32:24 +01:00

61 lines
1.6 KiB
Rust

//! # Virtual machines routes controller
use crate::controllers::HttpResult;
use crate::virtweb_client;
use crate::virtweb_client::VMUuid;
use actix_web::{HttpResponse, web};
#[derive(serde::Deserialize)]
pub struct ReqPath {
uid: VMUuid,
}
/// Get the state of a VM
pub async fn state(path: web::Path<ReqPath>) -> HttpResult {
Ok(HttpResponse::Ok().json(virtweb_client::vm_state(path.uid).await?))
}
/// Start a VM
pub async fn start(path: web::Path<ReqPath>) -> HttpResult {
virtweb_client::vm_start(path.uid).await?;
Ok(HttpResponse::Ok().finish())
}
/// Shutdown a VM
pub async fn shutdown(path: web::Path<ReqPath>) -> HttpResult {
virtweb_client::vm_shutdown(path.uid).await?;
Ok(HttpResponse::Ok().finish())
}
/// Kill a VM
pub async fn kill(path: web::Path<ReqPath>) -> HttpResult {
virtweb_client::vm_kill(path.uid).await?;
Ok(HttpResponse::Ok().finish())
}
/// Reset a VM
pub async fn reset(path: web::Path<ReqPath>) -> HttpResult {
virtweb_client::vm_reset(path.uid).await?;
Ok(HttpResponse::Ok().finish())
}
/// Suspend a VM
pub async fn suspend(path: web::Path<ReqPath>) -> HttpResult {
virtweb_client::vm_suspend(path.uid).await?;
Ok(HttpResponse::Ok().finish())
}
/// Resume a VM
pub async fn resume(path: web::Path<ReqPath>) -> HttpResult {
virtweb_client::vm_resume(path.uid).await?;
Ok(HttpResponse::Ok().finish())
}
/// Take the screenshot of a VM
pub async fn screenshot(path: web::Path<ReqPath>) -> HttpResult {
let screenshot = virtweb_client::vm_screenshot(path.uid).await?;
Ok(HttpResponse::Ok()
.insert_header(("content-type", "image/png"))
.body(screenshot))
}