Skip to content

Commit

Permalink
libvirt: Regenerates xml instead of using on-disk
Browse files Browse the repository at this point in the history
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 b22c330)
  • Loading branch information
vishvananda committed Nov 22, 2012
1 parent 8d1095c commit f7e5dde
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions nova/virt/libvirt/driver.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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')
Expand Down

0 comments on commit f7e5dde

Please sign in to comment.