def cleanup_attached_vdis(session):
 this_vm_ref = _get_this_vm_ref(session)
 vbd_refs = session.call_xenapi('VM.get_VBDs', this_vm_ref)
 for vbd_ref in vbd_refs:
  try:
   vdi_ref = session.call_xenapi('VBD.get_VDI', vbd_ref)
   vdi_rec = session.call_xenapi('VDI.get_record', vdi_ref)
  except session.XenAPI.Failure as e:
   if (e.details[0] != 'HANDLE_INVALID'):
    raise
   continue
  if ('nova_instance_uuid' in vdi_rec['other_config']):
   LOG.info(_LI('Disconnecting stale VDI %s from compute domU'), vdi_rec['uuid'])
   unplug_vbd(session, vbd_ref, this_vm_ref)
   destroy_vbd(session, vbd_ref)

def cleanup_attached_vdis ( session ) : this_vm_ref = _get_this_vm_ref ( session ) vbd_refs = session . call_xenapi ( 'VM.get_VBDs' , this_vm_ref ) for vbd_ref in vbd_refs : try : vdi_ref = session . call_xenapi ( 'VBD.get_VDI' , vbd_ref ) vdi_rec = session . call_xenapi ( 'VDI.get_record' , vdi_ref ) except session . XenAPI . Failure as e : if ( e . details [ 0 ] != 'HANDLE_INVALID' ) : raise continue if ( 'nova_instance_uuid' in vdi_rec [ 'other_config' ] ) : LOG . info ( _LI ( 'Disconnecting stale VDI %s from compute domU' ) , vdi_rec [ 'uuid' ] ) unplug_vbd ( session , vbd_ref , this_vm_ref ) destroy_vbd ( session , vbd_ref )
unplug any instance vdis left after an unclean restart .