def find_disk(virt_dom):
 xml_desc = virt_dom.XMLDesc(0)
 domain = etree.fromstring(xml_desc)
 os_type = domain.find('os/type').text
 driver = None
 if (CONF.libvirt.virt_type == 'lxc'):
  filesystem = domain.find('devices/filesystem')
  driver = filesystem.find('driver')
  source = filesystem.find('source')
  disk_path = source.get('dir')
  disk_path = disk_path[0:disk_path.rfind('rootfs')]
  disk_path = os.path.join(disk_path, 'disk')
 elif ((CONF.libvirt.virt_type == 'parallels') and (os_type == obj_fields.VMMode.EXE)):
  filesystem = domain.find('devices/filesystem')
  driver = filesystem.find('driver')
  source = filesystem.find('source')
  disk_path = source.get('file')
 else:
  disk = domain.find('devices/disk')
  driver = disk.find('driver')
  source = disk.find('source')
  disk_path = (source.get('file') or source.get('dev'))
  if ((not disk_path) and (CONF.libvirt.images_type == 'rbd')):
   disk_path = source.get('name')
   if disk_path:
    disk_path = ('rbd:' + disk_path)
 if (not disk_path):
  raise RuntimeError(_("Can't retrieve root device path from instance libvirt configuration"))
 if (driver is not None):
  format = driver.get('type')
  if (format == 'aio'):
   format = 'raw'
 else:
  format = None
 return (disk_path, format)

def find_disk ( virt_dom ) : xml_desc = virt_dom . XMLDesc ( 0 ) domain = etree . fromstring ( xml_desc ) os_type = domain . find ( 'os/type' ) . text driver = None if ( CONF . libvirt . virt_type == 'lxc' ) : filesystem = domain . find ( 'devices/filesystem' ) driver = filesystem . find ( 'driver' ) source = filesystem . find ( 'source' ) disk_path = source . get ( 'dir' ) disk_path = disk_path [ 0 : disk_path . rfind ( 'rootfs' ) ] disk_path = os . path . join ( disk_path , 'disk' ) elif ( ( CONF . libvirt . virt_type == 'parallels' ) and ( os_type == obj_fields . VMMode . EXE ) ) : filesystem = domain . find ( 'devices/filesystem' ) driver = filesystem . find ( 'driver' ) source = filesystem . find ( 'source' ) disk_path = source . get ( 'file' ) else : disk = domain . find ( 'devices/disk' ) driver = disk . find ( 'driver' ) source = disk . find ( 'source' ) disk_path = ( source . get ( 'file' ) or source . get ( 'dev' ) ) if ( ( not disk_path ) and ( CONF . libvirt . images_type == 'rbd' ) ) : disk_path = source . get ( 'name' ) if disk_path : disk_path = ( 'rbd:' + disk_path ) if ( not disk_path ) : raise RuntimeError ( _ ( "Can't retrieve root device path from instance libvirt configuration" ) ) if ( driver is not None ) : format = driver . get ( 'type' ) if ( format == 'aio' ) : format = 'raw' else : format = None return ( disk_path , format )
find root device path for instance may be file or device .