コード例 #1
0
        vm_ref = VMHelper.lookup(self._session, instance_name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance_name)
        # Detach VBD from VM
        LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s")
                % locals())
        device_number = VolumeHelper.mountpoint_to_number(mountpoint)
        try:
            vbd_ref = VMHelper.find_vbd_by_number(self._session,
                                                        vm_ref, device_number)
        except StorageError, exc:
            LOG.exception(exc)
            raise Exception(_('Unable to locate volume %s') % mountpoint)

        try:
            sr_ref = VolumeHelper.find_sr_from_vbd(self._session,
                                                    vbd_ref)
            VMHelper.unplug_vbd(self._session, vbd_ref)
        except StorageError, exc:
            LOG.exception(exc)
            raise Exception(_('Unable to detach volume %s') % mountpoint)
        try:
            VMHelper.destroy_vbd(self._session, vbd_ref)
        except 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:
            VolumeHelper.purge_sr(self._session, sr_ref)
        except StorageError, exc:
            LOG.exception(exc)
コード例 #2
0
ファイル: volumeops.py プロジェクト: wendy-king/x7_venv
        vm_ref = VMHelper.lookup(self._session, instance_name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance_name)
        # Detach VBD from VM
        LOG.debug(
            _("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())
        device_number = VolumeHelper.mountpoint_to_number(mountpoint)
        try:
            vbd_ref = VMHelper.find_vbd_by_number(self._session, vm_ref,
                                                  device_number)
        except StorageError, exc:
            LOG.exception(exc)
            raise Exception(_('Unable to locate volume %s') % mountpoint)

        try:
            sr_ref = VolumeHelper.find_sr_from_vbd(self._session, vbd_ref)
            VMHelper.unplug_vbd(self._session, vbd_ref)
        except StorageError, exc:
            LOG.exception(exc)
            raise Exception(_('Unable to detach volume %s') % mountpoint)
        try:
            VMHelper.destroy_vbd(self._session, vbd_ref)
        except 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:
            VolumeHelper.purge_sr(self._session, sr_ref)
        except StorageError, exc:
            LOG.exception(exc)