Implements VM groups API #206

Merged
pierre merged 7 commits from groups_api into master 2024-11-28 18:06:20 +00:00
2 changed files with 22 additions and 2 deletions
Showing only changes of commit 1c6ca2d76a - Show all commits

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),