summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Andrews <anotherjesse@gmail.com>2010-06-12 18:24:27 -0700
committerJesse Andrews <anotherjesse@gmail.com>2010-06-12 18:24:27 -0700
commit0a5c5f8130fce42b1edcfb67c702e25f51aefa13 (patch)
tree8587f2ff0d993e979567ac0201f1b7c2baa6366f
parent6152e3ab712fd38789ea73515f3957c9817a4dfa (diff)
implement image serving in objectstore so nginx isn't required in development
reviewed by yosh
-rw-r--r--nova/objectstore/handler.py26
-rw-r--r--nova/objectstore/image.py4
2 files changed, 30 insertions, 0 deletions
diff --git a/nova/objectstore/handler.py b/nova/objectstore/handler.py
index a7fff12fc..3f00bb0c4 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 892ada00c..b8dae4077 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: