mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-04 17:44:11 +02:00
improve cleanup of leftover networks and workdirs
This commit is contained in:
parent
4bb6a21d7c
commit
755573ba4b
2 changed files with 32 additions and 9 deletions
|
|
@ -1,19 +1,21 @@
|
|||
use bollard::Docker;
|
||||
use crate::cloud::Cloud;
|
||||
use bollard::network::CreateNetworkOptions;
|
||||
use bollard::Docker;
|
||||
use miette::{IntoDiagnostic, Result, WrapErr};
|
||||
|
||||
pub async fn clear_networks(docker: &Docker) -> Result<()> {
|
||||
pub async fn clear_networks(docker: &Docker, instances: &[Cloud]) -> Result<()> {
|
||||
let networks = docker
|
||||
.list_networks::<&str>(None)
|
||||
.await
|
||||
.into_diagnostic()
|
||||
.wrap_err("Failed to list docker networks")?;
|
||||
for network in networks {
|
||||
match network.name.as_deref() {
|
||||
Some(name) if name.starts_with("haze-") => {
|
||||
docker.remove_network(name).await.ok();
|
||||
if let Some(name) = network.name.as_deref() {
|
||||
if let Some(id) = name.strip_prefix("haze-") {
|
||||
if !instances.iter().any(|cloud| cloud.id == id) {
|
||||
docker.remove_network(name).await.ok();
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue