From ed0c75f10afb02436eb43b29693941ec97795b46 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 15 Sep 2021 17:12:25 +0200 Subject: Add fn to get number of running containers on endpoint Signed-off-by: Matthias Beyer --- src/endpoint/configured.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index 4a0e933..c6c4953 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -281,6 +281,24 @@ impl Endpoint { }) } + pub async fn number_of_running_containers(&self) -> Result { + self.docker + .containers() + .list({ + &shiplift::builder::ContainerListOptions::builder() + .all() + .build() + }) + .await + .map_err(Error::from) + .map(|list| { + list.into_iter() + .inspect(|stat| trace!("stat = {:?}", stat)) + .filter(|stat| stat.state == "running") + .count() + }) + } + pub async fn has_container_with_id(&self, id: &str) -> Result { self.container_stats() .await? -- cgit v1.2.3