Can get the screenshots of VMs of a group
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Pierre HUBERT 2024-11-25 21:36:01 +01:00
parent 7eced6b8b5
commit 1c6ca2d76a
2 changed files with 22 additions and 2 deletions

View File

@ -117,13 +117,30 @@ pub async fn vm_reset(client: LibVirtReq, vms: GroupVmIdExtractor) -> HttpResult
Ok(HttpResponse::Ok().json(res))
}
/// Get the screenshot of the VMs of a group
pub async fn vm_screenshot(client: LibVirtReq, vms: GroupVmIdExtractor) -> HttpResult {
if vms.0.is_empty() {
return Ok(HttpResponse::NoContent().finish());
}
let image = if vms.0.len() == 1 {
client.screenshot_domain(vms.0[0].uuid.unwrap()).await?
} else {
return Ok(
HttpResponse::UnprocessableEntity().json("Cannot return multiple VM screenshots!!")
);
};
Ok(HttpResponse::Ok().content_type("image/png").body(image))
}
/// Get the state of the VMs
pub async fn vm_state(client: LibVirtReq, vms: GroupVmIdExtractor) -> HttpResult {
let mut states = HashMap::new();
for vm in vms.0 {
if let Some(uuid) = vm.uuid {
states.insert(uuid.clone(), client.get_domain_state(uuid).await?);
states.insert(uuid, client.get_domain_state(uuid).await?);
}
}

View File

@ -240,7 +240,10 @@ async fn main() -> std::io::Result<()> {
"/api/group/{gid}/vm/reset",
web::get().to(groups_controller::vm_reset),
)
// TODO screenshot VM
.route(
"/api/group/{gid}/vm/screenshot",
web::get().to(groups_controller::vm_screenshot),
)
.route(
"/api/group/{gid}/vm/state",
web::get().to(groups_controller::vm_state),