Can get XML network definition
This commit is contained in:
		@@ -452,6 +452,20 @@ impl Handler<GetNetworkXMLReq> for LibVirtActor {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Message)]
 | 
			
		||||
#[rtype(result = "anyhow::Result<String>")]
 | 
			
		||||
pub struct GetSourceNetworkXMLReq(pub XMLUuid);
 | 
			
		||||
 | 
			
		||||
impl Handler<GetSourceNetworkXMLReq> for LibVirtActor {
 | 
			
		||||
    type Result = anyhow::Result<String>;
 | 
			
		||||
 | 
			
		||||
    fn handle(&mut self, msg: GetSourceNetworkXMLReq, _ctx: &mut Self::Context) -> Self::Result {
 | 
			
		||||
        log::debug!("Get network XML:\n{}", msg.0.as_string());
 | 
			
		||||
        let network = Network::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
 | 
			
		||||
        Ok(network.get_xml_desc(0)?)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Message)]
 | 
			
		||||
#[rtype(result = "anyhow::Result<()>")]
 | 
			
		||||
pub struct DeleteNetwork(pub XMLUuid);
 | 
			
		||||
 
 | 
			
		||||
@@ -42,6 +42,12 @@ pub async fn get_single(client: LibVirtReq, req: web::Path<NetworkID>) -> HttpRe
 | 
			
		||||
    Ok(HttpResponse::Ok().json(network))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get the XML source description of a single network
 | 
			
		||||
pub async fn single_src(client: LibVirtReq, req: web::Path<NetworkID>) -> HttpResult {
 | 
			
		||||
    let xml = client.get_single_network_xml(req.uid).await?;
 | 
			
		||||
    Ok(HttpResponse::Ok().content_type("application/xml").body(xml))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Update the information about a single network
 | 
			
		||||
pub async fn update(
 | 
			
		||||
    client: LibVirtReq,
 | 
			
		||||
 
 | 
			
		||||
@@ -119,6 +119,13 @@ impl LibVirtClient {
 | 
			
		||||
        self.0.send(libvirt_actor::GetNetworkXMLReq(id)).await?
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Get the source XML configuration of a single network
 | 
			
		||||
    pub async fn get_single_network_xml(&self, id: XMLUuid) -> anyhow::Result<String> {
 | 
			
		||||
        self.0
 | 
			
		||||
            .send(libvirt_actor::GetSourceNetworkXMLReq(id))
 | 
			
		||||
            .await?
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Delete a network
 | 
			
		||||
    pub async fn delete_network(&self, id: XMLUuid) -> anyhow::Result<()> {
 | 
			
		||||
        self.0.send(libvirt_actor::DeleteNetwork(id)).await?
 | 
			
		||||
 
 | 
			
		||||
@@ -199,6 +199,10 @@ async fn main() -> std::io::Result<()> {
 | 
			
		||||
                "/api/network/{uid}",
 | 
			
		||||
                web::get().to(network_controller::get_single),
 | 
			
		||||
            )
 | 
			
		||||
            .route(
 | 
			
		||||
                "/api/network/{uid}/src",
 | 
			
		||||
                web::get().to(network_controller::single_src),
 | 
			
		||||
            )
 | 
			
		||||
            .route(
 | 
			
		||||
                "/api/network/{uid}",
 | 
			
		||||
                web::put().to(network_controller::update),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user