Add a helper method to Image to parse ancestor string.
This commit is contained in:
parent
cd8b45e25b
commit
1d8b72235a
6 changed files with 33 additions and 32 deletions
|
@ -13,7 +13,7 @@ def image_view(image, image_map, include_ancestors=True):
|
|||
command = image.command
|
||||
|
||||
def docker_id(aid):
|
||||
if not aid or not aid in image_map:
|
||||
if aid not in image_map:
|
||||
return ''
|
||||
|
||||
return image_map[aid].docker_image_id
|
||||
|
@ -30,14 +30,14 @@ def image_view(image, image_map, include_ancestors=True):
|
|||
|
||||
if include_ancestors:
|
||||
# Calculate the ancestors string, with the DBID's replaced with the docker IDs.
|
||||
ancestors = [docker_id(a) for a in image.ancestors.split('/')]
|
||||
image_data['ancestors'] = '/'.join(ancestors)
|
||||
ancestors = [docker_id(a) for a in image.ancestor_id_list()]
|
||||
image_data['ancestors'] = '/{0}/'.format('/'.join(ancestors))
|
||||
|
||||
return image_data
|
||||
|
||||
|
||||
def historical_image_view(image, image_map):
|
||||
ancestors = [image_map[a] for a in image.ancestors.split('/')[1:-1]]
|
||||
ancestors = [image_map[a] for a in image.ancestor_id_list()]
|
||||
normal_view = image_view(image, image_map)
|
||||
normal_view['history'] = [image_view(parent, image_map, False) for parent in ancestors]
|
||||
return normal_view
|
||||
|
@ -58,23 +58,23 @@ class RepositoryImageList(RepositoryParamResource):
|
|||
all_images = model.image.get_repository_images_without_placements(repo)
|
||||
all_tags = model.tag.list_repository_tags(namespace, repository)
|
||||
|
||||
tags_by_image_id = defaultdict(list)
|
||||
tags_by_docker_id = defaultdict(list)
|
||||
found_image_ids = set()
|
||||
|
||||
for tag in all_tags:
|
||||
tags_by_image_id[tag.image.docker_image_id].append(tag.name)
|
||||
found_image_ids.add(str(tag.image.id))
|
||||
found_image_ids.update(tag.image.ancestors.split('/')[1:-1])
|
||||
tags_by_docker_id[tag.image.docker_image_id].append(tag.name)
|
||||
found_image_ids.add(tag.image.id)
|
||||
found_image_ids.update(tag.image.ancestor_id_list())
|
||||
|
||||
image_map = {}
|
||||
filtered_images = []
|
||||
for image in all_images:
|
||||
if str(image.id) in found_image_ids:
|
||||
image_map[str(image.id)] = image
|
||||
if image.id in found_image_ids:
|
||||
image_map[image.id] = image
|
||||
filtered_images.append(image)
|
||||
|
||||
def add_tags(image_json):
|
||||
image_json['tags'] = tags_by_image_id[image_json['id']]
|
||||
image_json['tags'] = tags_by_docker_id[image_json['id']]
|
||||
return image_json
|
||||
|
||||
return {
|
||||
|
@ -98,7 +98,7 @@ class RepositoryImage(RepositoryParamResource):
|
|||
# Lookup all the ancestor images for the image.
|
||||
image_map = {}
|
||||
for current_image in model.image.get_parent_images(namespace, repository, image):
|
||||
image_map[str(current_image.id)] = current_image
|
||||
image_map[current_image.id] = current_image
|
||||
|
||||
return historical_image_view(image, image_map)
|
||||
|
||||
|
|
Reference in a new issue