24 lines
724 B
Rust
24 lines
724 B
Rust
|
use crate::controllers::{HttpResult, LibVirtReq};
|
||
|
use crate::libvirt_lib_structures::XMLUuid;
|
||
|
use crate::libvirt_rest_structures::NetworkInfo;
|
||
|
use actix_web::{web, HttpResponse};
|
||
|
|
||
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||
|
struct NetworkID {
|
||
|
id: XMLUuid,
|
||
|
}
|
||
|
|
||
|
/// Create a new network
|
||
|
pub async fn create(client: LibVirtReq, req: web::Json<NetworkInfo>) -> HttpResult {
|
||
|
let network = match req.0.to_virt_network() {
|
||
|
Ok(d) => d,
|
||
|
Err(e) => {
|
||
|
log::error!("Failed to extract network info! {e}");
|
||
|
return Ok(HttpResponse::BadRequest().body(e.to_string()));
|
||
|
}
|
||
|
};
|
||
|
let id = client.update_network(network).await?;
|
||
|
|
||
|
Ok(HttpResponse::Ok().json(NetworkID { id }))
|
||
|
}
|