Can update or delete domains
This commit is contained in:
@ -65,6 +65,49 @@ pub async fn get_single(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> H
|
||||
}))
|
||||
}
|
||||
|
||||
/// Update a VM information
|
||||
pub async fn update(
|
||||
client: LibVirtReq,
|
||||
id: web::Path<SingleVMUUidReq>,
|
||||
req: web::Json<VMInfo>,
|
||||
) -> HttpResult {
|
||||
let mut domain = req.0.to_domain().map_err(|e| {
|
||||
log::error!("Failed to extract domain info! {e}");
|
||||
HttpResponse::BadRequest().body(e.to_string())
|
||||
})?;
|
||||
|
||||
domain.uuid = Some(id.uid);
|
||||
client.update_domain(domain).await?;
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct DeleteVMQuery {
|
||||
keep_files: bool,
|
||||
}
|
||||
|
||||
/// Delete a VM
|
||||
pub async fn delete(
|
||||
client: LibVirtReq,
|
||||
id: web::Path<SingleVMUUidReq>,
|
||||
req: web::Json<DeleteVMQuery>,
|
||||
) -> HttpResult {
|
||||
if let Err(e) = client.kill_domain(id.uid).await {
|
||||
log::info!("Failed to kill domain before deleting it: {e}");
|
||||
}
|
||||
|
||||
client
|
||||
.delete_domain(id.uid, req.keep_files)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
log::error!("Failed to delete domain! {e}");
|
||||
HttpResponse::InternalServerError().body(e.to_string())
|
||||
})?;
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
||||
/// Start a VM
|
||||
pub async fn start(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
|
||||
Ok(match client.start_domain(id.uid).await {
|
||||
|
Reference in New Issue
Block a user