mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-18 12:52:37 +00:00
Rewrite the docker_network_info module (#409)
* Rewrite the docker_network_info module. * Improve error messages.
This commit is contained in:
parent
4c026307fb
commit
18fdd04782
4
changelogs/fragments/409-docker-api.yml
Normal file
4
changelogs/fragments/409-docker-api.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
major_changes:
|
||||||
|
- "docker_network_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/409)."
|
||||||
@ -27,15 +27,13 @@ options:
|
|||||||
type: str
|
type: str
|
||||||
required: yes
|
required: yes
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- community.docker.docker
|
- community.docker.docker.api_documentation
|
||||||
- community.docker.docker.docker_py_1_documentation
|
|
||||||
|
|
||||||
|
|
||||||
author:
|
author:
|
||||||
- "Dave Bendit (@DBendit)"
|
- "Dave Bendit (@DBendit)"
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) >= 1.8.0"
|
|
||||||
- "Docker API >= 1.25"
|
- "Docker API >= 1.25"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
@ -102,16 +100,11 @@ import traceback
|
|||||||
|
|
||||||
from ansible.module_utils.common.text.converters import to_native
|
from ansible.module_utils.common.text.converters import to_native
|
||||||
|
|
||||||
try:
|
from ansible_collections.community.docker.plugins.module_utils.common_api import (
|
||||||
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 (
|
|
||||||
AnsibleDockerClient,
|
AnsibleDockerClient,
|
||||||
RequestException,
|
RequestException,
|
||||||
)
|
)
|
||||||
|
from ansible_collections.community.docker.plugins.module_utils._api.errors import DockerException
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -133,10 +126,10 @@ def main():
|
|||||||
network=network,
|
network=network,
|
||||||
)
|
)
|
||||||
except DockerException as e:
|
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:
|
except RequestException as e:
|
||||||
client.fail(
|
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())
|
exception=traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -70,7 +70,7 @@
|
|||||||
- "'is too new. Maximum supported API version is' in docker_inspect.stderr"
|
- "'is too new. Maximum supported API version is' in docker_inspect.stderr"
|
||||||
when: docker_inspect is failed
|
when: docker_inspect is failed
|
||||||
|
|
||||||
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_network_info tests!"
|
- fail: msg="Too old docker / docker-py version to run docker_network_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)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user