Not compatible with the new Docker API 2.0 (Docker 1.13) (issue #1000)

pull/1005/head
nicolargo 2017-01-21 09:46:51 +01:00
parent d54e85f4b6
commit 138cb2dbaa
3 changed files with 32 additions and 6 deletions

1
NEWS
View File

@ -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)

View File

@ -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:

View File

@ -3,7 +3,7 @@ bernhard
bottle
cassandra-driver
couchdb
docker-py
docker>=2.0.2
elasticsearch
hddtemp
influxdb