implement image serving in objectstore so nginx isn't required in development

reviewed by yosh
This commit is contained in:
Jesse Andrews 2010-06-20 15:09:17 -07:00
parent 13aef6666a
commit 5a4e4ecb28
2 changed files with 30 additions and 0 deletions

View File

@ -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")

View File

@ -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: