Can create networks
This commit is contained in:
23
virtweb_backend/src/controllers/network_controller.rs
Normal file
23
virtweb_backend/src/controllers/network_controller.rs
Normal file
@ -0,0 +1,23 @@
|
||||
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 }))
|
||||
}
|
Reference in New Issue
Block a user