//! # Virtual machines routes controller use crate::controllers::HttpResult; use crate::virtweb_client; use crate::virtweb_client::VMUuid; use actix_web::HttpResponse; #[derive(Debug, serde::Serialize)] pub struct VMInfoAndCaps { uiid: VMUuid, name: String, description: Option, can_get_state: bool, can_start: bool, can_shutdown: bool, can_kill: bool, can_reset: bool, can_suspend: bool, can_resume: bool, can_screenshot: bool, } /// Get the list of VMs that can be controlled by VirtWeb remote pub async fn list() -> HttpResult { let rights = virtweb_client::get_token_info().await?; let mut res = vec![]; for v in rights.list_vm() { let vm_info = virtweb_client::get_vm_info(v).await?; res.push(VMInfoAndCaps { uiid: vm_info.uuid, name: vm_info.name, description: vm_info.description.clone(), can_get_state: rights.is_route_allowed("GET", &v.route_state()), can_start: rights.is_route_allowed("GET", &v.route_start()), can_shutdown: rights.is_route_allowed("GET", &v.route_shutdown()), can_kill: rights.is_route_allowed("GET", &v.route_kill()), can_reset: rights.is_route_allowed("GET", &v.route_reset()), can_suspend: rights.is_route_allowed("GET", &v.route_suspend()), can_resume: rights.is_route_allowed("GET", &v.route_resume()), can_screenshot: rights.is_route_allowed("GET", &v.route_screenshot()), }) } Ok(HttpResponse::Ok().json(res)) }