-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- note the modal situation needs tidying up as it is currently messy - failed deletion results in a slightly dodgy y/n modal where neither can do anything...
- Loading branch information
1 parent
6acddc5
commit 8b9ab10
Showing
14 changed files
with
480 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::{docker::network::DockerNetwork, traits::Callback}; | ||
use async_trait::async_trait; | ||
use color_eyre::eyre::Result; | ||
|
||
#[derive(Debug)] | ||
pub struct DeleteNetwork { | ||
docker: bollard::Docker, | ||
network: DockerNetwork, | ||
} | ||
|
||
impl DeleteNetwork { | ||
pub fn new(docker: bollard::Docker, network: DockerNetwork) -> Self { | ||
Self { docker, network } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Callback for DeleteNetwork { | ||
async fn call(&self) -> Result<()> { | ||
let _ = self.network.delete(&self.docker).await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::traits::Callback; | ||
use async_trait::async_trait; | ||
use color_eyre::eyre::Result; | ||
|
||
#[derive(Debug)] | ||
pub struct EmptyCallable {} | ||
|
||
impl Default for EmptyCallable { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl EmptyCallable { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Callback for EmptyCallable { | ||
async fn call(&self) -> Result<()> { | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
pub mod delete_container; | ||
pub mod delete_image; | ||
pub mod delete_network; | ||
pub mod delete_volume; | ||
pub mod empty_callable; | ||
pub use delete_container::DeleteContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
pub mod container; | ||
pub mod image; | ||
pub mod logs; | ||
pub mod network; | ||
pub mod traits; | ||
pub mod util; | ||
pub mod volume; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use bollard::{ | ||
secret::{Network, NetworkContainer}, | ||
}; | ||
use color_eyre::eyre::{bail, Result}; | ||
use serde::Serialize; | ||
use std::collections::HashMap; | ||
|
||
use super::traits::Describe; | ||
|
||
#[derive(Debug, Clone, PartialEq, Serialize)] | ||
pub struct DockerNetwork { | ||
pub id: String, | ||
pub name: String, | ||
pub driver: String, | ||
pub created_at: String, | ||
pub scope: String, | ||
pub internal: Option<bool>, | ||
pub attachable: Option<bool>, | ||
pub containers: Option<HashMap<String, NetworkContainer>>, | ||
} | ||
|
||
impl DockerNetwork { | ||
pub fn from(v: Network) -> Self { | ||
Self { | ||
id: v.id.unwrap_or_default(), | ||
name: v.name.unwrap_or_default(), | ||
driver: v.driver.unwrap_or_default(), | ||
created_at: v.created.unwrap_or_default(), | ||
scope: v.scope.unwrap_or_default(), | ||
internal: v.internal, | ||
attachable: v.attachable, | ||
containers: v.containers, | ||
} | ||
} | ||
|
||
pub async fn list(docker: &bollard::Docker) -> Result<Vec<Self>> { | ||
let networks = docker.list_networks::<String>(None).await?; | ||
let mut network: Vec<Self> = networks.into_iter().map(Self::from).collect(); | ||
|
||
network.sort_by_key(|v| v.name.clone()); | ||
|
||
Ok(network) | ||
} | ||
|
||
pub async fn delete(&self, docker: &bollard::Docker) -> Result<()> { | ||
docker.remove_network(&self.get_name()).await?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl Describe for DockerNetwork { | ||
fn get_id(&self) -> String { | ||
self.get_name() | ||
} | ||
fn get_name(&self) -> String { | ||
self.name.clone() | ||
} | ||
|
||
fn describe(&self) -> Result<Vec<String>> { | ||
let summary = match serde_yml::to_string(&self) { | ||
Ok(s) => s, | ||
Err(_) => { | ||
bail!("failed to parse container summary") | ||
} | ||
}; | ||
Ok(summary.lines().map(String::from).collect()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.