Move shared V1/V2 code into common methods and fix verbs

This commit is contained in:
Joseph Schorr 2015-08-13 17:14:17 -04:00
parent 0e93dbb832
commit d246e68e68
5 changed files with 42 additions and 28 deletions

View file

@ -360,6 +360,27 @@ def get_repo_image_by_storage_checksum(namespace, repository_name, storage_check
raise InvalidImageException(msg)
def get_image_json(image, store):
""" Returns the JSON definition data for this image. """
if image.v1_json_metadata:
return image.v1_json_metadata
return store.get_content(image.storage.locations, store.image_json_path(image.storage.uuid))
def get_image_ancestors(image, include_image=True):
""" Returns a query of the full ancestors of an image, including itself. """
ancestors = image.ancestors.split('/')[1:-1]
image_ids = [ancestor_id for ancestor_id in ancestors if ancestor_id]
if include_image:
image_ids.append(image.id)
if not image_ids:
return []
return Image.select().where(Image.id << image_ids)
def synthesize_v1_image(namespace, repository_name, storage_checksum, docker_image_id,
created_date_str, comment, command, v1_json_metadata, parent_docker_id):
""" Find an existing image with this docker image id, and if none exists, write one with the