提交 138cb2db 编写于 作者: N nicolargo

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

上级 d54e85f4
......@@ -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)
......
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册