Can delete network filter
This commit is contained in:
		@@ -5,7 +5,7 @@ use crate::libvirt_lib_structures::nwfilter::*;
 | 
				
			|||||||
use crate::libvirt_lib_structures::*;
 | 
					use crate::libvirt_lib_structures::*;
 | 
				
			||||||
use crate::libvirt_rest_structures::hypervisor::*;
 | 
					use crate::libvirt_rest_structures::hypervisor::*;
 | 
				
			||||||
use crate::libvirt_rest_structures::net::*;
 | 
					use crate::libvirt_rest_structures::net::*;
 | 
				
			||||||
use crate::libvirt_rest_structures::nw_filter::NetworkFilter;
 | 
					use crate::libvirt_rest_structures::nw_filter::{NetworkFilter, NetworkFilterName};
 | 
				
			||||||
use crate::libvirt_rest_structures::vm::*;
 | 
					use crate::libvirt_rest_structures::vm::*;
 | 
				
			||||||
use actix::{Actor, Context, Handler, Message};
 | 
					use actix::{Actor, Context, Handler, Message};
 | 
				
			||||||
use image::ImageOutputFormat;
 | 
					use image::ImageOutputFormat;
 | 
				
			||||||
@@ -618,3 +618,27 @@ impl Handler<DefineNWFilterReq> for LibVirtActor {
 | 
				
			|||||||
        Ok(uuid)
 | 
					        Ok(uuid)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Message)]
 | 
				
			||||||
 | 
					#[rtype(result = "anyhow::Result<()>")]
 | 
				
			||||||
 | 
					pub struct DeleteNetworkFilter(pub XMLUuid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Handler<DeleteNetworkFilter> for LibVirtActor {
 | 
				
			||||||
 | 
					    type Result = anyhow::Result<()>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fn handle(&mut self, msg: DeleteNetworkFilter, _ctx: &mut Self::Context) -> Self::Result {
 | 
				
			||||||
 | 
					        log::debug!("Delete network filter: {}\n", msg.0.as_string());
 | 
				
			||||||
 | 
					        let nw_filter = NWFilter::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
 | 
				
			||||||
 | 
					        let nw_filter_name = nw_filter.get_name()?;
 | 
				
			||||||
 | 
					        nw_filter.undefine()?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Remove backup definition
 | 
				
			||||||
 | 
					        let backup_definition =
 | 
				
			||||||
 | 
					            AppConfig::get().net_filter_definition_path(&NetworkFilterName(nw_filter_name));
 | 
				
			||||||
 | 
					        if backup_definition.exists() {
 | 
				
			||||||
 | 
					            std::fs::remove_file(backup_definition)?;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Ok(())
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,3 +91,10 @@ pub async fn update(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    Ok(HttpResponse::Ok().json("Network filter updated"))
 | 
					    Ok(HttpResponse::Ok().json("Network filter updated"))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Delete a network filter
 | 
				
			||||||
 | 
					pub async fn delete(client: LibVirtReq, path: web::Path<NetworkFilterID>) -> HttpResult {
 | 
				
			||||||
 | 
					    client.delete_network_filter(path.uid).await?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Ok(HttpResponse::Ok().json("Network deleted"))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -197,4 +197,9 @@ impl LibVirtClient {
 | 
				
			|||||||
            .send(libvirt_actor::DefineNWFilterReq(nwf_def, xml))
 | 
					            .send(libvirt_actor::DefineNWFilterReq(nwf_def, xml))
 | 
				
			||||||
            .await?
 | 
					            .await?
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /// Delete a network filter
 | 
				
			||||||
 | 
					    pub async fn delete_network_filter(&self, id: XMLUuid) -> anyhow::Result<()> {
 | 
				
			||||||
 | 
					        self.0.send(libvirt_actor::DeleteNetworkFilter(id)).await?
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -256,6 +256,10 @@ async fn main() -> std::io::Result<()> {
 | 
				
			|||||||
                "/api/nwfilter/{uid}",
 | 
					                "/api/nwfilter/{uid}",
 | 
				
			||||||
                web::put().to(nwfilter_controller::update),
 | 
					                web::put().to(nwfilter_controller::update),
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					            .route(
 | 
				
			||||||
 | 
					                "/api/nwfilter/{uid}",
 | 
				
			||||||
 | 
					                web::delete().to(nwfilter_controller::delete),
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
            // Static assets
 | 
					            // Static assets
 | 
				
			||||||
            .route("/", web::get().to(static_controller::root_index))
 | 
					            .route("/", web::get().to(static_controller::root_index))
 | 
				
			||||||
            .route(
 | 
					            .route(
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user