23 lines
701 B
Python
23 lines
701 B
Python
|
from data.model import config, DataModelException
|
||
|
|
||
|
from data.database import ImageStorage, Image, ImageStorageLocation, ImageStoragePlacement
|
||
|
|
||
|
|
||
|
class BlobDoesNotExist(DataModelException):
|
||
|
pass
|
||
|
|
||
|
|
||
|
def get_blob_by_digest(blob_digest):
|
||
|
try:
|
||
|
return ImageStorage.get(checksum=blob_digest)
|
||
|
except ImageStorage.DoesNotExist:
|
||
|
raise BlobDoesNotExist('Blob does not exist with digest: {0}'.format(blob_digest))
|
||
|
|
||
|
|
||
|
def store_blob_record(blob_digest, location_name):
|
||
|
storage = ImageStorage.create(checksum=blob_digest)
|
||
|
location = ImageStorageLocation.get(name=location_name)
|
||
|
ImageStoragePlacement.create(location=location, storage=storage)
|
||
|
storage.locations = {location_name}
|
||
|
return storage
|