summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorSalvatore Orlando <salvatore.orlando@eu.citrix.com>2011-03-24 09:38:12 +0000
committerSalvatore Orlando <salvatore.orlando@eu.citrix.com>2011-03-24 09:38:12 +0000
commita3dee96483cb416cb1605cb6975135ea09bd12b6 (patch)
tree5dd0e6f791e5b16773cd08199d71062a0d0f9ce6 /nova/utils.py
parentf0a44da43c804d689e8174957f35dbe2f857acdc (diff)
parent08fd7016db5b0e435b8d9728345739afcf3cb152 (diff)
merge trunk
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 8b9ce4734..e4d8a70eb 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -335,6 +335,14 @@ def utcnow():
utcnow.override_time = None
+def is_older_than(before, seconds):
+ """Return True if before is older than 'seconds'"""
+ if utcnow() - before > datetime.timedelta(seconds=seconds):
+ return True
+ else:
+ return False
+
+
def utcnow_ts():
"""Timestamp version of our utcnow function."""
return time.mktime(utcnow().timetuple())
@@ -653,3 +661,12 @@ def get_from_path(items, path):
return results
else:
return get_from_path(results, remainder)
+
+
+def check_isinstance(obj, cls):
+ """Checks that obj is of type cls, and lets PyLint infer types"""
+ if isinstance(obj, cls):
+ return obj
+ raise Exception(_("Expected object of type: %s") % (str(cls)))
+ # TODO(justinsb): Can we make this better??
+ return cls() # Ugly PyLint hack