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
  • Loading branch information
vishvananda committed Nov 7, 2012
1 parent d8970d6 commit b22c330
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions nova/virt/libvirt/driver.py
Expand Up @@ -683,15 +683,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 @@ -941,7 +939,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 @@ -1000,7 +999,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 @@ -1016,7 +1015,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 b22c330

Please sign in to comment.