Can get domain state through a dedicated route
This commit is contained in:
		@@ -131,6 +131,22 @@ pub async fn resume(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpR
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Serialize)]
 | 
			
		||||
struct DomainStateRes {
 | 
			
		||||
    state: DomainState,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get the state of a VM
 | 
			
		||||
pub async fn state(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
 | 
			
		||||
    Ok(match client.get_domain_state(id.uid).await {
 | 
			
		||||
        Ok(s) => HttpResponse::Ok().json(DomainStateRes { state: s }),
 | 
			
		||||
        Err(e) => {
 | 
			
		||||
            log::error!("Failed to get domain state {:?} ! {e}", id.uid);
 | 
			
		||||
            HttpResponse::InternalServerError().json("Failed to get domain state!")
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Take a screenshot of a VM
 | 
			
		||||
pub async fn screenshot(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
 | 
			
		||||
    Ok(match client.screenshot_domain(id.uid).await {
 | 
			
		||||
 
 | 
			
		||||
@@ -150,6 +150,7 @@ async fn main() -> std::io::Result<()> {
 | 
			
		||||
                web::get().to(vm_controller::suspend),
 | 
			
		||||
            )
 | 
			
		||||
            .route("/api/vm/{uid}/resume", web::get().to(vm_controller::resume))
 | 
			
		||||
            .route("/api/vm/{uid}/state", web::get().to(vm_controller::state))
 | 
			
		||||
            .route(
 | 
			
		||||
                "/api/vm/{uid}/screenshot",
 | 
			
		||||
                web::get().to(vm_controller::screenshot),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user