Parse NW filters XML structure

This commit is contained in:
2023-12-28 15:12:38 +01:00
parent b4f765d486
commit 3849b0d51d
9 changed files with 588 additions and 4 deletions

View File

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

View File

@ -0,0 +1,36 @@
use crate::controllers::{HttpResult, LibVirtReq};
use crate::libvirt_lib_structures::XMLUuid;
use actix_web::{web, HttpResponse};
#[derive(serde::Serialize, serde::Deserialize)]
pub struct NetworkFilterID {
uid: XMLUuid,
}
/// Get the list of network filters
pub async fn list(client: LibVirtReq) -> HttpResult {
let networks = match client.get_full_network_filters_list().await {
Err(e) => {
log::error!("Failed to get the list of network filters! {e}");
return Ok(HttpResponse::InternalServerError()
.json(format!("Failed to get the list of networks! {e}")));
}
Ok(l) => l,
};
/*let networks = networks
.into_iter()
.map(|n| NetworkInfo::from_xml(n).unwrap())
.collect::<Vec<_>>();*/
// TODO : turn into lib structure
println!("{:#?}", networks);
Ok(HttpResponse::Ok().body(format!("{:#?}", networks)))
}
/// Get the information about a single network filter
pub async fn get_single(client: LibVirtReq, req: web::Path<NetworkFilterID>) -> HttpResult {
let nwfilter = client.get_single_network_filter(req.uid).await?;
// TODO : turn into lib structure
Ok(HttpResponse::Ok().body(format!("{:#?}", nwfilter)))
}

View File

@ -16,6 +16,7 @@ struct StaticConfig {
iso_mimetypes: &'static [&'static str],
net_mac_prefix: &'static str,
constraints: ServerConstraints,
builtin_network_rules: &'static [&'static str],
}
#[derive(serde::Serialize)]
@ -45,6 +46,7 @@ pub async fn static_config(local_auth: LocalAuthEnabled) -> impl Responder {
oidc_auth_enabled: !AppConfig::get().disable_oidc,
iso_mimetypes: &constants::ALLOWED_ISO_MIME_TYPES,
net_mac_prefix: constants::NET_MAC_ADDR_PREFIX,
builtin_network_rules: &constants::BUILTIN_NETWORK_FILTER_RULES,
constraints: ServerConstraints {
iso_max_size: constants::ISO_MAX_SIZE,