diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-06-22 17:44:57 +0200 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-06-23 08:21:50 +0200 |
commit | b39f15d9f7ed589b9078dd9b1f7003c69de74f32 (patch) | |
tree | c4ca9d46c374706ad51107b6ef2a051aef2191b4 | |
parent | 2ebb3a00aca2eaaea5f182b1f72e21c09fcba6ee (diff) |
Add Endpoint::images() to get information about the images on an endpoint
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r-- | src/endpoint/configured.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index aecb291..822ed55 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -296,6 +296,23 @@ impl Endpoint { Ok(None) } } + + pub async fn images(&self, name_filter: Option<&str>) -> Result<impl Iterator<Item = Image>> { + let mut listopts = shiplift::builder::ImageListOptions::builder(); + + if let Some(name) = name_filter { + listopts.filter_name(name); + } else { + listopts.all(); + } + + self.docker + .images() + .list(&listopts.build()) + .await + .map_err(Error::from) + .map(|v| v.into_iter().map(Image::from)) + } } /// Helper type to store endpoint statistics @@ -357,6 +374,28 @@ impl From<shiplift::rep::Container> for ContainerStat { } } +#[derive(Getters)] +pub struct Image { + #[getset(get = "pub")] + created: chrono::DateTime<chrono::Utc>, + + #[getset(get = "pub")] + id: String, + + #[getset(get = "pub")] + tags: Option<Vec<String>>, +} + +impl From<shiplift::rep::Image> for Image { + fn from(img: shiplift::rep::Image) -> Self { + Image { + created: img.created, + id: img.id, + tags: img.repo_tags, + } + } +} + pub struct EndpointHandle(Arc<Endpoint>); impl EndpointHandle { |