Modify the rule of filtering glance tag

In the current progress of filtering glance image tags,
there are two problems:
1 When use "repo:tag" to pull image , if the glance image
tags were not updated , we will not get it even though the
glance image is what we want.
2 the current progress use update time to filter glance images,
this is an unreliable parameters which with some randomness.

we can use repo to find glance image firstly, if more than one
image is returned, then use tag to filter.

Change-Id: Ida4274688e7088e672c8963e75fd29ee524fbf97
Closes-bug: #1769912
This commit is contained in:
weikeyou 2018-05-09 23:35:54 +08:00
parent 778ed4ab6e
commit e6eb3045c0
1 changed files with 4 additions and 10 deletions

View File

@ -59,20 +59,14 @@ def find_images(context, image_ident, tag, exact_match):
# ignore exception
pass
else:
kwargs = {}
kwargs['sort-dir'] = 'desc'
kwargs['sort-key'] = 'updated_at'
if not tag:
filters = {'container_format': 'docker'}
else:
filters = {'container_format': 'docker', 'tag': [tag]}
kwargs['filters'] = filters
images = list(glance.images.list(**kwargs))
filters = {'container_format': 'docker'}
images = list(glance.images.list(filters=filters))
if exact_match:
images = [i for i in images if i.name == image_ident]
else:
images = [i for i in images if image_ident in i.name]
if tag and len(images) > 1:
images = [i for i in images if tag in i.tags]
return images