//! # 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) -> HttpResult { Ok(HttpResponse::Ok().json(virtweb_client::vm_state(path.uid).await?)) } /// Start a VM pub async fn start(path: web::Path) -> HttpResult { virtweb_client::vm_start(path.uid).await?; Ok(HttpResponse::Ok().finish()) } /// Shutdown a VM pub async fn shutdown(path: web::Path) -> HttpResult { virtweb_client::vm_shutdown(path.uid).await?; Ok(HttpResponse::Ok().finish()) } /// Kill a VM pub async fn kill(path: web::Path) -> HttpResult { virtweb_client::vm_kill(path.uid).await?; Ok(HttpResponse::Ok().finish()) } /// Reset a VM pub async fn reset(path: web::Path) -> HttpResult { virtweb_client::vm_reset(path.uid).await?; Ok(HttpResponse::Ok().finish()) } /// Suspend a VM pub async fn suspend(path: web::Path) -> HttpResult { virtweb_client::vm_suspend(path.uid).await?; Ok(HttpResponse::Ok().finish()) } /// Resume a VM pub async fn resume(path: web::Path) -> 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) -> HttpResult { let screenshot = virtweb_client::vm_screenshot(path.uid).await?; Ok(HttpResponse::Ok() .insert_header(("content-type", "image/png")) .body(screenshot)) }