From f68abf9b0e3e2ba206c560c19db321c6f88670f1 Mon Sep 17 00:00:00 2001 From: Alvaro Lopez Garcia Date: Fri, 2 Dec 2011 14:18:38 +0100 Subject: 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 --- nova/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'nova/utils.py') 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 -- cgit