[modules/docker] Add basic docker list module
This commit is contained in:
parent
4a75d9e143
commit
e767f9b393
4 changed files with 86 additions and 36 deletions
37
bumblebee/modules/docker_ps.py
Normal file
37
bumblebee/modules/docker_ps.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Displays the number of docker containers running
|
||||
|
||||
Requires the following python packages:
|
||||
* docker
|
||||
|
||||
"""
|
||||
|
||||
try:
|
||||
import docker
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
import bumblebee.input
|
||||
import bumblebee.output
|
||||
import bumblebee.engine
|
||||
|
||||
|
||||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine, config):
|
||||
widget = bumblebee.output.Widget(full_text=self.status)
|
||||
super(Module, self).__init__(engine, config, widget)
|
||||
self._status = self.status
|
||||
|
||||
def update(self, widgets):
|
||||
self._status = self.status
|
||||
|
||||
def status(self, _):
|
||||
cli = docker.DockerClient(base_url='unix://var/run/docker.sock')
|
||||
try:
|
||||
cli.ping()
|
||||
except ConnectionError:
|
||||
return "Daemon off"
|
||||
return "OK - {}".format(len(cli.containers.list(filters={'status': "running"})))
|
Loading…
Add table
Add a link
Reference in a new issue