From 0d468a3aa086a7145ed4261b8042d26163ba51c6 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 30 Apr 2015 07:46:41 -0700 Subject: [PATCH] Get docker's default api version definition from both 1.2 location and pre-1.2 location Fixes #1227 --- lib/ansible/modules/cloud/docker/docker.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker.py b/lib/ansible/modules/cloud/docker/docker.py index 3f4ae2d5dc..0c7e54614c 100644 --- a/lib/ansible/modules/cloud/docker/docker.py +++ b/lib/ansible/modules/cloud/docker/docker.py @@ -377,6 +377,13 @@ if HAS_DOCKER_PY: from docker.errors import APIError as DockerAPIError except ImportError: from docker.client import APIError as DockerAPIError + try: + # docker-py 1.2+ + import docker.constants + DEFAULT_DOCKER_API_VERSION = docker.constants.DEFAULT_DOCKER_API_VERSION + except (ImportError, AttributeError): + # docker-py less than 1.2 + DEFAULT_DOCKER_API_VERSION = docker.client.DEFAULT_DOCKER_API_VERSION def _human_to_bytes(number): @@ -567,9 +574,7 @@ class DockerManager(object): else: docker_url = 'unix://var/run/docker.sock' - docker_api_version = module.params.get('docker_api_version') - if not docker_api_version: - docker_api_version=docker.client.DEFAULT_DOCKER_API_VERSION + docker_api_version = module.params.get('docker_api_version', DEFAULT_DOCKER_API_VERSION) tls_client_cert = module.params.get('tls_client_cert', None) if not tls_client_cert and env_cert_path: