def find_bad_volumes(self, vm_ref): """Find any volumes with their connection severed. Certain VM operations (e.g. `VM.start`, `VM.reboot`, etc.) will not work when a VBD is present that points to a non-working volume. To work around this, we scan for non-working volumes and detach them before retrying a failed operation. """ bad_devices = [] vbd_refs = self._get_all_volume_vbd_refs(vm_ref) for vbd_ref in vbd_refs: sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref) try: # TODO(sirp): bug1152401 This relies on a 120 sec timeout # within XenServer, update this to fail-fast when this is fixed # upstream self._session.SR.scan(sr_ref) except self._session.XenAPI.Failure as exc: if exc.details[0] == 'SR_BACKEND_FAILURE_40': device = self._session.VBD.get_device(vbd_ref) bad_devices.append('/dev/%s' % device) else: raise return bad_devices
def _detach_vbds_and_srs(self, vm_ref, vbd_refs): is_vm_shutdown = vm_utils.is_vm_shutdown(self._session, vm_ref) for vbd_ref in vbd_refs: # find sr before we destroy the vbd sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref) if not is_vm_shutdown: vm_utils.unplug_vbd(self._session, vbd_ref, vm_ref) vm_utils.destroy_vbd(self._session, vbd_ref) # Forget (i.e. disconnect) SR only if not in use volume_utils.purge_sr(self._session, sr_ref)