Can update and delete networks
This commit is contained in:
parent
2025416607
commit
9a99e0b54e
@ -413,3 +413,18 @@ impl Handler<GetNetworkXMLReq> for LibVirtActor {
|
||||
Ok(serde_xml_rs::from_str(&xml)?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<()>")]
|
||||
pub struct DeleteNetwork(pub XMLUuid);
|
||||
|
||||
impl Handler<DeleteNetwork> for LibVirtActor {
|
||||
type Result = anyhow::Result<()>;
|
||||
|
||||
fn handle(&mut self, msg: DeleteNetwork, _ctx: &mut Self::Context) -> Self::Result {
|
||||
log::debug!("Delete network: {}\n", msg.0.as_string());
|
||||
let network = Network::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
|
||||
network.undefine()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -40,3 +40,23 @@ pub async fn get_single(client: LibVirtReq, req: web::Path<NetworkID>) -> HttpRe
|
||||
|
||||
Ok(HttpResponse::Ok().json(network))
|
||||
}
|
||||
|
||||
/// Update the information about a single network
|
||||
pub async fn update(
|
||||
client: LibVirtReq,
|
||||
path: web::Path<NetworkID>,
|
||||
body: web::Json<NetworkInfo>,
|
||||
) -> HttpResult {
|
||||
let mut network = body.0.to_virt_network()?;
|
||||
network.uuid = Some(path.uid);
|
||||
client.update_network(network).await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json("Network updated"))
|
||||
}
|
||||
|
||||
/// Delete a network
|
||||
pub async fn delete(client: LibVirtReq, path: web::Path<NetworkID>) -> HttpResult {
|
||||
client.delete_network(path.uid).await?;
|
||||
|
||||
Ok(HttpResponse::Ok().json("Network deleted"))
|
||||
}
|
||||
|
@ -111,4 +111,9 @@ impl LibVirtClient {
|
||||
pub async fn get_single_network(&self, id: XMLUuid) -> anyhow::Result<NetworkXML> {
|
||||
self.0.send(libvirt_actor::GetNetworkXMLReq(id)).await?
|
||||
}
|
||||
|
||||
/// Delete a network
|
||||
pub async fn delete_network(&self, id: XMLUuid) -> anyhow::Result<()> {
|
||||
self.0.send(libvirt_actor::DeleteNetwork(id)).await?
|
||||
}
|
||||
}
|
||||
|
@ -186,6 +186,14 @@ async fn main() -> std::io::Result<()> {
|
||||
"/api/network/{uid}",
|
||||
web::get().to(network_controller::get_single),
|
||||
)
|
||||
.route(
|
||||
"/api/network/{uid}",
|
||||
web::put().to(network_controller::update),
|
||||
)
|
||||
.route(
|
||||
"/api/network/{uid}",
|
||||
web::delete().to(network_controller::delete),
|
||||
)
|
||||
})
|
||||
.bind(&AppConfig::get().listen_address)?
|
||||
.run()
|
||||
|
Loading…
Reference in New Issue
Block a user