summaryrefslogtreecommitdiffstats
path: root/nova/objects
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-06-03 09:41:01 -0700
committerDan Smith <danms@us.ibm.com>2013-06-03 10:25:50 -0700
commit820135933168feeb6320a23555ca0ebf5e14fa08 (patch)
tree1c66143a56aec79b5b95638ecc842387360b6430 /nova/objects
parent275e673e90c2a00d45451a232ffd66e7a9618174 (diff)
downloadnova-820135933168feeb6320a23555ca0ebf5e14fa08.tar.gz
nova-820135933168feeb6320a23555ca0ebf5e14fa08.tar.xz
nova-820135933168feeb6320a23555ca0ebf5e14fa08.zip
Make instance object tolerate isotime strings
Any time we get a db object over RPC, the datetime has been serialized to an isotime string. We have other legacy code that needs to tolerate this, and those hacks would need to be replicated in the objects transition. Instead, make the instance object type function tolerate isotime-formatted strings so that we can more easily convert RPC-transited database objects until we're fully converted, at which time we could remove the tolerance. Luckily, the objects still end up with a datetime internally, which means the rest of the code can stop needing to handle strings and datetimes gracefully. Related to blueprint unified-object-model Change-Id: I132559d3541d19353de6acc36a2740185e564105
Diffstat (limited to 'nova/objects')
-rw-r--r--nova/objects/base.py6
-rw-r--r--nova/objects/instance.py6
-rw-r--r--nova/objects/utils.py8
3 files changed, 14 insertions, 6 deletions
diff --git a/nova/objects/base.py b/nova/objects/base.py
index abeebf990..0cfd08e6b 100644
--- a/nova/objects/base.py
+++ b/nova/objects/base.py
@@ -168,9 +168,9 @@ class NovaObject(object):
# by subclasses, but that is a special case. Objects inheriting from
# other objects will not receive this merging of fields contents.
fields = {
- 'created_at': obj_utils.datetime_or_none,
- 'updated_at': obj_utils.datetime_or_none,
- 'deleted_at': obj_utils.datetime_or_none,
+ 'created_at': obj_utils.datetime_or_str_or_none,
+ 'updated_at': obj_utils.datetime_or_str_or_none,
+ 'deleted_at': obj_utils.datetime_or_str_or_none,
}
def __init__(self):
diff --git a/nova/objects/instance.py b/nova/objects/instance.py
index 836d78c08..dbf9786df 100644
--- a/nova/objects/instance.py
+++ b/nova/objects/instance.py
@@ -58,9 +58,9 @@ class Instance(base.NovaObject):
'reservation_id': obj_utils.str_or_none,
- 'scheduled_at': obj_utils.datetime_or_none,
- 'launched_at': obj_utils.datetime_or_none,
- 'terminated_at': obj_utils.datetime_or_none,
+ 'scheduled_at': obj_utils.datetime_or_str_or_none,
+ 'launched_at': obj_utils.datetime_or_str_or_none,
+ 'terminated_at': obj_utils.datetime_or_str_or_none,
'availability_zone': obj_utils.str_or_none,
diff --git a/nova/objects/utils.py b/nova/objects/utils.py
index 042b7b36e..dd654045c 100644
--- a/nova/objects/utils.py
+++ b/nova/objects/utils.py
@@ -27,6 +27,14 @@ def datetime_or_none(dt):
raise ValueError('A datetime.datetime is required here')
+# NOTE(danms): Being tolerant of isotime strings here will help us
+# during our objects transition
+def datetime_or_str_or_none(val):
+ if isinstance(val, basestring):
+ return timeutils.parse_isotime(val)
+ return datetime_or_none(val)
+
+
def int_or_none(val):
"""Attempt to parse an integer value, or None."""
if val is None: