From f7e5dde6bbd70ee61924c8f556d0070c8ce0a4b2 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Wed, 31 Oct 2012 13:42:12 -0700 Subject: [PATCH] libvirt: Regenerates xml instead of using on-disk The libvirt.xml file is written on initial boot of the instance and may not reflect the current state of the vm if volumes have been attached. If the libvirt definition of the vm has been lost, it is safer to regenerate it rather than attempt to load it from the outdated file. This should properly bring back vms with attached volumes. Fixes bug 1073720 Change-Id: Iaa754700a149f09fc0c022fa664c06ad17f505f5 (cherry picked from commit b22c3302ccea6b4b9e685640accbfdbb2856d460) --- nova/virt/libvirt/driver.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 30cde650b96..04fec41281a 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -678,15 +678,13 @@ def _get_disk_xml(xml, device): if child.get('dev') == device: return etree.tostring(node) - def _get_domain_xml(self, instance): + def _get_domain_xml(self, instance, network_info, block_device_info=None): try: virt_dom = self._lookup_by_name(instance['name']) xml = virt_dom.XMLDesc(0) except exception.InstanceNotFound: - instance_dir = os.path.join(FLAGS.instances_path, - instance['name']) - xml_path = os.path.join(instance_dir, 'libvirt.xml') - xml = libvirt_utils.load_file(xml_path) + xml = self.to_xml(instance, network_info, + block_device_info=block_device_info) return xml @exception.wrap_exception() @@ -929,7 +927,8 @@ def _hard_reboot(self, instance, network_info, xml=None, """ if not xml: - xml = self._get_domain_xml(instance) + xml = self._get_domain_xml(instance, network_info, + block_device_info) self._destroy(instance) self._create_domain_and_network(xml, instance, network_info, @@ -988,7 +987,7 @@ def resume(self, instance): def resume_state_on_host_boot(self, context, instance, network_info, block_device_info=None): """resume guest state when a host is booted""" - xml = self._get_domain_xml(instance) + xml = self._get_domain_xml(instance, network_info, block_device_info) self._create_domain_and_network(xml, instance, network_info, block_device_info) @@ -1004,7 +1003,7 @@ def rescue(self, context, instance, network_info, image_meta, """ - unrescue_xml = self._get_domain_xml(instance) + unrescue_xml = self._get_domain_xml(instance, network_info) unrescue_xml_path = os.path.join(FLAGS.instances_path, instance['name'], 'unrescue.xml')