summaryrefslogtreecommitdiffstats
path: root/nova/image
diff options
context:
space:
mode:
authorjaypipes@gmail.com <>2010-10-01 16:06:14 -0400
committerjaypipes@gmail.com <>2010-10-01 16:06:14 -0400
commit0ef621d47eeea421820a2191de53dee9e83d8c44 (patch)
tree1b686e54d75a6c48810cbb3c97d8727f2283f7f1 /nova/image
parentbf22bbd2d4f4364255a306e024d1a7d316b89014 (diff)
downloadnova-0ef621d47eeea421820a2191de53dee9e83d8c44.tar.gz
nova-0ef621d47eeea421820a2191de53dee9e83d8c44.tar.xz
nova-0ef621d47eeea421820a2191de53dee9e83d8c44.zip
Adds BaseImageService and flag to control image service loading. Adds unit test for local image service.
Diffstat (limited to 'nova/image')
-rw-r--r--nova/image/service.py114
1 files changed, 102 insertions, 12 deletions
diff --git a/nova/image/service.py b/nova/image/service.py
index 1a7a258b7..4bceab6ee 100644
--- a/nova/image/service.py
+++ b/nova/image/service.py
@@ -20,34 +20,117 @@ import os.path
import random
import string
-class ImageService(object):
- """Provides storage and retrieval of disk image objects."""
+from nova import utils
+from nova import flags
- @staticmethod
- def load():
- """Factory method to return image service."""
- #TODO(gundlach): read from config.
- class_ = LocalImageService
- return class_()
+
+FLAGS = flags.FLAGS
+
+
+flags.DEFINE_string('glance_teller_address', '127.0.0.1',
+ 'IP address or URL where Glance\'s Teller service resides')
+flags.DEFINE_string('glance_teller_port', '9191',
+ 'Port for Glance\'s Teller service')
+flags.DEFINE_string('glance_parallax_address', '127.0.0.1',
+ 'IP address or URL where Glance\'s Parallax service resides')
+flags.DEFINE_string('glance_parallax_port', '9191',
+ 'Port for Glance\'s Parallax service')
+
+
+class BaseImageService(object):
+
+ """Base class for providing image search and retrieval services"""
def index(self):
"""
Return a dict from opaque image id to image data.
"""
+ raise NotImplementedError
def show(self, id):
"""
Returns a dict containing image data for the given opaque image id.
"""
+ raise NotImplementedError
+
+ def create(self, data):
+ """
+ Store the image data and return the new image id.
+
+ :raises AlreadyExists if the image already exist.
+ """
+ raise NotImplementedError
+
+ def update(self, image_id, data):
+ """Replace the contents of the given image with the new data.
-class GlanceImageService(ImageService):
+ :raises NotFound if the image does not exist.
+
+ """
+ raise NotImplementedError
+
+ def delete(self, image_id):
+ """
+ Delete the given image.
+
+ :raises NotFound if the image does not exist.
+
+ """
+ raise NotImplementedError
+
+
+class GlanceImageService(BaseImageService):
+
"""Provides storage and retrieval of disk image objects within Glance."""
- # TODO(gundlach): once Glance has an API, build this.
- pass
+ def index(self):
+ """
+ Calls out to Parallax for a list of images available
+ """
+ raise NotImplementedError
+
+ def show(self, id):
+ """
+ Returns a dict containing image data for the given opaque image id.
+ """
+ raise NotImplementedError
+
+ def create(self, data):
+ """
+ Store the image data and return the new image id.
+
+ :raises AlreadyExists if the image already exist.
+
+ """
+ raise NotImplementedError
+
+ def update(self, image_id, data):
+ """Replace the contents of the given image with the new data.
+
+ :raises NotFound if the image does not exist.
+
+ """
+ raise NotImplementedError
+
+ def delete(self, image_id):
+ """
+ Delete the given image.
+
+ :raises NotFound if the image does not exist.
+
+ """
+ raise NotImplementedError
+
+ def delete_all(self):
+ """
+ Clears out all images
+ """
+ pass
+
+
+class LocalImageService(BaseImageService):
-class LocalImageService(ImageService):
"""Image service storing images to local disk."""
def __init__(self):
@@ -88,3 +171,10 @@ class LocalImageService(ImageService):
Delete the given image. Raises OSError if the image does not exist.
"""
os.unlink(self._path_to(image_id))
+
+ def delete_all(self):
+ """
+ Clears out all images in local directory
+ """
+ for f in os.listdir(self._path):
+ os.unlink(self._path_to(f))