Can get information about a single network

This commit is contained in:
Pierre HUBERT 2023-10-31 11:08:05 +01:00
parent 2741faa95b
commit 2025416607
2 changed files with 15 additions and 4 deletions

View File

@ -4,8 +4,8 @@ use crate::libvirt_rest_structures::NetworkInfo;
use actix_web::{web, HttpResponse};
#[derive(serde::Serialize, serde::Deserialize)]
struct NetworkID {
id: XMLUuid,
pub struct NetworkID {
uid: XMLUuid,
}
/// Create a new network
@ -17,9 +17,9 @@ pub async fn create(client: LibVirtReq, req: web::Json<NetworkInfo>) -> HttpResu
return Ok(HttpResponse::BadRequest().body(e.to_string()));
}
};
let id = client.update_network(network).await?;
let uid = client.update_network(network).await?;
Ok(HttpResponse::Ok().json(NetworkID { id }))
Ok(HttpResponse::Ok().json(NetworkID { uid }))
}
/// Get the list of networks
@ -33,3 +33,10 @@ pub async fn list(client: LibVirtReq) -> HttpResult {
Ok(HttpResponse::Ok().json(networks))
}
/// Get the information about a single network
pub async fn get_single(client: LibVirtReq, req: web::Path<NetworkID>) -> HttpResult {
let network = NetworkInfo::from_xml(client.get_single_network(req.uid).await?)?;
Ok(HttpResponse::Ok().json(network))
}

View File

@ -182,6 +182,10 @@ async fn main() -> std::io::Result<()> {
web::post().to(network_controller::create),
)
.route("/api/network/list", web::get().to(network_controller::list))
.route(
"/api/network/{uid}",
web::get().to(network_controller::get_single),
)
})
.bind(&AppConfig::get().listen_address)?
.run()