mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
Implement all remaining deprecations for 3.0.0 (#400)
* Remove support for Ansible 2.9 and ansible-base 2.10. * Remove Ansible 2.9 compatiblity code. * Remove docker-compose from EE. * Drop support for Python 2.6. Stop advertising docker-py for Python 2.6. * Drop support for API versions 1.20 to 1.24. * Fix condition.
This commit is contained in:
@@ -71,8 +71,8 @@ except ImportError:
|
||||
try:
|
||||
from requests.exceptions import RequestException
|
||||
except ImportError:
|
||||
# Either docker-py is no longer using requests, or docker-py isn't around either,
|
||||
# or docker-py's dependency requests is missing. In any case, define an exception
|
||||
# Either Docker SDK for Python is no longer using requests, or Docker SDK for Python isn't around either,
|
||||
# or Docker SDK for Python's dependency requests is missing. In any case, define an exception
|
||||
# class RequestException so that our code doesn't break.
|
||||
class RequestException(Exception):
|
||||
pass
|
||||
@@ -180,9 +180,7 @@ def get_connect_params(auth, fail_function):
|
||||
|
||||
DOCKERPYUPGRADE_SWITCH_TO_DOCKER = "Try `pip uninstall docker-py` followed by `pip install docker`."
|
||||
DOCKERPYUPGRADE_UPGRADE_DOCKER = "Use `pip install --upgrade docker` to upgrade."
|
||||
DOCKERPYUPGRADE_RECOMMEND_DOCKER = ("Use `pip install --upgrade docker-py` to upgrade. "
|
||||
"Hint: if you do not need Python 2.6 support, try "
|
||||
"`pip uninstall docker-py` instead, followed by `pip install docker`.")
|
||||
DOCKERPYUPGRADE_RECOMMEND_DOCKER = "Use `pip install --upgrade docker-py` to upgrade."
|
||||
|
||||
|
||||
class AnsibleDockerClientBase(Client):
|
||||
@@ -197,28 +195,22 @@ class AnsibleDockerClientBase(Client):
|
||||
self.fail("Cannot have both the docker-py and docker python modules (old and new version of Docker "
|
||||
"SDK for Python) installed together as they use the same namespace and cause a corrupt "
|
||||
"installation. Please uninstall both packages, and re-install only the docker-py or docker "
|
||||
"python module (for %s's Python %s). It is recommended to install the docker module if no "
|
||||
"support for Python 2.6 is required. Please note that simply uninstalling one of the modules "
|
||||
"can leave the other module in a broken state." % (platform.node(), sys.executable))
|
||||
"python module (for %s's Python %s). It is recommended to install the docker module. Please "
|
||||
"note that simply uninstalling one of the modules can leave the other module in a broken "
|
||||
"state." % (platform.node(), sys.executable))
|
||||
|
||||
if not HAS_DOCKER_PY:
|
||||
if NEEDS_DOCKER_PY2:
|
||||
msg = missing_required_lib("Docker SDK for Python: docker above 5.0.0 (Python >= 3.6) or "
|
||||
"docker before 5.0.0 (Python 2.7)")
|
||||
msg = msg + ", for example via `pip install docker` (Python >= 3.6) or " \
|
||||
+ "`pip install docker==4.4.4` (Python 2.7). The error was: %s"
|
||||
else:
|
||||
msg = missing_required_lib("Docker SDK for Python: docker above 5.0.0 (Python >= 3.6) or "
|
||||
"docker before 5.0.0 (Python 2.7) or docker-py (Python 2.6)")
|
||||
msg = msg + ", for example via `pip install docker` (Python >= 3.6) or `pip install docker==4.4.4` (Python 2.7) " \
|
||||
+ "or `pip install docker-py` (Python 2.6). The error was: %s"
|
||||
msg = missing_required_lib("Docker SDK for Python: docker>=5.0.0 (Python >= 3.6) or "
|
||||
"docker<5.0.0 (Python 2.7)")
|
||||
msg = msg + ", for example via `pip install docker` (Python >= 3.6) or " \
|
||||
+ "`pip install docker==4.4.4` (Python 2.7). The error was: %s"
|
||||
self.fail(msg % HAS_DOCKER_ERROR, exception=HAS_DOCKER_TRACEBACK)
|
||||
|
||||
if self.docker_py_version < LooseVersion(min_docker_version):
|
||||
msg = "Error: Docker SDK for Python version is %s (%s's Python %s). Minimum version required is %s."
|
||||
if not NEEDS_DOCKER_PY2:
|
||||
# The minimal required version is < 2.0 (and the current version as well).
|
||||
# Advertise docker (instead of docker-py) for non-Python-2.6 users.
|
||||
# Advertise docker (instead of docker-py).
|
||||
msg += DOCKERPYUPGRADE_RECOMMEND_DOCKER
|
||||
elif docker_version < LooseVersion('2.0'):
|
||||
msg += DOCKERPYUPGRADE_SWITCH_TO_DOCKER
|
||||
@@ -237,9 +229,9 @@ class AnsibleDockerClientBase(Client):
|
||||
self.fail("Error connecting: %s" % exc)
|
||||
|
||||
self.docker_api_version = LooseVersion(self.docker_api_version_str)
|
||||
if min_docker_api_version is not None:
|
||||
if self.docker_api_version < LooseVersion(min_docker_api_version):
|
||||
self.fail('Docker API version is %s. Minimum version required is %s.' % (self.docker_api_version_str, min_docker_api_version))
|
||||
min_docker_api_version = min_docker_api_version or '1.25'
|
||||
if self.docker_api_version < LooseVersion(min_docker_api_version):
|
||||
self.fail('Docker API version is %s. Minimum version required is %s.' % (self.docker_api_version_str, min_docker_api_version))
|
||||
|
||||
def log(self, msg, pretty_print=False):
|
||||
pass
|
||||
|
||||
@@ -139,7 +139,7 @@ class DockerSocketHandlerBase(object):
|
||||
|
||||
def select(self, timeout=None, _internal_recursion=False):
|
||||
if not _internal_recursion and self._paramiko_read_workaround and len(self._write_buffer) > 0:
|
||||
# When the SSH transport is used, docker-py internally uses Paramiko, whose
|
||||
# When the SSH transport is used, Docker SDK for Python internally uses Paramiko, whose
|
||||
# Channel object supports select(), but only for reading
|
||||
# (https://github.com/paramiko/paramiko/issues/695).
|
||||
if self._sock.send_ready():
|
||||
@@ -208,25 +208,3 @@ class DockerSocketHandlerBase(object):
|
||||
class DockerSocketHandlerModule(DockerSocketHandlerBase):
|
||||
def __init__(self, sock, module, selectors):
|
||||
super(DockerSocketHandlerModule, self).__init__(sock, selectors, module.debug)
|
||||
|
||||
|
||||
def find_selectors(module):
|
||||
try:
|
||||
# ansible-base 2.10+ has selectors a compat version of selectors, which a bundled fallback:
|
||||
from ansible.module_utils.compat import selectors
|
||||
return selectors
|
||||
except ImportError:
|
||||
pass
|
||||
try:
|
||||
# Python 3.4+
|
||||
import selectors
|
||||
return selectors
|
||||
except ImportError:
|
||||
pass
|
||||
try:
|
||||
# backport package installed in the system
|
||||
import selectors2
|
||||
return selectors2
|
||||
except ImportError:
|
||||
pass
|
||||
module.fail_json(msg=missing_required_lib('selectors2', reason='for handling stdin'))
|
||||
|
||||
Reference in New Issue
Block a user