summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsh Wilson <smashwilson@gmail.com>2015-03-09 10:05:56 -0400
committerAsh Wilson <smashwilson@gmail.com>2015-03-09 10:05:56 -0400
commit79db47531650e7c87658a59a5d9e293ab39ec684 (patch)
tree5a7f5d342562f974a7f2ef4aa0852315fe8c568f
parent1c0623ab8d934c651b317ffffdb0d2a6cc8082bd (diff)
downloadansible-modules-core-79db47531650e7c87658a59a5d9e293ab39ec684.tar.gz
Full image inspection and just repo tags
Hat tip to @bobrik.
-rw-r--r--cloud/docker/docker.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/cloud/docker/docker.py b/cloud/docker/docker.py
index f42cf882..1bfbdf99 100644
--- a/cloud/docker/docker.py
+++ b/cloud/docker/docker.py
@@ -725,16 +725,24 @@ class DockerManager(object):
return False
def get_inspect_image(self):
+ try:
+ return self.client.inspect_image(self.module.params.get('image'))
+ except DockerAPIError as e:
+ if e.response.status_code == 404:
+ return None
+ else:
+ raise e
+
+ def get_image_repo_tags(self):
image, tag = get_split_image_tag(self.module.params.get('image'))
if tag is None:
tag = 'latest'
resource = '%s:%s' % (image, tag)
- matching_image = None
for image in self.client.images(name=image):
if resource in image.get('RepoTags', []):
- matching_image = image
- return matching_image
+ return image['RepoTags']
+ return None
def get_inspect_containers(self, containers):
inspect = []
@@ -1032,10 +1040,10 @@ class DockerManager(object):
# that map to the same Docker image.
inspected = self.get_inspect_image()
if inspected:
- images = inspected.get('RepoTags', [])
+ repo_tags = self.get_image_repo_tags()
else:
image, tag = get_split_image_tag(self.module.params.get('image'))
- images = [':'.join([image, tag])]
+ repo_tags = [':'.join([image, tag])]
for i in self.client.containers(all=True):
running_image = i['Image']
@@ -1045,7 +1053,7 @@ class DockerManager(object):
if name:
matches = name in i.get('Names', [])
else:
- image_matches = running_image in images
+ image_matches = running_image in repo_tags
# if a container has an entrypoint, `command` will actually equal
# '{} {}'.format(entrypoint, command)