Fix verbs support in V2
This commit is contained in:
parent
cf030e2a98
commit
1450b7e84c
9 changed files with 64 additions and 44 deletions
|
@ -5,7 +5,7 @@ from peewee import JOIN_LEFT_OUTER, fn
|
|||
from datetime import datetime
|
||||
|
||||
from data.model import (DataModelException, db_transaction, _basequery, storage,
|
||||
InvalidImageException)
|
||||
InvalidImageException, config)
|
||||
from data.database import (Image, Repository, ImageStoragePlacement, Namespace, ImageStorage,
|
||||
ImageStorageLocation, RepositoryPermission, db_for_update)
|
||||
|
||||
|
@ -79,7 +79,10 @@ def get_repository_images_base(namespace_name, repository_name, query_modifier):
|
|||
.where(Repository.name == repository_name, Namespace.username == namespace_name))
|
||||
|
||||
query = query_modifier(query)
|
||||
return _translate_placements_to_images_with_locations(query)
|
||||
|
||||
|
||||
def _translate_placements_to_images_with_locations(query):
|
||||
location_list = list(query)
|
||||
|
||||
images = {}
|
||||
|
@ -113,7 +116,7 @@ def lookup_repository_images(namespace_name, repository_name, docker_image_ids):
|
|||
|
||||
def get_matching_repository_images(namespace_name, repository_name, docker_image_ids):
|
||||
def modify_query(query):
|
||||
return query.where(Image.docker_image_id << docker_image_ids)
|
||||
return query.where(Image.docker_image_id << list(docker_image_ids))
|
||||
|
||||
return get_repository_images_base(namespace_name, repository_name, modify_query)
|
||||
|
||||
|
@ -360,25 +363,42 @@ 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. """
|
||||
def has_image_json(image):
|
||||
""" Returns the whether there exists a JSON definition data for the image. """
|
||||
if image.v1_json_metadata:
|
||||
return bool(image.v1_json_metadata)
|
||||
|
||||
store = config.store
|
||||
return store.exists(image.storage.locations, store.image_json_path(image.storage.uuid))
|
||||
|
||||
|
||||
def get_image_json(image):
|
||||
""" Returns the JSON definition data for the image. """
|
||||
if image.v1_json_metadata:
|
||||
return image.v1_json_metadata
|
||||
|
||||
store = config.store
|
||||
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. """
|
||||
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]
|
||||
if include_image:
|
||||
image_ids.append(image.id)
|
||||
image_ids.append(str(image.id))
|
||||
|
||||
if not image_ids:
|
||||
return []
|
||||
query = (ImageStoragePlacement
|
||||
.select(ImageStoragePlacement, Image, ImageStorage, ImageStorageLocation)
|
||||
.join(ImageStorageLocation)
|
||||
.switch(ImageStoragePlacement)
|
||||
.join(ImageStorage, JOIN_LEFT_OUTER)
|
||||
.join(Image)
|
||||
.where(Image.id << image_ids))
|
||||
|
||||
return Image.select().where(Image.id << image_ids)
|
||||
image_list = list(_translate_placements_to_images_with_locations(query))
|
||||
image_list.sort(key=lambda image: image_ids.index(str(image.id)))
|
||||
return image_list
|
||||
|
||||
|
||||
def synthesize_v1_image(namespace, repository_name, storage_checksum, docker_image_id,
|
||||
|
|
Reference in a new issue