From 1c903961b0d563eb05132800d3f42fb9fcbe4b32 Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Wed, 25 Apr 2018 16:55:40 -0700 Subject: Add ignore_removed param to containers.list() to control whether to raise or ignore NotFound Signed-off-by: Joffrey F --- docker/models/containers.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'docker/models/containers.py') diff --git a/docker/models/containers.py b/docker/models/containers.py index 789fa93..b33a718 100644 --- a/docker/models/containers.py +++ b/docker/models/containers.py @@ -844,7 +844,7 @@ class ContainerCollection(Collection): return self.prepare_model(resp) def list(self, all=False, before=None, filters=None, limit=-1, since=None, - sparse=False): + sparse=False, ignore_removed=False): """ List containers. Similar to the ``docker ps`` command. @@ -882,6 +882,10 @@ class ContainerCollection(Collection): information, but guaranteed not to block. Use :py:meth:`Container.reload` on resulting objects to retrieve all attributes. Default: ``False`` + ignore_removed (bool): Ignore failures due to missing containers + when attempting to inspect containers from the original list. + Set to ``True`` if race conditions are likely. Has no effect + if ``sparse=True``. Default: ``False`` Returns: (list of :py:class:`Container`) @@ -902,7 +906,8 @@ class ContainerCollection(Collection): containers.append(self.get(r['Id'])) # a container may have been removed while iterating except NotFound: - pass + if not ignore_removed: + raise return containers def prune(self, filters=None): -- cgit v1.2.1