Skip to content

Commit

Permalink
docker modules: various adjustments (#51700)
Browse files Browse the repository at this point in the history
* Move docker_ module_utils into subpackage.

* Remove docker_ prefix from module_utils.docker modules.

* Adding jurisdiction for module_utils/docker to $team_docker.

* Making docker* unit tests community supported.

* Linting.

* Python < 2.6 is not supported.

* Refactoring docker-py version comments. Moving them to doc fragments. Cleaning up some indentations.
  • Loading branch information
felixfontein authored and gundalow committed Feb 8, 2019
1 parent 88df4e2 commit 0c2bb3d
Show file tree
Hide file tree
Showing 25 changed files with 178 additions and 274 deletions.
11 changes: 8 additions & 3 deletions .github/BOTMETA.yml
Expand Up @@ -582,8 +582,7 @@ files:
labels: windows
maintainers: $team_windows_core
support: core
$module_utils/docker_common.py: *docker
$module_utils/docker_swarm.py: *docker
$module_utils/docker/: *docker
$module_utils/ec2.py:
support: core
labels:
Expand Down Expand Up @@ -1289,6 +1288,7 @@ files:
test/integration/targets/postgresql: *postgresql
test/integration/targets/setup_acme:
maintainers: resmo felixfontein
test/integration/targets/setup_docker: *docker
test/integration/targets/setup_mysql_db: *mysql
test/integration/targets/setup_zabbix:
maintainers: eikef D3DeFi
Expand All @@ -1304,8 +1304,13 @@ files:
test/legacy/scaleway:
<<: *scaleway
support: community
test/units/module_utils/docker/:
<<: *docker
support: community
test/units/module_utils/facts/network/test_generic_bsd.py: *bsd
test/units/modules/cloud/docker: *docker
test/units/modules/cloud/docker:
<<: *docker
support: community
test/units/modules/network:
maintainers: $team_networking
labels: networking
Expand Down
Empty file.
File renamed without changes.
Expand Up @@ -7,11 +7,11 @@
try:
from docker.errors import APIError
except ImportError:
# missing docker-py handled in ansible.module_utils.docker_common
# missing docker-py handled in ansible.module_utils.docker.common
pass

from ansible.module_utils._text import to_native
from ansible.module_utils.docker_common import AnsibleDockerClient
from ansible.module_utils.docker.common import AnsibleDockerClient


class AnsibleDockerSwarmClient(AnsibleDockerClient):
Expand Down
22 changes: 7 additions & 15 deletions lib/ansible/modules/cloud/docker/docker_compose.py
Expand Up @@ -140,22 +140,14 @@
default: 10
extends_documentation_fragment:
- docker
- docker
- docker.docker_py_1_documentation
requirements:
- "python >= 2.6"
- "docker-py >= 1.8.0"
- "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).
For Python 2.6, C(docker-py) must be used. Otherwise, it is recommended to
install the C(docker) Python module. Note that both modules should I(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."
- "docker-compose >= 1.7.0"
- "Docker API >= 1.20"
- "PyYAML >= 3.11"
- "docker-py >= 1.8.0"
- "docker-compose >= 1.7.0"
- "Docker API >= 1.20"
- "PyYAML >= 3.11"
'''

EXAMPLES = '''
Expand Down Expand Up @@ -468,7 +460,7 @@
HAS_COMPOSE_EXC = str(exc)
DEFAULT_TIMEOUT = 10

from ansible.module_utils.docker_common import AnsibleDockerClient, DockerBaseClass
from ansible.module_utils.docker.common import AnsibleDockerClient, DockerBaseClass


AUTH_PARAM_MAPPING = {
Expand Down
12 changes: 4 additions & 8 deletions lib/ansible/modules/cloud/docker/docker_config.py
Expand Up @@ -67,15 +67,11 @@
- present
extends_documentation_fragment:
- docker
- docker
- docker.docker_py_2_documentation
requirements:
- "python >= 2.7"
- "docker >= 2.6.0"
- "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).
Version 2.6.0 or newer is only available with the C(docker) module."
- "Docker API >= 1.30"
author:
Expand Down Expand Up @@ -162,10 +158,10 @@
try:
from docker.errors import APIError
except ImportError:
# missing docker-py handled in ansible.module_utils.docker_common
# missing docker-py handled in ansible.module_utils.docker.common
pass

from ansible.module_utils.docker_common import AnsibleDockerClient, DockerBaseClass, compare_generic
from ansible.module_utils.docker.common import AnsibleDockerClient, DockerBaseClass, compare_generic
from ansible.module_utils._text import to_native, to_bytes


Expand Down
42 changes: 17 additions & 25 deletions lib/ansible/modules/cloud/docker/docker_container.py
Expand Up @@ -586,30 +586,22 @@
- Path to the working directory.
version_added: "2.4"
extends_documentation_fragment:
- docker
- docker
- docker.docker_py_1_documentation
author:
- "Cove Schneider (@cove)"
- "Joshua Conner (@joshuaconner)"
- "Pavel Antonov (@softzilla)"
- "Thomas Steinbach (@ThomasSteinbach)"
- "Philippe Jandot (@zfil)"
- "Daan Oosterveld (@dusdanig)"
- "Chris Houseknecht (@chouseknecht)"
- "Kassian Sun (@kassiansun)"
- "Cove Schneider (@cove)"
- "Joshua Conner (@joshuaconner)"
- "Pavel Antonov (@softzilla)"
- "Thomas Steinbach (@ThomasSteinbach)"
- "Philippe Jandot (@zfil)"
- "Daan Oosterveld (@dusdanig)"
- "Chris Houseknecht (@chouseknecht)"
- "Kassian Sun (@kassiansun)"
requirements:
- "python >= 2.6"
- "docker-py >= 1.8.0"
- "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).
For Python 2.6, C(docker-py) must be used. Otherwise, it is recommended to
install the C(docker) Python module. Note that both modules should I(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."
- "Docker API >= 1.20"
- "docker-py >= 1.8.0"
- "Docker API >= 1.20"
'''

EXAMPLES = '''
Expand Down Expand Up @@ -875,7 +867,7 @@
from distutils.version import LooseVersion

from ansible.module_utils.basic import human_to_bytes
from ansible.module_utils.docker_common import (
from ansible.module_utils.docker.common import (
AnsibleDockerClient,
DockerBaseClass, sanitize_result, is_image_name_id,
compare_generic, DifferenceTracker,
Expand All @@ -884,14 +876,14 @@

try:
from docker import utils
from ansible.module_utils.docker_common import docker_version
from ansible.module_utils.docker.common import docker_version
if LooseVersion(docker_version) >= LooseVersion('1.10.0'):
from docker.types import Ulimit, LogConfig
else:
from docker.utils.types import Ulimit, LogConfig
from docker.errors import APIError, NotFound
except Exception:
# missing docker-py handled in ansible.module_utils.docker
# missing docker-py handled in ansible.module_utils.docker.common
pass


Expand Down Expand Up @@ -1546,7 +1538,7 @@ def _parse_healthcheck(self):
elif key == 'retries':
try:
result[key] = int(result[key])
except Exception as e:
except Exception as dummy:
self.fail('Cannot parse number of retries for healthcheck. '
'Expected an integer, got "{0}".'.format(result[key]))

Expand Down Expand Up @@ -2555,7 +2547,7 @@ def container_remove(self, container_id, link=False, force=False):
while True:
try:
response = self.client.remove_container(container_id, v=volume_state, link=link, force=force)
except NotFound as exc:
except NotFound as dummy:
pass
except APIError as exc:
if 'Unpause the container before stopping or killing' in exc.explanation:
Expand Down
20 changes: 6 additions & 14 deletions lib/ansible/modules/cloud/docker/docker_container_facts.py
Expand Up @@ -32,23 +32,15 @@
- When identifying an existing container name may be a name or a long or short container ID.
required: true
extends_documentation_fragment:
- docker
- docker
- docker.docker_py_1_documentation
author:
- "Felix Fontein (@felixfontein)"
- "Felix Fontein (@felixfontein)"
requirements:
- "python >= 2.6"
- "docker-py >= 1.8.0"
- "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).
For Python 2.6, C(docker-py) must be used. Otherwise, it is recommended to
install the C(docker) Python module. Note that both modules should I(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."
- "Docker API >= 1.20"
- "docker-py >= 1.8.0"
- "Docker API >= 1.20"
'''

EXAMPLES = '''
Expand Down Expand Up @@ -114,7 +106,7 @@
}'
'''

from ansible.module_utils.docker_common import AnsibleDockerClient
from ansible.module_utils.docker.common import AnsibleDockerClient


def main():
Expand Down
30 changes: 9 additions & 21 deletions lib/ansible/modules/cloud/docker/docker_host_facts.py
Expand Up @@ -91,23 +91,15 @@
type: bool
default: no
extends_documentation_fragment:
- docker
- docker
- docker.docker_py_1_documentation
author:
- Piotr Wojciechowski (@WojciechowskiPiotr)
- Piotr Wojciechowski (@WojciechowskiPiotr)
requirements:
- "python >= 2.6"
- "docker-py >= 1.10.0"
- "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).
For Python 2.6, C(docker-py) must be used. Otherwise, it is recommended to
install the C(docker) Python module. Note that both modules should I(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."
- "Docker API >= 1.21"
- "docker-py >= 1.10.0"
- "Docker API >= 1.21"
'''

EXAMPLES = '''
Expand Down Expand Up @@ -186,20 +178,16 @@
'''

from ansible.module_utils.docker_common import AnsibleDockerClient, DockerBaseClass
from ansible.module_utils.docker.common import AnsibleDockerClient, DockerBaseClass
from ansible.module_utils._text import to_native

try:
from docker.errors import APIError, NotFound
from docker.errors import APIError
except ImportError:
# missing docker-py handled in ansible.module_utils.docker_common
# missing docker-py handled in ansible.module_utils.docker.common
pass

try:
from ansible.module_utils.docker_common import docker_version, clean_dict_booleans_for_docker_api
except Exception as dummy:
# missing docker-py handled in ansible.module_utils.docker
pass
from ansible.module_utils.docker.common import clean_dict_booleans_for_docker_api


class DockerHostManager(DockerBaseClass):
Expand Down
14 changes: 3 additions & 11 deletions lib/ansible/modules/cloud/docker/docker_image.py
Expand Up @@ -175,19 +175,11 @@
version_added: "2.0"
extends_documentation_fragment:
- docker
- docker
- docker.docker_py_1_documentation
requirements:
- "python >= 2.6"
- "docker-py >= 1.8.0"
- "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).
For Python 2.6, C(docker-py) must be used. Otherwise, it is recommended to
install the C(docker) Python module. Note that both modules should I(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."
- "Docker API >= 1.20"
author:
Expand Down Expand Up @@ -276,7 +268,7 @@
import os
import re

from ansible.module_utils.docker_common import (
from ansible.module_utils.docker.common import (
HAS_DOCKER_PY_2, HAS_DOCKER_PY_3, AnsibleDockerClient, DockerBaseClass, is_image_name_id,
)
from ansible.module_utils._text import to_native
Expand Down
16 changes: 4 additions & 12 deletions lib/ansible/modules/cloud/docker/docker_image_facts.py
Expand Up @@ -32,19 +32,11 @@
required: true
extends_documentation_fragment:
- docker
- docker
- docker.docker_py_1_documentation
requirements:
- "python >= 2.6"
- "docker-py >= 1.8.0"
- "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).
For Python 2.6, C(docker-py) must be used. Otherwise, it is recommended to
install the C(docker) Python module. Note that both modules should I(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."
- "Docker API >= 1.20"
author:
Expand Down Expand Up @@ -161,10 +153,10 @@
try:
from docker import utils
except ImportError:
# missing docker-py handled in ansible.module_utils.docker_common
# missing docker-py handled in ansible.module_utils.docker.common
pass

from ansible.module_utils.docker_common import AnsibleDockerClient, DockerBaseClass, is_image_name_id
from ansible.module_utils.docker.common import AnsibleDockerClient, DockerBaseClass, is_image_name_id


class ImageManager(DockerBaseClass):
Expand Down

0 comments on commit 0c2bb3d

Please sign in to comment.