summaryrefslogtreecommitdiffstats
path: root/nova/image
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2011-03-29 19:09:42 -0700
committerJustin Santa Barbara <justin@fathomdb.com>2011-03-29 19:09:42 -0700
commit93b43cfcaeffa93b2f8ce50f473840c77be532c9 (patch)
treeab3c9f97697c157be300b58ee702e8f4ffab7fb4 /nova/image
parent2315682856f420ff0b781bead142e1aff82071a4 (diff)
parente5f108058f9b085571330dff3c3e3e3e57d2e5ed (diff)
Merged with trunk
Diffstat (limited to 'nova/image')
-rw-r--r--nova/image/glance.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/nova/image/glance.py b/nova/image/glance.py
index be9805b69..fdf468594 100644
--- a/nova/image/glance.py
+++ b/nova/image/glance.py
@@ -220,7 +220,7 @@ def _convert_timestamps_to_datetimes(image_meta):
Returns image with known timestamp fields converted to datetime objects
"""
for attr in ['created_at', 'updated_at', 'deleted_at']:
- if image_meta.get(attr) is not None:
+ if image_meta.get(attr):
image_meta[attr] = _parse_glance_iso8601_timestamp(
image_meta[attr])
return image_meta
@@ -230,8 +230,13 @@ def _parse_glance_iso8601_timestamp(timestamp):
"""
Parse a subset of iso8601 timestamps into datetime objects
"""
- GLANCE_FMT = "%Y-%m-%dT%H:%M:%S"
- ISO_FMT = "%Y-%m-%dT%H:%M:%S.%f"
- # FIXME(sirp): Glance is not returning in ISO format, we should fix Glance
- # to do so, and then switch to parsing it here
- return datetime.datetime.strptime(timestamp, GLANCE_FMT)
+ iso_formats = ["%Y-%m-%dT%H:%M:%S.%f", "%Y-%m-%dT%H:%M:%S"]
+
+ for iso_format in iso_formats:
+ try:
+ return datetime.datetime.strptime(timestamp, iso_format)
+ except ValueError:
+ pass
+
+ raise ValueError(_("%(timestamp)s does not follow any of the "
+ "signatures: %(ISO_FORMATS)s") % locals())