[modules/docker] Return n/a when docker is not available

When the docker python module is not available, return n/a
instead of error'ing out.
This commit is contained in:
Tobias Witek 2018-10-18 19:34:27 +02:00
parent f7d80d8f27
commit a579f32879
2 changed files with 4 additions and 2 deletions

View file

@ -5,7 +5,7 @@
[![Test Coverage](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status/badges/coverage.svg)](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status/coverage)
[![Issue Count](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status/badges/issue_count.svg)](https://codeclimate.com/github/tobi-wan-kenobi/bumblebee-status)
**Many, many thanks to all contributors! As of now, 32 of the modules are from various contributors (!), and only 16 from myself.**
**Many, many thanks to all contributors! As of now, 33 of the modules are from various contributors (!), and only 16 from myself.**
![Solarized Powerline](https://github.com/tobi-wan-kenobi/bumblebee-status/blob/master/screenshots/themes/powerline-solarized.png)

View file

@ -29,9 +29,11 @@ class Module(bumblebee.engine.Module):
self._status = self.status
def status(self, _):
cli = docker.DockerClient(base_url='unix://var/run/docker.sock')
try:
cli = docker.DockerClient(base_url='unix://var/run/docker.sock')
cli.ping()
except ConnectionError:
return "Daemon off"
except Exception:
return "n/a"
return "OK - {}".format(len(cli.containers.list(filters={'status': "running"})))