summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorAlvaro Lopez Garcia <aloga@ifca.unican.es>2011-12-02 14:18:38 +0100
committerAlvaro Lopez Garcia <aloga@ifca.unican.es>2011-12-15 18:09:21 +0100
commitf68abf9b0e3e2ba206c560c19db321c6f88670f1 (patch)
tree3e798b368e928c79d15dc7d8337db976324e4e0d /nova/utils.py
parent36791875b599da16d90578b1b53759f82f8e04bb (diff)
downloadnova-f68abf9b0e3e2ba206c560c19db321c6f88670f1.tar.gz
nova-f68abf9b0e3e2ba206c560c19db321c6f88670f1.tar.xz
nova-f68abf9b0e3e2ba206c560c19db321c6f88670f1.zip
Fixes bug 723235
The XML templates have been converted into properties, thus we can compare the mtime of the XML templates (libvirt and cpuinfo) each time they are needed, checking if they have been modified and reloading them. Added a function to read cached files. Change-Id: I6cf0229c6435300e73f9d9a6b10b0bf9bf144a55
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 1139e101e..992482223 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -1110,3 +1110,17 @@ def sanitize_hostname(hostname):
hostname = hostname.strip('.-')
return hostname
+
+
+def read_cached_file(filename, cache_info):
+ """Return the contents of a file. If the file hasn't changed since the
+ last invocation, a cached version will be returned.
+ """
+ mtime = os.path.getmtime(filename)
+ if cache_info and mtime == cache_info.get('mtime', None):
+ return cache_info['data']
+
+ data = open(filename).read()
+ cache_info['data'] = data
+ cache_info['mtime'] = mtime
+ return data