Can get the screenshots of VMs of a group
This commit is contained in:
		@@ -117,13 +117,30 @@ pub async fn vm_reset(client: LibVirtReq, vms: GroupVmIdExtractor) -> HttpResult
 | 
				
			|||||||
    Ok(HttpResponse::Ok().json(res))
 | 
					    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
 | 
					/// Get the state of the VMs
 | 
				
			||||||
pub async fn vm_state(client: LibVirtReq, vms: GroupVmIdExtractor) -> HttpResult {
 | 
					pub async fn vm_state(client: LibVirtReq, vms: GroupVmIdExtractor) -> HttpResult {
 | 
				
			||||||
    let mut states = HashMap::new();
 | 
					    let mut states = HashMap::new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for vm in vms.0 {
 | 
					    for vm in vms.0 {
 | 
				
			||||||
        if let Some(uuid) = vm.uuid {
 | 
					        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?);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -240,7 +240,10 @@ async fn main() -> std::io::Result<()> {
 | 
				
			|||||||
                "/api/group/{gid}/vm/reset",
 | 
					                "/api/group/{gid}/vm/reset",
 | 
				
			||||||
                web::get().to(groups_controller::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(
 | 
					            .route(
 | 
				
			||||||
                "/api/group/{gid}/vm/state",
 | 
					                "/api/group/{gid}/vm/state",
 | 
				
			||||||
                web::get().to(groups_controller::vm_state),
 | 
					                web::get().to(groups_controller::vm_state),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user