diff options
author | Jesse Andrews <anotherjesse@gmail.com> | 2010-06-20 15:09:17 -0700 |
---|---|---|
committer | Jesse Andrews <anotherjesse@gmail.com> | 2010-06-20 15:09:17 -0700 |
commit | 5a4e4ecb28b338715c1b69a70887b9cf740cb0f7 (patch) | |
tree | c2eca59e963aaa71337f250534062dc7686e7cc8 /nova/objectstore | |
parent | 13aef6666a17dbbe0c4645a30654ba023b9a434e (diff) | |
download | nova-5a4e4ecb28b338715c1b69a70887b9cf740cb0f7.tar.gz |
implement image serving in objectstore so nginx isn't required in development
reviewed by yosh
Diffstat (limited to 'nova/objectstore')
-rw-r--r-- | nova/objectstore/handler.py | 26 | ||||
-rw-r--r-- | nova/objectstore/image.py | 4 |
2 files changed, 30 insertions, 0 deletions
diff --git a/nova/objectstore/handler.py b/nova/objectstore/handler.py index a7fff12fc2..3f00bb0c4f 100644 --- a/nova/objectstore/handler.py +++ b/nova/objectstore/handler.py @@ -71,6 +71,7 @@ class Application(web.Application): def __init__(self, user_manager): web.Application.__init__(self, [ (r"/", RootHandler), + (r"/_images/(.+)", ImageDownloadHandler), (r"/_images/", ImageHandler), (r"/([^/]+)/(.+)", ObjectHandler), (r"/([^/]+)/", BucketHandler), @@ -224,6 +225,31 @@ class ObjectHandler(BaseRequestHandler): self.finish() +class ImageDownloadHandler(BaseRequestHandler): + SUPPORTED_METHODS = ("GET", ) + + @catch_nova_exceptions + def get(self, image_id): + """ send the decrypted image file + + streaming content through python is slow and should only be used + in development mode. You should serve files via a web server + in production. + """ + + self.set_header("Content-Type", "application/octet-stream") + + READ_SIZE = 64*1024 + + img = image.Image(image_id) + with open(img.image_path, 'rb') as fp: + s = fp.read(READ_SIZE) + while s: + self.write(s) + s = fp.read(READ_SIZE) + + self.finish() + class ImageHandler(BaseRequestHandler): SUPPORTED_METHODS = ("POST", "PUT", "GET", "DELETE") diff --git a/nova/objectstore/image.py b/nova/objectstore/image.py index 892ada00cd..b8dae4077f 100644 --- a/nova/objectstore/image.py +++ b/nova/objectstore/image.py @@ -47,6 +47,10 @@ class Image(object): not os.path.isdir(self.path): raise exception.NotFound + @property + def image_path(self): + return os.path.join(self.path, 'image') + def delete(self): for fn in ['info.json', 'image']: try: |