def _detach_vbd(self, vbd_ref, unplug=False): if unplug: vm_utils.unplug_vbd(self._session, vbd_ref) sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref) vm_utils.destroy_vbd(self._session, vbd_ref) # Forget SR only if not in use volume_utils.purge_sr(self._session, sr_ref)
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)
vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref, device_number) except volume_utils.StorageError, exc: LOG.exception(exc) raise Exception(_('Unable to locate volume %s') % mountpoint) try: vm_rec = self._session.call_xenapi("VM.get_record", vm_ref) sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref) if vm_rec['power_state'] != 'Halted': vm_utils.unplug_vbd(self._session, vbd_ref) except volume_utils.StorageError, exc: LOG.exception(exc) raise Exception(_('Unable to detach volume %s') % mountpoint) try: vm_utils.destroy_vbd(self._session, vbd_ref) except volume_utils.StorageError, exc: LOG.exception(exc) raise Exception(_('Unable to destroy vbd %s') % mountpoint) # Forget SR only if no other volumes on this host are using it try: volume_utils.purge_sr(self._session, sr_ref) except volume_utils.StorageError, exc: LOG.exception(exc) raise Exception(_('Error purging SR %s') % sr_ref) LOG.info( _('Mountpoint %(mountpoint)s detached from' ' instance %(instance_name)s') % locals())
% locals()) device_number = volume_utils.mountpoint_to_number(mountpoint) try: vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref, device_number) except volume_utils.StorageError, exc: LOG.exception(exc) raise Exception(_('Unable to locate volume %s') % mountpoint) try: sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref) vm_utils.unplug_vbd(self._session, vbd_ref) except volume_utils.StorageError, exc: LOG.exception(exc) raise Exception(_('Unable to detach volume %s') % mountpoint) try: vm_utils.destroy_vbd(self._session, vbd_ref) except volume_utils.StorageError, exc: LOG.exception(exc) raise Exception(_('Unable to destroy vbd %s') % mountpoint) # Forget SR only if no other volumes on this host are using it try: volume_utils.purge_sr(self._session, sr_ref) except volume_utils.StorageError, exc: LOG.exception(exc) raise Exception(_('Error purging SR %s') % sr_ref) LOG.info(_('Mountpoint %(mountpoint)s detached from' ' instance %(instance_name)s') % locals())