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, 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.unplug on the given VBD, with a retry if we get
dataset/ETHPy150Open nii-cloud/dodai-compute/plugins/xenserver/xenapi/etc/xapi.d/plugins/pluginlib_nova.py/vbd_unplug_with_retry