Full image inspection and just repo tags
Hat tip to @bobrik.
This commit is contained in:
parent
bba322a10e
commit
0d822c0c02
1 changed files with 14 additions and 6 deletions
|
@ -729,16 +729,24 @@ class DockerManager(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_inspect_image(self):
|
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'))
|
image, tag = get_split_image_tag(self.module.params.get('image'))
|
||||||
if tag is None:
|
if tag is None:
|
||||||
tag = 'latest'
|
tag = 'latest'
|
||||||
resource = '%s:%s' % (image, tag)
|
resource = '%s:%s' % (image, tag)
|
||||||
|
|
||||||
matching_image = None
|
|
||||||
for image in self.client.images(name=image):
|
for image in self.client.images(name=image):
|
||||||
if resource in image.get('RepoTags', []):
|
if resource in image.get('RepoTags', []):
|
||||||
matching_image = image
|
return image['RepoTags']
|
||||||
return matching_image
|
return None
|
||||||
|
|
||||||
def get_inspect_containers(self, containers):
|
def get_inspect_containers(self, containers):
|
||||||
inspect = []
|
inspect = []
|
||||||
|
@ -1036,10 +1044,10 @@ class DockerManager(object):
|
||||||
# that map to the same Docker image.
|
# that map to the same Docker image.
|
||||||
inspected = self.get_inspect_image()
|
inspected = self.get_inspect_image()
|
||||||
if inspected:
|
if inspected:
|
||||||
images = inspected.get('RepoTags', [])
|
repo_tags = self.get_image_repo_tags()
|
||||||
else:
|
else:
|
||||||
image, tag = get_split_image_tag(self.module.params.get('image'))
|
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):
|
for i in self.client.containers(all=True):
|
||||||
running_image = i['Image']
|
running_image = i['Image']
|
||||||
|
@ -1049,7 +1057,7 @@ class DockerManager(object):
|
||||||
if name:
|
if name:
|
||||||
matches = name in i.get('Names', [])
|
matches = name in i.get('Names', [])
|
||||||
else:
|
else:
|
||||||
image_matches = running_image in images
|
image_matches = running_image in repo_tags
|
||||||
|
|
||||||
# if a container has an entrypoint, `command` will actually equal
|
# if a container has an entrypoint, `command` will actually equal
|
||||||
# '{} {}'.format(entrypoint, command)
|
# '{} {}'.format(entrypoint, command)
|
||||||
|
|
Loading…
Reference in a new issue