Self fix corrupt docker network (#1907)

This commit is contained in:
Pascal Vizeli 2020-08-13 17:50:39 +02:00 committed by GitHub
parent 8d7b15cbeb
commit dfaffe3ec5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,7 +31,15 @@ class DockerNetwork:
@property @property
def containers(self) -> List[docker.models.containers.Container]: def containers(self) -> List[docker.models.containers.Container]:
"""Return of connected containers from network.""" """Return of connected containers from network."""
return self.network.containers containers: List[docker.models.containers.Container] = []
for cid, data in self.network.attrs.get("Containers", {}).items():
try:
containers.append(self.docker.containers.get(cid))
except docker.errors.APIError as err:
_LOGGER.warning("Docker network is corrupt! %s - run autofix", err)
self.stale_cleanup(data.get("Name", cid))
return containers
@property @property
def gateway(self) -> IPv4Address: def gateway(self) -> IPv4Address: