Add groups support (#146)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #146
This commit is contained in:
79
remote_backend/src/controllers/group_controller.rs
Normal file
79
remote_backend/src/controllers/group_controller.rs
Normal file
@ -0,0 +1,79 @@
|
||||
use crate::controllers::HttpResult;
|
||||
use crate::virtweb_client;
|
||||
use crate::virtweb_client::{GroupID, VMUuid};
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct GroupIDInPath {
|
||||
gid: GroupID,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct VMIDInQuery {
|
||||
vm_id: Option<VMUuid>,
|
||||
}
|
||||
|
||||
/// Get the state of one or all VM
|
||||
pub async fn vm_state(
|
||||
path: web::Path<GroupIDInPath>,
|
||||
query: web::Query<VMIDInQuery>,
|
||||
) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(virtweb_client::group_vm_state(&path.gid, query.vm_id).await?))
|
||||
}
|
||||
|
||||
/// Start one or all VM
|
||||
pub async fn vm_start(
|
||||
path: web::Path<GroupIDInPath>,
|
||||
query: web::Query<VMIDInQuery>,
|
||||
) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(virtweb_client::group_vm_start(&path.gid, query.vm_id).await?))
|
||||
}
|
||||
|
||||
/// Shutdown one or all VM
|
||||
pub async fn vm_shutdown(
|
||||
path: web::Path<GroupIDInPath>,
|
||||
query: web::Query<VMIDInQuery>,
|
||||
) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(virtweb_client::group_vm_shutdown(&path.gid, query.vm_id).await?))
|
||||
}
|
||||
|
||||
/// Kill one or all VM
|
||||
pub async fn vm_kill(path: web::Path<GroupIDInPath>, query: web::Query<VMIDInQuery>) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(virtweb_client::group_vm_kill(&path.gid, query.vm_id).await?))
|
||||
}
|
||||
|
||||
/// Reset one or all VM
|
||||
pub async fn vm_reset(
|
||||
path: web::Path<GroupIDInPath>,
|
||||
query: web::Query<VMIDInQuery>,
|
||||
) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(virtweb_client::group_vm_reset(&path.gid, query.vm_id).await?))
|
||||
}
|
||||
|
||||
/// Suspend one or all VM
|
||||
pub async fn vm_suspend(
|
||||
path: web::Path<GroupIDInPath>,
|
||||
query: web::Query<VMIDInQuery>,
|
||||
) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(virtweb_client::group_vm_suspend(&path.gid, query.vm_id).await?))
|
||||
}
|
||||
|
||||
/// Resume one or all VM
|
||||
pub async fn vm_resume(
|
||||
path: web::Path<GroupIDInPath>,
|
||||
query: web::Query<VMIDInQuery>,
|
||||
) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().json(virtweb_client::group_vm_resume(&path.gid, query.vm_id).await?))
|
||||
}
|
||||
|
||||
/// Screenshot one or all VM
|
||||
pub async fn vm_screenshot(
|
||||
path: web::Path<GroupIDInPath>,
|
||||
query: web::Query<VMIDInQuery>,
|
||||
) -> HttpResult {
|
||||
let screenshot = virtweb_client::group_vm_screenshot(&path.gid, query.vm_id).await?;
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.insert_header(("content-type", "image/png"))
|
||||
.body(screenshot))
|
||||
}
|
Reference in New Issue
Block a user