From 2025416607d456535045f3fdce4dfdbdb0100365 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Tue, 31 Oct 2023 11:08:05 +0100 Subject: [PATCH] Can get information about a single network --- .../src/controllers/network_controller.rs | 15 +++++++++++---- virtweb_backend/src/main.rs | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/virtweb_backend/src/controllers/network_controller.rs b/virtweb_backend/src/controllers/network_controller.rs index 224d8d9..240e021 100644 --- a/virtweb_backend/src/controllers/network_controller.rs +++ b/virtweb_backend/src/controllers/network_controller.rs @@ -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) -> 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) -> HttpResult { + let network = NetworkInfo::from_xml(client.get_single_network(req.uid).await?)?; + + Ok(HttpResponse::Ok().json(network)) +} diff --git a/virtweb_backend/src/main.rs b/virtweb_backend/src/main.rs index 45707f2..70fa907 100644 --- a/virtweb_backend/src/main.rs +++ b/virtweb_backend/src/main.rs @@ -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()