summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicolargo <nicolas@nicolargo.com>2017-01-21 09:47:17 +0100
committernicolargo <nicolas@nicolargo.com>2017-01-21 09:47:17 +0100
commit2926d9e67495c82d4a7522b4716e2cb72b6c67ec (patch)
treea4426df44f880a18dd7b3b46182324c0e2e502c4
parentd54e85f4b612c390db2bdfaa938826eec8e04462 (diff)
parent138cb2dbaa1caa4ec758ccc9d5731cb270f3794b (diff)
Merge branch 'issue1000' into develop
-rw-r--r--NEWS1
-rw-r--r--glances/plugins/glances_docker.py35
-rw-r--r--optional-requirements.txt2
3 files changed, 32 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index ac449ec3..0f938474 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,7 @@ Enhancements and new features:
* GPU monitoring (limited to NVidia) (issue #170)
* WebUI CPU consumption optimization (issue #836)
+ * Not compatible with the new Docker API 2.0 (Docker 1.13) (issue #1000)
* Add ZeroMQ exporter (issue #939)
* Add CouchDB exporter (issue #928)
* Add hotspot Wifi informations (issue #937)
diff --git a/glances/plugins/glances_docker.py b/glances/plugins/glances_docker.py
index 788cbe59..34300750 100644
--- a/glances/plugins/glances_docker.py
+++ b/glances/plugins/glances_docker.py
@@ -93,18 +93,43 @@ class Plugin(GlancesPlugin):
logger.debug("Docker export error {}".format(e))
return ret
- def connect(self, version=None):
- """Connect to the Docker server."""
+ def __connect_old(self, version):
+ """Connect to the Docker server with the 'old school' method"""
+ # Glances is compatible with both API 2.0 and <2.0
+ # (thanks to the @bacondropped patch)
+ if hasattr(docker, 'APIClient'):
+ # Correct issue #1000 for API 2.0
+ init_docker = docker.APIClient
+ elif hasattr(docker, 'Client'):
+ # < API 2.0
+ init_docker = docker.Client
+ else:
+ # Can not found init method (new API version ?)
+ logger.error("Can not found any way to init the Docker API")
+ return None
# Init connection to the Docker API
try:
if version is None:
- ret = docker.Client(base_url='unix://var/run/docker.sock')
+ ret = init_docker(base_url='unix://var/run/docker.sock')
else:
- ret = docker.Client(base_url='unix://var/run/docker.sock',
- version=version)
+ ret = init_docker(base_url='unix://var/run/docker.sock',
+ version=version)
except NameError:
# docker lib not found
return None
+
+ return ret
+
+ def connect(self, version=None):
+ """Connect to the Docker server."""
+ if hasattr(docker, 'from_env') and version is not None:
+ # Connect to Docker using the default socket or
+ # the configuration in your environment
+ ret = docker.from_env()
+ else:
+ ret = self.__connect_old(version=version)
+
+ # Check the server connection with the version() method
try:
ret.version()
except requests.exceptions.ConnectionError as e:
diff --git a/optional-requirements.txt b/optional-requirements.txt
index e1f65005..1ac822f6 100644
--- a/optional-requirements.txt
+++ b/optional-requirements.txt
@@ -3,7 +3,7 @@ bernhard
bottle
cassandra-driver
couchdb
-docker-py
+docker>=2.0.2
elasticsearch
hddtemp
influxdb