def get_vdi_for_vm_safely(session, vm_ref):
 vbd_refs = session.call_xenapi('VM.get_VBDs', vm_ref)
 for vbd in vbd_refs:
  vbd_rec = session.call_xenapi('VBD.get_record', vbd)
  if (vbd_rec['userdevice'] == '0'):
   vdi_rec = session.call_xenapi('VDI.get_record', vbd_rec['VDI'])
   return (vbd_rec['VDI'], vdi_rec)
 raise exception.NovaException((_('No primary VDI found for %(vm_ref)s') % locals()))

def get_vdi_for_vm_safely ( session , vm_ref ) : vbd_refs = session . call_xenapi ( 'VM.get_VBDs' , vm_ref ) for vbd in vbd_refs : vbd_rec = session . call_xenapi ( 'VBD.get_record' , vbd ) if ( vbd_rec [ 'userdevice' ] == '0' ) : vdi_rec = session . call_xenapi ( 'VDI.get_record' , vbd_rec [ 'VDI' ] ) return ( vbd_rec [ 'VDI' ] , vdi_rec ) raise exception . NovaException ( ( _ ( 'No primary VDI found for %(vm_ref)s' ) % locals ( ) ) )
retrieves the primary vdi for a vm .