Can get information about a single network
This commit is contained in:
parent
2741faa95b
commit
2025416607
@ -4,8 +4,8 @@ use crate::libvirt_rest_structures::NetworkInfo;
|
|||||||
use actix_web::{web, HttpResponse};
|
use actix_web::{web, HttpResponse};
|
||||||
|
|
||||||
#[derive(serde::Serialize, serde::Deserialize)]
|
#[derive(serde::Serialize, serde::Deserialize)]
|
||||||
struct NetworkID {
|
pub struct NetworkID {
|
||||||
id: XMLUuid,
|
uid: XMLUuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new network
|
/// 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()));
|
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
|
/// Get the list of networks
|
||||||
@ -33,3 +33,10 @@ pub async fn list(client: LibVirtReq) -> HttpResult {
|
|||||||
|
|
||||||
Ok(HttpResponse::Ok().json(networks))
|
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))
|
||||||
|
}
|
||||||
|
@ -182,6 +182,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
web::post().to(network_controller::create),
|
web::post().to(network_controller::create),
|
||||||
)
|
)
|
||||||
.route("/api/network/list", web::get().to(network_controller::list))
|
.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)?
|
.bind(&AppConfig::get().listen_address)?
|
||||||
.run()
|
.run()
|
||||||
|
Loading…
Reference in New Issue
Block a user