Switch to using straight docker IDs instead of a hashing scheme

This commit is contained in:
Joseph Schorr 2014-09-18 17:16:10 -04:00
parent 63628678b8
commit a90aab4665
8 changed files with 51 additions and 54 deletions

View file

@ -4,27 +4,26 @@ from collections import defaultdict
from app import storage as store
from endpoints.api import (resource, nickname, require_repo_read, RepositoryParamResource,
format_date, NotFound, calculate_internal_id)
format_date, NotFound)
from data import model
from util.cache import cache_control_flask_restful
def image_view(image):
def image_view(image, image_map):
extended_props = image
if image.storage and image.storage.id:
extended_props = image.storage
command = extended_props.command
def internal_id(aid):
if aid == '':
def docker_id(aid):
if not aid:
return ''
return calculate_internal_id(aid)
return image_map[aid]
# Calculate the ancestors string, with the DBID's replaced with the
# hashed 'internal' IDs.
ancestors = [internal_id(a) for a in image.ancestors.split('/')]
# Calculate the ancestors string, with the DBID's replaced with the docker IDs.
ancestors = [docker_id(a) for a in image.ancestors.split('/')]
ancestors_string = '/'.join(ancestors)
return {
@ -35,10 +34,7 @@ def image_view(image):
'size': extended_props.image_size,
'locations': list(image.storage.locations),
'uploading': image.storage.uploading,
'ancestors': ancestors_string,
'internal_id': calculate_internal_id(image.id),
'sort_index': len(image.ancestors)
}
@ -57,14 +53,16 @@ class RepositoryImageList(RepositoryParamResource):
for tag in all_tags:
tags_by_image_id[tag.image.docker_image_id].append(tag.name)
image_map = {}
for image in all_images:
image_map[str(image.id)] = image.docker_image_id
def add_tags(image_json):
image_json['tags'] = tags_by_image_id[image_json['id']]
return image_json
return {
'images': [add_tags(image_view(image)) for image in all_images]
'images': [add_tags(image_view(image, image_map)) for image in all_images]
}
@ -79,7 +77,12 @@ class RepositoryImage(RepositoryParamResource):
if not image:
raise NotFound()
return image_view(image)
# Lookup all the ancestor images for the image.
image_map = {}
for current_image in model.get_parent_images(namespace, repository, image):
image_map[str(current_image.id)] = image.docker_image_id
return image_view(image, image_map)
@resource('/v1/repository/<repopath:repository>/image/<image_id>/changes')