Change image API endpoint to use new registry model
This commit is contained in:
parent
254f06e634
commit
7b95082a99
3 changed files with 37 additions and 140 deletions
|
@ -1,11 +1,36 @@
|
|||
""" List and lookup repository images. """
|
||||
import json
|
||||
|
||||
from data.registry_model import registry_model
|
||||
from endpoints.api import (resource, nickname, require_repo_read, RepositoryParamResource,
|
||||
path_param, disallow_for_app_repositories)
|
||||
from endpoints.api.image_models_pre_oci import pre_oci_model as model
|
||||
path_param, disallow_for_app_repositories, format_date)
|
||||
from endpoints.exception import NotFound
|
||||
|
||||
|
||||
def _image_dict(image, with_history=False, with_tags=False):
|
||||
image_data = {
|
||||
'id': image.docker_image_id,
|
||||
'created': format_date(image.created),
|
||||
'comment': image.comment,
|
||||
'command': json.loads(image.command) if image.command else None,
|
||||
'size': image.image_size,
|
||||
'uploading': image.uploading,
|
||||
'sort_index': len(image.parents),
|
||||
}
|
||||
|
||||
if with_tags:
|
||||
image_data['tags'] = [tag.name for tag in image.tags]
|
||||
|
||||
if with_history:
|
||||
image_data['history'] = [_image_dict(parent, with_history, with_tags)
|
||||
for parent in image.parents]
|
||||
|
||||
# Calculate the ancestors string, with the DBID's replaced with the docker IDs.
|
||||
parent_docker_ids = [parent_image.docker_image_id for parent_image in image.parents]
|
||||
image_data['ancestors'] = '/{0}/'.format('/'.join(parent_docker_ids))
|
||||
return image_data
|
||||
|
||||
|
||||
@resource('/v1/repository/<apirepopath:repository>/image/')
|
||||
@path_param('repository', 'The full path of the repository. e.g. namespace/name')
|
||||
class RepositoryImageList(RepositoryParamResource):
|
||||
|
@ -16,11 +41,12 @@ class RepositoryImageList(RepositoryParamResource):
|
|||
@disallow_for_app_repositories
|
||||
def get(self, namespace, repository):
|
||||
""" List the images for the specified repository. """
|
||||
images = model.get_repository_images(namespace, repository)
|
||||
if images is None:
|
||||
repo_ref = registry_model.lookup_repository(namespace, repository)
|
||||
if repo_ref is None:
|
||||
raise NotFound()
|
||||
|
||||
return {'images': [image.to_dict() for image in images]}
|
||||
images = registry_model.get_legacy_images(repo_ref)
|
||||
return {'images': [_image_dict(image, with_tags=True) for image in images]}
|
||||
|
||||
|
||||
@resource('/v1/repository/<apirepopath:repository>/image/<image_id>')
|
||||
|
@ -34,8 +60,12 @@ class RepositoryImage(RepositoryParamResource):
|
|||
@disallow_for_app_repositories
|
||||
def get(self, namespace, repository, image_id):
|
||||
""" Get the information available for the specified image. """
|
||||
image = model.get_repository_image(namespace, repository, image_id)
|
||||
repo_ref = registry_model.lookup_repository(namespace, repository)
|
||||
if repo_ref is None:
|
||||
raise NotFound()
|
||||
|
||||
image = registry_model.get_legacy_image(repo_ref, image_id, include_parents=True)
|
||||
if image is None:
|
||||
raise NotFound()
|
||||
|
||||
return image.to_dict()
|
||||
return _image_dict(image, with_history=True)
|
||||
|
|
Reference in a new issue