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)
def safe_cleanup_from_vdis(self, vdi_refs): # A helper method to detach volumes that are not associated with an # instance for vdi_ref in vdi_refs: try: sr_ref = volume_utils.find_sr_from_vdi(self._session, vdi_ref) except exception.StorageError as exc: LOG.debug(exc.format_message()) continue try: # Forget (i.e. disconnect) SR only if not in use volume_utils.purge_sr(self._session, sr_ref) except Exception: LOG.debug('Ignoring error while purging sr: %s' % sr_ref, exc_info=True)