2013-11-11 21:41:33 +00:00
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
2014-06-17 20:03:43 +00:00
|
|
|
class StoragePaths(object):
|
|
|
|
shared_images = 'sharedimages'
|
|
|
|
|
2014-06-17 20:37:48 +00:00
|
|
|
@staticmethod
|
|
|
|
def temp_store_handler():
|
|
|
|
tmpf = tempfile.TemporaryFile()
|
2014-11-24 21:07:38 +00:00
|
|
|
|
2014-06-17 20:37:48 +00:00
|
|
|
def fn(buf):
|
|
|
|
try:
|
|
|
|
tmpf.write(buf)
|
|
|
|
except IOError:
|
|
|
|
pass
|
2014-11-24 21:07:38 +00:00
|
|
|
|
2014-06-17 20:37:48 +00:00
|
|
|
return tmpf, fn
|
|
|
|
|
2014-06-17 20:03:43 +00:00
|
|
|
def image_path(self, storage_uuid):
|
|
|
|
return '{0}/{1}/'.format(self.shared_images, storage_uuid)
|
|
|
|
|
|
|
|
def image_layer_path(self, storage_uuid):
|
|
|
|
base_path = self.image_path(storage_uuid)
|
|
|
|
return '{0}layer'.format(base_path)
|
|
|
|
|
|
|
|
def image_ancestry_path(self, storage_uuid):
|
|
|
|
base_path = self.image_path(storage_uuid)
|
|
|
|
return '{0}ancestry'.format(base_path)
|
|
|
|
|
|
|
|
def image_file_trie_path(self, storage_uuid):
|
|
|
|
base_path = self.image_path(storage_uuid)
|
|
|
|
return '{0}files.trie'.format(base_path)
|
|
|
|
|
|
|
|
def image_file_diffs_path(self, storage_uuid):
|
|
|
|
base_path = self.image_path(storage_uuid)
|
|
|
|
return '{0}diffs.json'.format(base_path)
|
|
|
|
|
2013-11-07 04:21:12 +00:00
|
|
|
|
2014-06-17 20:03:43 +00:00
|
|
|
class BaseStorage(StoragePaths):
|
2013-11-07 04:21:12 +00:00
|
|
|
"""Storage is organized as follow:
|
|
|
|
$ROOT/images/<image_id>/json
|
|
|
|
$ROOT/images/<image_id>/layer
|
|
|
|
$ROOT/repositories/<namespace>/<repository_name>/<tag_name>
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Useful if we want to change those locations later without rewriting
|
|
|
|
# the code which uses Storage
|
|
|
|
repositories = 'repositories'
|
|
|
|
images = 'images'
|
|
|
|
# Set the IO buffer to 64kB
|
|
|
|
buffer_size = 64 * 1024
|
|
|
|
|
2015-01-16 21:10:40 +00:00
|
|
|
def setup(self):
|
|
|
|
""" Called to perform any storage system setup. """
|
|
|
|
pass
|
|
|
|
|
2015-09-14 21:49:35 +00:00
|
|
|
def validate(self, client):
|
|
|
|
""" Called to perform any custom storage system validation. The client is an HTTP
|
|
|
|
client to use for any external calls. """
|
2015-07-27 18:32:02 +00:00
|
|
|
pass
|
|
|
|
|
2014-09-09 19:54:03 +00:00
|
|
|
def get_direct_download_url(self, path, expires_in=60, requires_cors=False):
|
2013-12-04 00:39:07 +00:00
|
|
|
return None
|
|
|
|
|
2014-09-09 19:54:03 +00:00
|
|
|
def get_direct_upload_url(self, path, mime_type, requires_cors=True):
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_supports_resumable_downloads(self):
|
2014-07-02 04:39:59 +00:00
|
|
|
return False
|
|
|
|
|
2013-11-07 04:21:12 +00:00
|
|
|
def get_content(self, path):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def put_content(self, path, content):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def stream_read(self, path):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def stream_read_file(self, path):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2014-09-11 19:33:10 +00:00
|
|
|
def stream_write(self, path, fp, content_type=None, content_encoding=None):
|
2013-11-07 04:21:12 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def list_directory(self, path=None):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def exists(self, path):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def remove(self, path):
|
|
|
|
raise NotImplementedError
|
2014-09-09 19:54:03 +00:00
|
|
|
|
|
|
|
def get_checksum(self, path):
|
2014-11-24 21:07:38 +00:00
|
|
|
raise NotImplementedError
|
2015-07-06 19:00:07 +00:00
|
|
|
|
2015-06-28 10:29:22 +00:00
|
|
|
def copy_to(self, destination, path):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2015-07-06 19:00:07 +00:00
|
|
|
|
|
|
|
class DigestInvalidException(RuntimeError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class BaseStorageV2(BaseStorage):
|
|
|
|
def initiate_chunked_upload(self):
|
|
|
|
""" Start a new chunked upload, and return a handle with which the upload can be referenced.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def stream_upload_chunk(self, uuid, offset, length, in_fp):
|
|
|
|
""" Upload the specified amount of data from the given file pointer to the chunked destination
|
|
|
|
specified, starting at the given offset. Returns the number of bytes written.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def complete_chunked_upload(self, uuid, final_path, digest_to_verify):
|
|
|
|
""" Complete the chunked upload and store the final results in the path indicated.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|