WIP: Add groups support #146
@ -28,3 +28,52 @@ pub async fn vm_start(
|
||||
) -> 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))
|
||||
}
|
||||
|
@ -96,21 +96,30 @@ async fn main() -> std::io::Result<()> {
|
||||
"/api/group/{gid}/vm/start",
|
||||
web::get().to(group_controller::vm_start),
|
||||
)
|
||||
/*.route(
|
||||
.route(
|
||||
"/api/group/{gid}/vm/shutdown",
|
||||
web::get().to(group_controller::vm_shutdown),
|
||||
)
|
||||
.route("/api/group/{gid}/vm/kill", web::get().to(group_controller::vm_kill))
|
||||
.route("/api/group/{gid}/vm/reset", web::get().to(group_controller::vm_reset))
|
||||
.route(
|
||||
"/api/group/{gid}/vm/kill",
|
||||
web::get().to(group_controller::vm_kill),
|
||||
)
|
||||
.route(
|
||||
"/api/group/{gid}/vm/reset",
|
||||
web::get().to(group_controller::vm_reset),
|
||||
)
|
||||
.route(
|
||||
"/api/group/{gid}/vm/suspend",
|
||||
web::get().to(group_controller::vm_suspend),
|
||||
)
|
||||
.route("/api/group/{gid}/vm/resume", web::get().to(group_controller::vm_resume))
|
||||
.route(
|
||||
"/api/group/{gid}/vm/resume",
|
||||
web::get().to(group_controller::vm_resume),
|
||||
)
|
||||
.route(
|
||||
"/api/group/{gid}/vm/screenshot",
|
||||
web::get().to(group_controller::vm_screenshot),
|
||||
)*/
|
||||
)
|
||||
// VM routes
|
||||
.route("/api/vm/{uid}/state", web::get().to(vm_controller::state))
|
||||
.route("/api/vm/{uid}/start", web::get().to(vm_controller::start))
|
||||
|
@ -389,6 +389,52 @@ pub async fn group_vm_start(
|
||||
json_request(id.route_vm_start(vm_id)).await
|
||||
}
|
||||
|
||||
/// Shutdown one or all VMs of a group
|
||||
pub async fn group_vm_shutdown(
|
||||
id: &GroupID,
|
||||
vm_id: Option<VMUuid>,
|
||||
) -> anyhow::Result<TreatmentResult> {
|
||||
json_request(id.route_vm_shutdown(vm_id)).await
|
||||
}
|
||||
|
||||
/// Kill one or all VMs of a group
|
||||
pub async fn group_vm_kill(id: &GroupID, vm_id: Option<VMUuid>) -> anyhow::Result<TreatmentResult> {
|
||||
json_request(id.route_vm_kill(vm_id)).await
|
||||
}
|
||||
|
||||
/// Reset one or all VMs of a group
|
||||
pub async fn group_vm_reset(
|
||||
id: &GroupID,
|
||||
vm_id: Option<VMUuid>,
|
||||
) -> anyhow::Result<TreatmentResult> {
|
||||
json_request(id.route_vm_reset(vm_id)).await
|
||||
}
|
||||
|
||||
/// Suspend one or all VMs of a group
|
||||
pub async fn group_vm_suspend(
|
||||
id: &GroupID,
|
||||
vm_id: Option<VMUuid>,
|
||||
) -> anyhow::Result<TreatmentResult> {
|
||||
json_request(id.route_vm_suspend(vm_id)).await
|
||||
}
|
||||
|
||||
/// Resume one or all VMs of a group
|
||||
pub async fn group_vm_resume(
|
||||
id: &GroupID,
|
||||
vm_id: Option<VMUuid>,
|
||||
) -> anyhow::Result<TreatmentResult> {
|
||||
json_request(id.route_vm_resume(vm_id)).await
|
||||
}
|
||||
|
||||
/// Get the screenshot of one or all VMs of a group
|
||||
pub async fn group_vm_screenshot(id: &GroupID, vm_id: Option<VMUuid>) -> anyhow::Result<Vec<u8>> {
|
||||
Ok(request(id.route_vm_screenshot(vm_id))
|
||||
.await?
|
||||
.bytes()
|
||||
.await?
|
||||
.to_vec())
|
||||
}
|
||||
|
||||
/// Get current server information
|
||||
pub async fn get_server_info() -> anyhow::Result<SystemInfo> {
|
||||
json_request("/api/server/info").await
|
||||
|
Loading…
Reference in New Issue
Block a user