summaryrefslogtreecommitdiffstats
path: root/nova/image
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2011-03-24 01:05:13 -0700
committerJustin Santa Barbara <justin@fathomdb.com>2011-03-24 01:05:13 -0700
commit143a8387fcbec34fd919e322a3fed7e9505c8a7c (patch)
tree347dc908b9da81008cff98310211fcef59566075 /nova/image
parent1894937e1ef6769a5f76c0a382931480e2547ce8 (diff)
parent86b3cc94bc672fda7925a247c3b7c2f85be2c5b5 (diff)
Merged with trunk
Diffstat (limited to 'nova/image')
-rw-r--r--nova/image/glance.py36
-rw-r--r--nova/image/service.py16
2 files changed, 37 insertions, 15 deletions
diff --git a/nova/image/glance.py b/nova/image/glance.py
index 15fca69b8..171b28fde 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -18,6 +18,8 @@
from __future__ import absolute_import
+import datetime
+
from glance.common import exception as glance_exception
from nova import exception
@@ -37,8 +39,11 @@ GlanceClient = utils.import_class('glance.client.Client')
class GlanceImageService(service.BaseImageService):
"""Provides storage and retrieval of disk image objects within Glance."""
- def __init__(self):
- self.client = GlanceClient(FLAGS.glance_host, FLAGS.glance_port)
+ def __init__(self, client=None):
+ if client is None:
+ self.client = GlanceClient(FLAGS.glance_host, FLAGS.glance_port)
+ else:
+ self.client = client
def index(self, context):
"""
@@ -50,7 +55,8 @@ class GlanceImageService(service.BaseImageService):
"""
Calls out to Glance for a list of detailed image information
"""
- return self.client.get_images_detailed()
+ return [self._convert_timestamps_to_datetimes(image)
+ for image in self.client.get_images_detailed()]
def show(self, context, image_id):
"""
@@ -60,8 +66,23 @@ class GlanceImageService(service.BaseImageService):
image = self.client.get_image_meta(image_id)
except glance_exception.NotFound:
raise exception.NotFound
+ return self._convert_timestamps_to_datetimes(image)
+
+ def _convert_timestamps_to_datetimes(self, image):
+ """
+ Returns image with known timestamp fields converted to datetime objects
+ """
+ for attr in ['created_at', 'updated_at', 'deleted_at']:
+ if image.get(attr) is not None:
+ image[attr] = self._parse_glance_iso8601_timestamp(image[attr])
return image
+ def _parse_glance_iso8601_timestamp(self, timestamp):
+ """
+ Parse a subset of iso8601 timestamps into datetime objects
+ """
+ return datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%f")
+
def show_by_name(self, context, name):
"""
Returns a dict containing image data for the given name.
@@ -88,7 +109,7 @@ class GlanceImageService(service.BaseImageService):
raise exception.NotFound
for chunk in image_chunks:
data.write(chunk)
- return metadata
+ return self._convert_timestamps_to_datetimes(metadata)
def create(self, context, metadata, data=None):
"""
@@ -97,7 +118,8 @@ class GlanceImageService(service.BaseImageService):
:raises AlreadyExists if the image already exist.
"""
- return self.client.add_image(metadata, data)
+ return self._convert_timestamps_to_datetimes(
+ self.client.add_image(metadata, data))
def update(self, context, image_id, metadata, data=None):
"""Replace the contents of the given image with the new data.
@@ -106,10 +128,10 @@ class GlanceImageService(service.BaseImageService):
"""
try:
- result = self.client.update_image(image_id, metadata, data)
+ metadata = self.client.update_image(image_id, metadata, data)
except glance_exception.NotFound:
raise exception.NotFound
- return result
+ return self._convert_timestamps_to_datetimes(metadata)
def delete(self, context, image_id):
"""
diff --git a/nova/image/service.py b/nova/image/service.py
index c09052cab..e907381c9 100644
--- a/nova/image/service.py
+++ b/nova/image/service.py
@@ -40,9 +40,9 @@ class BaseImageService(object):
:retval: a sequence of mappings with the following signature
{'id': opaque id of image,
'name': name of image,
- 'created_at': creation timestamp,
- 'updated_at': modification timestamp,
- 'deleted_at': deletion timestamp or None,
+ 'created_at': creation datetime object,
+ 'updated_at': modification datetime object,
+ 'deleted_at': deletion datetime object or None,
'deleted': boolean indicating if image has been deleted,
'status': string description of image status,
'is_public': boolean indicating if image is public
@@ -64,9 +64,9 @@ class BaseImageService(object):
{'id': opaque id of image,
'name': name of image,
- 'created_at': creation timestamp,
- 'updated_at': modification timestamp,
- 'deleted_at': deletion timestamp or None,
+ 'created_at': creation datetime object,
+ 'updated_at': modification datetime object,
+ 'deleted_at': deletion datetime object or None,
'deleted': boolean indicating if image has been deleted,
'status': string description of image status,
'is_public': boolean indicating if image is public
@@ -88,7 +88,7 @@ class BaseImageService(object):
def create(self, context, metadata, data=None):
"""
- Store the image metadata and data and return the new image id.
+ Store the image metadata and data and return the new image metadata.
:raises AlreadyExists if the image already exist.
@@ -96,7 +96,7 @@ class BaseImageService(object):
raise NotImplementedError
def update(self, context, image_id, metadata, data=None):
- """Update the given image with the new metadata and data.
+ """Update the given image metadata and data and return the metadata
:raises NotFound if the image does not exist.