Can create networks

This commit is contained in:
2023-10-31 09:26:42 +01:00
parent 335aec788e
commit f2237d4f2f
12 changed files with 328 additions and 65 deletions

View File

@ -7,6 +7,7 @@ use std::io::ErrorKind;
pub mod auth_controller;
pub mod iso_controller;
pub mod network_controller;
pub mod server_controller;
pub mod vm_controller;

View 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 }))
}

View File

@ -1,7 +1,7 @@
use crate::actors::vnc_actor::VNCActor;
use crate::actors::vnc_tokens_actor::VNCTokensManager;
use crate::controllers::{HttpResult, LibVirtReq};
use crate::libvirt_lib_structures::{DomainState, DomainXMLUuid};
use crate::libvirt_lib_structures::{DomainState, XMLUuid};
use crate::libvirt_rest_structures::VMInfo;
use actix_web::{web, HttpRequest, HttpResponse};
use actix_web_actors::ws;
@ -15,7 +15,7 @@ struct VMInfoAndState {
#[derive(serde::Serialize)]
struct VMUuid {
uuid: DomainXMLUuid,
uuid: XMLUuid,
}
/// Create a new VM
@ -52,7 +52,7 @@ pub async fn list_all(client: LibVirtReq) -> HttpResult {
#[derive(serde::Deserialize)]
pub struct SingleVMUUidReq {
uid: DomainXMLUuid,
uid: XMLUuid,
}
/// Get the information about a single VM