1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[docker] Add compatibility with docker-py v2.0

This commit is contained in:
dariko 2016-12-20 14:55:03 +01:00 committed by Ryan S. Brown
parent 339312a6b4
commit e2a1ce2916
4 changed files with 36 additions and 13 deletions

View file

@ -27,17 +27,24 @@ from urlparse import urlparse
from ansible.module_utils.basic import *
HAS_DOCKER_PY = True
HAS_DOCKER_PY_2 = False
HAS_DOCKER_ERROR = None
try:
from requests.exceptions import SSLError
from docker import Client
from docker import __version__ as docker_version
from docker.errors import APIError, TLSParameterError, NotFound
from docker.tls import TLSConfig
from docker.constants import DEFAULT_TIMEOUT_SECONDS, DEFAULT_DOCKER_API_VERSION
from docker.utils.types import Ulimit, LogConfig
from docker import auth
if LooseVersion(docker_version) >= LooseVersion('2.0.0'):
HAS_DOCKER_PY_2 = True
from docker import APIClient as Client
from docker.types import Ulimit, LogConfig
else:
from docker import Client
from docker.utils.types import Ulimit, LogConfig
except ImportError as exc:
HAS_DOCKER_ERROR = str(exc)
HAS_DOCKER_PY = False

View file

@ -656,6 +656,9 @@ from ansible.module_utils.docker_common import *
try:
from docker import utils
if HAS_DOCKER_PY_2:
from docker.types import Ulimit
else:
from docker.utils.types import Ulimit
except:
# missing docker-py handled in ansible.module_utils.docker

View file

@ -250,6 +250,9 @@ image:
from ansible.module_utils.docker_common import *
try:
if HAS_DOCKER_PY_2:
from docker.auth import resolve_repository_name
else:
from docker.auth.auth import resolve_repository_name
from docker.utils.utils import parse_repository_tag
except ImportError:

View file

@ -164,6 +164,9 @@ from ansible.module_utils.docker_common import *
try:
from docker import utils
if HAS_DOCKER_PY_2:
from docker.types import Ulimit, IPAMPool, IPAMConfig
else:
from docker.utils.types import Ulimit
except:
# missing docker-py handled in ansible.module_utils.docker
@ -275,8 +278,15 @@ class DockerNetworkManager(object):
if not self.existing_network:
ipam_pools = []
if self.parameters.ipam_options:
if HAS_DOCKER_PY_2:
ipam_pools.append(IPAMPool(**self.parameters.ipam_options))
else:
ipam_pools.append(utils.create_ipam_pool(**self.parameters.ipam_options))
if HAS_DOCKER_PY_2:
ipam_config = IPAMConfig(driver=self.parameters.ipam_driver,
pool_configs=ipam_pools)
else:
ipam_config = utils.create_ipam_config(driver=self.parameters.ipam_driver,
pool_configs=ipam_pools)