def detach_volume(self, connection_info, instance_name, mountpoint): """Detach volume storage to VM instance.""" LOG.debug( _("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals()) device_number = volume_utils.get_device_number(mountpoint) vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name) try: vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref, device_number) except volume_utils.StorageError: # NOTE(sirp): If we don't find the VBD then it must have been # detached previously. LOG.warn( _('Skipping detach because VBD for %(instance_name)s was' ' not found') % locals()) return # Unplug VBD if we're NOT shutdown unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref) self._detach_vbd(vbd_ref, unplug=unplug) LOG.info( _('Mountpoint %(mountpoint)s detached from instance' ' %(instance_name)s') % locals())
def detach_all(self, vm_ref): """Detach any external nova/cinder volumes and purge the SRs.""" # Generally speaking, detach_all will be called with VM already # shutdown; however if it's still running, we can still perform the # operation by unplugging the VBD first. unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref) vbd_refs = self._get_all_volume_vbd_refs(vm_ref) for vbd_ref in vbd_refs: self._detach_vbd(vbd_ref, unplug=unplug)
def detach_volume(self, connection_info, instance_name, mountpoint): """Detach volume storage to VM instance.""" LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals()) device_number = volume_utils.get_device_number(mountpoint) vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name) vbd_ref = vm_utils.find_vbd_by_number( self._session, vm_ref, device_number) # Unplug VBD if we're NOT shutdown unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref) self._detach_vbd(vbd_ref, unplug=unplug) LOG.info(_('Mountpoint %(mountpoint)s detached from instance' ' %(instance_name)s') % locals())
def detach_volume(self, connection_info, instance_name, mountpoint): """Detach volume storage to VM instance.""" LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals()) device_number = volume_utils.get_device_number(mountpoint) vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name) try: vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref, device_number) except volume_utils.StorageError: # NOTE(sirp): If we don't find the VBD then it must have been # detached previously. LOG.warn(_("Skipping detach because VBD for %(instance_name)s was" " not found") % locals()) return # Unplug VBD if we're NOT shutdown unplug = not vm_utils._is_vm_shutdown(self._session, vm_ref) self._detach_vbd(vbd_ref, unplug=unplug) LOG.info(_("Mountpoint %(mountpoint)s detached from instance" " %(instance_name)s") % locals())
vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name) # Detach VBD from VM LOG.debug( _("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals()) device_number = volume_utils.get_device_number(mountpoint) try: vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref, device_number) sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref) except volume_utils.StorageError, exc: LOG.exception(exc) raise Exception(_('Unable to locate volume %s') % mountpoint) try: if not vm_utils._is_vm_shutdown(self._session, vm_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)
vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name) # Detach VBD from VM LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals()) device_number = volume_utils.get_device_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: if not vm_utils._is_vm_shutdown(self._session, vm_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: sr_ref = volume_utils.find_sr_from_vbd(self._session, vbd_ref) volume_utils.purge_sr(self._session, sr_ref) except volume_utils.StorageError, exc: