From 8efce857b81cb374d5fc494055c64f2b281023ff Mon Sep 17 00:00:00 2001 From: Stephen Paul Suarez Date: Wed, 25 Jun 2014 14:20:07 +0800 Subject: [PATCH 1/2] fixes the now-incorrect module for ApiError https://github.com/dotcloud/docker-py/blob/0.3.2/docker/errors.py - ApiError is now(0.3.2) under the docker.errors --- cloud/docker_image | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/docker_image b/cloud/docker_image index 1727486f8aa..512f17cfd1c 100644 --- a/cloud/docker_image +++ b/cloud/docker_image @@ -235,7 +235,7 @@ def main(): module.exit_json(failed=failed, changed=manager.has_changed(), msg=msg, image_id=image_id) - except docker.client.APIError as e: + except docker.errors.APIError as e: module.exit_json(failed=True, changed=manager.has_changed(), msg="Docker API error: " + e.explanation) except RequestException as e: From 1fa9c2adcc83cfab7d5c13add2a00cb947b60861 Mon Sep 17 00:00:00 2001 From: Stephen Paul Suarez Date: Wed, 25 Jun 2014 14:52:00 +0800 Subject: [PATCH 2/2] support old and new versions of APIError --- cloud/docker_image | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cloud/docker_image b/cloud/docker_image index 512f17cfd1c..90f5adcd074 100644 --- a/cloud/docker_image +++ b/cloud/docker_image @@ -113,6 +113,11 @@ except ImportError, e: print "failed=True msg='failed to import python module: %s'" % e sys.exit(1) +try: + from docker.errors import APIError as DockerAPIError +except ImportError: + from docker.client import APIError as DockerAPIError + class DockerImageManager: def __init__(self, module): @@ -187,7 +192,7 @@ class DockerImageManager: try: self.client.remove_image(i['Id']) self.changed = True - except docker.APIError as e: + except DockerAPIError as e: # image can be removed by docker if not used pass @@ -235,7 +240,7 @@ def main(): module.exit_json(failed=failed, changed=manager.has_changed(), msg=msg, image_id=image_id) - except docker.errors.APIError as e: + except DockerAPIError as e: module.exit_json(failed=True, changed=manager.has_changed(), msg="Docker API error: " + e.explanation) except RequestException as e: