def vbd_unplug_with_retry(session, vbd):
 while True:
  try:
   session.xenapi.VBD.unplug(vbd)
   logging.debug(_('VBD.unplug successful first time.'))
   return
  except XenAPI.Failure as e:
   if ((len(e.details) > 0) and (e.details[0] == 'DEVICE_DETACH_REJECTED')):
    logging.debug(_('VBD.unplug rejected: retrying...'))
    time.sleep(1)
   elif ((len(e.details) > 0) and (e.details[0] == 'DEVICE_ALREADY_DETACHED')):
    logging.debug(_('VBD.unplug successful eventually.'))
    return
   else:
    logging.error(_('Ignoring XenAPI.Failure in VBD.unplug: %s'), e)
    return

def vbd_unplug_with_retry ( session , vbd ) : while True : try : session . xenapi . VBD . unplug ( vbd ) logging . debug ( _ ( 'VBD.unplug successful first time.' ) ) return except XenAPI . Failure as e : if ( ( len ( e . details ) > 0 ) and ( e . details [ 0 ] == 'DEVICE_DETACH_REJECTED' ) ) : logging . debug ( _ ( 'VBD.unplug rejected: retrying...' ) ) time . sleep ( 1 ) elif ( ( len ( e . details ) > 0 ) and ( e . details [ 0 ] == 'DEVICE_ALREADY_DETACHED' ) ) : logging . debug ( _ ( 'VBD.unplug successful eventually.' ) ) return else : logging . error ( _ ( 'Ignoring XenAPI.Failure in VBD.unplug: %s' ) , e ) return
call vbd .