Skip to content

Commit

Permalink
Rewrite the docker_container_info module (#402)
Browse files Browse the repository at this point in the history
* Rewrite the docker_container_info module.

* Improve error messages.

* Remove wrong requirement.
  • Loading branch information
felixfontein authored Jul 6, 2022
1 parent 1101997 commit 37ff980
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/402-docker-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
major_changes:
- "docker_container_info - no longer uses the Docker SDK for Python. It requires ``requests`` to be installed,
and depending on the features used has some more requirements. If the Docker SDK for Python is installed,
these requirements are likely met (https://github.com/ansible-collections/community.docker/pull/402)."
17 changes: 5 additions & 12 deletions plugins/modules/docker_container_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@
type: str
required: yes
extends_documentation_fragment:
- community.docker.docker
- community.docker.docker.docker_py_1_documentation
- community.docker.docker.api_documentation
author:
- "Felix Fontein (@felixfontein)"
requirements:
- "L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) >= 1.8.0"
- "Docker API >= 1.25"
'''

Expand Down Expand Up @@ -106,16 +104,11 @@

from ansible.module_utils.common.text.converters import to_native

try:
from docker.errors import DockerException
except ImportError:
# missing Docker SDK for Python handled in ansible.module_utils.docker.common
pass

from ansible_collections.community.docker.plugins.module_utils.common import (
from ansible_collections.community.docker.plugins.module_utils.common_api import (
AnsibleDockerClient,
RequestException,
)
from ansible_collections.community.docker.plugins.module_utils._api.errors import DockerException


def main():
Expand All @@ -137,10 +130,10 @@ def main():
container=container,
)
except DockerException as e:
client.fail('An unexpected docker error occurred: {0}'.format(to_native(e)), exception=traceback.format_exc())
client.fail('An unexpected Docker error occurred: {0}'.format(to_native(e)), exception=traceback.format_exc())
except RequestException as e:
client.fail(
'An unexpected requests error occurred when Docker SDK for Python tried to talk to the docker daemon: {0}'.format(to_native(e)),
'An unexpected requests error occurred when trying to talk to the Docker daemon: {0}'.format(to_native(e)),
exception=traceback.format_exc())


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
state: absent
force_kill: yes

when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.25', '>=')
when: docker_api_version is version('1.25', '>=')

- fail: msg="Too old docker / docker-py version to run docker_container_info tests!"
when: not(docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
when: not(docker_api_version is version('1.25', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)

0 comments on commit 37ff980

Please sign in to comment.