Add a helper method to Image to parse ancestor string.

This commit is contained in:
Jake Moshenko 2016-08-26 14:46:18 -04:00
parent cd8b45e25b
commit 1d8b72235a
6 changed files with 33 additions and 32 deletions

View file

@ -397,9 +397,7 @@ def get_repo_image_by_storage_checksum(namespace, repository_name, storage_check
def get_image_layers(image):
""" Returns a list of the full layers of an image, including itself (if specified), sorted
from base image outward. """
ancestors = image.ancestors.split('/')[1:-1]
image_ids = [ancestor_id for ancestor_id in ancestors if ancestor_id]
image_ids.append(str(image.id))
image_ids = image.ancestor_id_list() + [image.id]
query = (ImageStoragePlacement
.select(ImageStoragePlacement, Image, ImageStorage, ImageStorageLocation)
@ -410,7 +408,7 @@ def get_image_layers(image):
.where(Image.id << image_ids))
image_list = list(invert_placement_query_results(query))
image_list.sort(key=lambda image: image_ids.index(str(image.id)))
image_list.sort(key=lambda img: image_ids.index(img.id))
return image_list

View file

@ -157,7 +157,7 @@ def garbage_collect_repo(repo):
def gen_referenced_ancestors():
for tagged_image in tagged_images:
# The ancestor list is in the format '/1/2/3/', extract just the ids
ancestor_id_strings = tagged_image.ancestors.split('/')[1:-1]
ancestor_id_strings = tagged_image.ancestor_list()
for img_id_str in ancestor_id_strings:
yield int(img_id_str)
yield tagged_image.id