mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-15 11:32:05 +00:00
Drop support for docker-py. (#1171)
This commit is contained in:
parent
0646e52bae
commit
3ff2cfe615
3
changelogs/fragments/1171-docker-py.yml
Normal file
3
changelogs/fragments/1171-docker-py.yml
Normal file
@ -0,0 +1,3 @@
|
||||
removed_features:
|
||||
- "Remove support for Docker SDK for Python version 1.x.y, also known as ``docker-py``. Modules and plugins that use Docker SDK for Python require version 2.0.0+
|
||||
(https://github.com/ansible-collections/community.docker/pull/1171)."
|
||||
@ -157,24 +157,7 @@ options:
|
||||
- name: ansible_docker_validate_certs
|
||||
"""
|
||||
|
||||
# Additional, more specific stuff for minimal Docker SDK for Python version < 2.0
|
||||
|
||||
DOCKER_PY_1_DOCUMENTATION = r"""
|
||||
options: {}
|
||||
notes:
|
||||
- This module uses the L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) to
|
||||
communicate with the Docker daemon.
|
||||
requirements:
|
||||
- "Docker SDK for Python: Please note that the L(docker-py,https://pypi.org/project/docker-py/)
|
||||
Python module has been superseded by L(docker,https://pypi.org/project/docker/)
|
||||
(see L(here,https://github.com/docker/docker-py/issues/1310) for details). Note that both
|
||||
modules should *not* be installed at the same time. Also note that when both modules are
|
||||
installed and one of them is uninstalled, the other might no longer function and a reinstall
|
||||
of it is required."
|
||||
"""
|
||||
|
||||
# Additional, more specific stuff for minimal Docker SDK for Python version >= 2.0.
|
||||
# Note that Docker SDK for Python >= 2.0 requires Python 2.7 or newer.
|
||||
|
||||
DOCKER_PY_2_DOCUMENTATION = r"""
|
||||
options: {}
|
||||
@ -182,11 +165,10 @@ notes:
|
||||
- This module uses the L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) to
|
||||
communicate with the Docker daemon.
|
||||
requirements:
|
||||
- "Python >= 2.7"
|
||||
- "Docker SDK for Python: Please note that the L(docker-py,https://pypi.org/project/docker-py/)
|
||||
Python module has been superseded by L(docker,https://pypi.org/project/docker/)
|
||||
(see L(here,https://github.com/docker/docker-py/issues/1310) for details).
|
||||
This module does *not* work with docker-py."
|
||||
This module does B(not) work with docker-py."
|
||||
"""
|
||||
|
||||
# Docker doc fragment when using the vendored API access code
|
||||
|
||||
@ -63,26 +63,6 @@ else:
|
||||
HAS_DOCKER_TRACEBACK = None # pylint: disable=invalid-name
|
||||
|
||||
|
||||
# The next two imports ``docker.models`` and ``docker.ssladapter`` are used
|
||||
# to ensure the user does not have both ``docker`` and ``docker-py`` modules
|
||||
# installed, as they utilize the same namespace are are incompatible
|
||||
try:
|
||||
# docker (Docker SDK for Python >= 2.0.0)
|
||||
import docker.models # noqa: F401, pylint: disable=unused-import
|
||||
|
||||
HAS_DOCKER_MODELS = True
|
||||
except ImportError:
|
||||
HAS_DOCKER_MODELS = False
|
||||
|
||||
try:
|
||||
# docker-py (Docker SDK for Python < 2.0.0)
|
||||
import docker.ssladapter # noqa: F401, pylint: disable=unused-import
|
||||
|
||||
HAS_DOCKER_SSLADAPTER = True
|
||||
except ImportError:
|
||||
HAS_DOCKER_SSLADAPTER = False
|
||||
|
||||
|
||||
try:
|
||||
from requests.exceptions import ( # noqa: F401, pylint: disable=unused-import
|
||||
RequestException,
|
||||
@ -95,7 +75,7 @@ except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
MIN_DOCKER_VERSION = "1.8.0"
|
||||
MIN_DOCKER_VERSION = "2.0.0"
|
||||
|
||||
|
||||
if not HAS_DOCKER_PY:
|
||||
@ -188,27 +168,15 @@ 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."
|
||||
|
||||
|
||||
class AnsibleDockerClientBase(Client):
|
||||
def __init__(self, min_docker_version=None, min_docker_api_version=None):
|
||||
if min_docker_version is None:
|
||||
min_docker_version = MIN_DOCKER_VERSION
|
||||
needs_docker_py2 = LooseVersion(min_docker_version) >= LooseVersion("2.0.0")
|
||||
|
||||
self.docker_py_version = LooseVersion(docker_version)
|
||||
|
||||
if HAS_DOCKER_MODELS and HAS_DOCKER_SSLADAPTER:
|
||||
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 "
|
||||
f"python module (for {platform.node()}'s Python {sys.executable}). 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."
|
||||
)
|
||||
|
||||
if not HAS_DOCKER_PY:
|
||||
msg = missing_required_lib("Docker SDK for Python: docker>=5.0.0")
|
||||
msg = f"{msg}, for example via `pip install docker`. The error was: {HAS_DOCKER_ERROR}"
|
||||
@ -219,11 +187,7 @@ class AnsibleDockerClientBase(Client):
|
||||
f"Error: Docker SDK for Python version is {docker_version} ({platform.node()}'s Python {sys.executable})."
|
||||
f" Minimum version required is {min_docker_version}."
|
||||
)
|
||||
if not needs_docker_py2:
|
||||
# The minimal required version is < 2.0 (and the current version as well).
|
||||
# Advertise docker (instead of docker-py).
|
||||
msg += DOCKERPYUPGRADE_RECOMMEND_DOCKER
|
||||
elif docker_version < LooseVersion("2.0"):
|
||||
if docker_version < LooseVersion("2.0"):
|
||||
msg += DOCKERPYUPGRADE_SWITCH_TO_DOCKER
|
||||
else:
|
||||
msg += DOCKERPYUPGRADE_UPGRADE_DOCKER
|
||||
@ -751,16 +715,8 @@ class AnsibleDockerClient(AnsibleDockerClientBase):
|
||||
elif not support_docker_py:
|
||||
msg = (
|
||||
f"Docker SDK for Python version is {docker_version} ({platform.node()}'s Python {sys.executable})."
|
||||
f" Minimum version required is {data['docker_py_version']} to {usg}. "
|
||||
f" Minimum version required is {data['docker_py_version']} to {usg}. {DOCKERPYUPGRADE_UPGRADE_DOCKER}"
|
||||
)
|
||||
if LooseVersion(data["docker_py_version"]) < LooseVersion(
|
||||
"2.0.0"
|
||||
):
|
||||
msg += DOCKERPYUPGRADE_RECOMMEND_DOCKER
|
||||
elif self.docker_py_version < LooseVersion("2.0.0"):
|
||||
msg += DOCKERPYUPGRADE_SWITCH_TO_DOCKER
|
||||
else:
|
||||
msg += DOCKERPYUPGRADE_UPGRADE_DOCKER
|
||||
else:
|
||||
# should not happen
|
||||
msg = f"Cannot {usg} with your configuration."
|
||||
|
||||
@ -15,7 +15,7 @@ description:
|
||||
- This module allows to change the node's role, its availability, and to modify, add or remove node labels.
|
||||
extends_documentation_fragment:
|
||||
- community.docker._docker
|
||||
- community.docker._docker.docker_py_1_documentation
|
||||
- community.docker._docker.docker_py_2_documentation
|
||||
- community.docker._attributes
|
||||
- community.docker._attributes.actiongroup_docker
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ description:
|
||||
- Must be executed on a host running as Swarm Manager, otherwise the module will fail.
|
||||
extends_documentation_fragment:
|
||||
- community.docker._docker
|
||||
- community.docker._docker.docker_py_1_documentation
|
||||
- community.docker._docker.docker_py_2_documentation
|
||||
- community.docker._attributes
|
||||
- community.docker._attributes.actiongroup_docker
|
||||
- community.docker._attributes.info_module
|
||||
|
||||
@ -15,7 +15,7 @@ description:
|
||||
- Add/Remove nodes or managers to an existing cluster.
|
||||
extends_documentation_fragment:
|
||||
- community.docker._docker
|
||||
- community.docker._docker.docker_py_1_documentation
|
||||
- community.docker._docker.docker_py_2_documentation
|
||||
- community.docker._attributes
|
||||
- community.docker._attributes.actiongroup_docker
|
||||
|
||||
@ -198,7 +198,7 @@ options:
|
||||
version_added: 3.1.0
|
||||
|
||||
requirements:
|
||||
- "L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) >= 1.10.0"
|
||||
- "L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) >= 2.0.0"
|
||||
- Docker API >= 1.25
|
||||
author:
|
||||
- Thierry Bouvet (@tbouvet)
|
||||
@ -724,7 +724,7 @@ def main():
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_if=required_if,
|
||||
min_docker_version="1.10.0",
|
||||
min_docker_version="2.0.0",
|
||||
option_minimal_versions=option_minimal_versions,
|
||||
)
|
||||
sanitize_labels(client.module.params["labels"], "labels", client)
|
||||
|
||||
@ -24,7 +24,7 @@ author:
|
||||
|
||||
extends_documentation_fragment:
|
||||
- community.docker._docker
|
||||
- community.docker._docker.docker_py_1_documentation
|
||||
- community.docker._docker.docker_py_2_documentation
|
||||
- community.docker._attributes
|
||||
- community.docker._attributes.actiongroup_docker
|
||||
- community.docker._attributes.info_module
|
||||
@ -83,7 +83,7 @@ options:
|
||||
default: false
|
||||
|
||||
requirements:
|
||||
- "L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) >= 1.10.0"
|
||||
- "L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) >= 2.0.0"
|
||||
- "Docker API >= 1.25"
|
||||
"""
|
||||
|
||||
@ -366,7 +366,7 @@ def main():
|
||||
client = AnsibleDockerSwarmClient(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
min_docker_version="1.10.0",
|
||||
min_docker_version="2.0.0",
|
||||
option_minimal_versions=option_minimal_versions,
|
||||
fail_results={
|
||||
"can_talk_to_docker": False,
|
||||
|
||||
@ -18,7 +18,7 @@ description:
|
||||
- Must be executed on a host running as Swarm Manager, otherwise the module will fail.
|
||||
extends_documentation_fragment:
|
||||
- community.docker._docker
|
||||
- community.docker._docker.docker_py_1_documentation
|
||||
- community.docker._docker.docker_py_2_documentation
|
||||
- community.docker._attributes
|
||||
- community.docker._attributes.actiongroup_docker
|
||||
- community.docker._attributes.info_module
|
||||
|
||||
Loading…
Reference in New Issue
Block a user