Can get VM caps
This commit is contained in:
@ -7,6 +7,7 @@ use std::io::ErrorKind;
|
||||
|
||||
pub mod auth_controller;
|
||||
pub mod server_controller;
|
||||
pub mod vm_controller;
|
||||
|
||||
/// Custom error to ease controller writing
|
||||
#[derive(Debug)]
|
||||
|
48
remote_backend/src/controllers/vm_controller.rs
Normal file
48
remote_backend/src/controllers/vm_controller.rs
Normal file
@ -0,0 +1,48 @@
|
||||
//! # 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<String>,
|
||||
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))
|
||||
}
|
Reference in New Issue
Block a user