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/virt/libvirt/connection.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'nova/virt') diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 5dee8f0c7..bbd45ee13 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -185,8 +185,6 @@ class LibvirtConnection(driver.ComputeDriver): def __init__(self, read_only): super(LibvirtConnection, self).__init__() - self.libvirt_xml = open(FLAGS.libvirt_xml_template).read() - self.cpuinfo_xml = open(FLAGS.cpuinfo_xml_template).read() self._host_state = None self._wrapped_conn = None self.read_only = read_only @@ -220,6 +218,22 @@ class LibvirtConnection(driver.ComputeDriver): # NOTE(nsokolov): moved instance restarting to ComputeManager pass + @property + def libvirt_xml(self): + if not hasattr(self, '_libvirt_xml_cache_info'): + self._libvirt_xml_cache_info = {} + + return utils.read_cached_file(FLAGS.libvirt_xml_template, + self._libvirt_xml_cache_info) + + @property + def cpuinfo_xml(self): + if not hasattr(self, '_cpuinfo_xml_cache_info'): + self._cpuinfo_xml_cache_info = {} + + return utils.read_cached_file(FLAGS.cpuinfo_xml_template, + self._cpuinfo_xml_cache_info) + def _get_connection(self): if not self._wrapped_conn or not self._test_connection(): LOG.debug(_('Connecting to libvirt: %s'), self.uri) -- cgit