volume = createVolumeFromSnapshot(volume, cmd.getSnapshotId(), cmd.getVirtualMachineId()); if (volume.getState() != Volume.State.Ready) { created = false; attachVolumeToVM(cmd.getVirtualMachineId(), volume.getId(), volume.getDeviceId()); } catch (Exception ex) { StringBuilder message = new StringBuilder("Volume: ");
@DB @Override @ActionEvent(eventType = EventTypes.EVENT_VOLUME_DELETE, eventDescription = "deleting volume") /** * Executes the removal of the volume. If the volume is only allocated we do not try to remove it from primary and secondary storage. * Otherwise, after the removal in the database, we will try to remove the volume from both primary and secondary storage. */ public boolean deleteVolume(long volumeId, Account caller) throws ConcurrentOperationException { VolumeVO volume = retrieveAndValidateVolume(volumeId, caller); try { destroyVolumeIfPossible(volume); // Mark volume as removed if volume has not been created on primary or secondary if (volume.getState() == Volume.State.Allocated) { _volsDao.remove(volumeId); stateTransitTo(volume, Volume.Event.DestroyRequested); return true; } expungeVolumesInPrimaryStorageIfNeeded(volume); expungeVolumesInSecondaryStorageIfNeeded(volume); cleanVolumesCache(volume); return true; } catch (InterruptedException | ExecutionException | NoTransitionException e) { s_logger.warn("Failed to expunge volume: " + volume.getUuid(), e); return false; } }
return doesTargetStorageSupportDiskOffering(destPool, targetStoreTags);
throw new CloudRuntimeException("volume '" + vol.getUuid() +"', has no diskoffering. Migration target cannot be checked."); if(! doesTargetStorageSupportDiskOffering(destPool, diskOffering)) { throw new CloudRuntimeException("Migration target has no matching tags for volume '" +vol.getName() + "(" + vol.getUuid() + ")'"); updateMissingRootDiskController(vm, vol.getChainInfo()); DiskOfferingVO newDiskOffering = retrieveAndValidateNewDiskOffering(cmd); validateConditionsToReplaceDiskOfferingOfVolume(vol, newDiskOffering, destPool); if (vm != null) { placeHolder = createPlaceHolderWork(vm.getId()); try { return orchestrateMigrateVolume(vol, destPool, liveMigrateVolume, newDiskOffering); } finally { _workJobDao.expunge(placeHolder.getId()); Outcome<Volume> outcome = migrateVolumeThroughJobQueue(vm, vol, destPool, liveMigrateVolume, newDiskOffering); return orchestrateMigrateVolume(vol, destPool, liveMigrateVolume, newDiskOffering);
validateRootVolumeDetachAttach(_volsDao.findById(volumeToAttach.getId()), vm); int maxAttachableDataVolumesSupported = getMaxDataVolumesSupported(vm); if (existingDataVolumes.size() >= maxAttachableDataVolumesSupported) { throw new InvalidParameterValueException( placeHolder = createPlaceHolderWork(vmId); try { return orchestrateAttachVolumeToVM(vmId, volumeId, deviceId); } finally { _workJobDao.expunge(placeHolder.getId()); Outcome<Volume> outcome = attachVolumeToVmThroughJobQueue(vmId, volumeId, deviceId);
validateIops(newMinIops, newMaxIops); } else { if (newDiskOffering.getRemoved() != null) { newMaxIops = cmd.getMaxIops() != null ? cmd.getMaxIops() : volume.getMaxIops(); validateIops(newMinIops, newMaxIops); } else { newMinIops = newDiskOffering.getMinIops(); if (!validateVolumeSizeRange(newSize)) { throw new InvalidParameterValueException("Requested size out of range"); placeHolder = createPlaceHolderWork(userVm.getId()); return orchestrateResizeVolume(volume.getId(), currentSize, newSize, newMinIops, newMaxIops, newHypervisorSnapshotReserve, newDiskOffering != null ? cmd.getNewDiskOfferingId() : null, shrinkOk); } finally { Outcome<Volume> outcome = resizeVolumeThroughJobQueue(userVm.getId(), volume.getId(), currentSize, newSize, newMinIops, newMaxIops, newHypervisorSnapshotReserve, newDiskOffering != null ? cmd.getNewDiskOfferingId() : null, shrinkOk); return orchestrateResizeVolume(volume.getId(), currentSize, newSize, newMinIops, newMaxIops, newHypervisorSnapshotReserve, newDiskOffering != null ? cmd.getNewDiskOfferingId() : null, shrinkOk);
validateRootVolumeDetachAttach(volume, vm); placeHolder = createPlaceHolderWork(vmId); try { return orchestrateDetachVolumeFromVM(vmId, volumeId); } finally { _workJobDao.expunge(placeHolder.getId()); Outcome<Volume> outcome = detachVolumeFromVmThroughJobQueue(vmId, volumeId);
placeHolder = createPlaceHolderWork(vm.getId()); try { return orchestrateTakeVolumeSnapshot(volumeId, policyId, snapshotId, account, quiescevm, locationType, asyncBackup); } finally { _workJobDao.expunge(placeHolder.getId()); Outcome<Snapshot> outcome = takeVolumeSnapshotThroughJobQueue(vm.getId(), volumeId, policyId, snapshotId, account.getId(), quiescevm, locationType, asyncBackup);
placeHolder = createPlaceHolderWork(vm.getId()); try { return orchestrateExtractVolume(volume.getId(), zoneId); } finally { _workJobDao.expunge(placeHolder.getId()); Outcome<String> outcome = extractVolumeThroughJobQueue(vm.getId(), volume.getId(), zoneId); return orchestrateExtractVolume(volume.getId(), zoneId);
verifyManagedStorage(volumeToAttachStoragePool.getId(), hostId); checkAndSetAttaching(volumeToAttach.getId(), hostId); deviceId = getDeviceId(vm, deviceId); deviceId = getDeviceId(vm, deviceId);
if (!validateVolumeSizeRange(size)) {// convert size from mb to gb String userSpecifiedName = getVolumeNameFromCommand(cmd); VolumeVO volume = commitVolume(cmd, caller, owner, displayVolume, zoneId, diskOfferingId, provisioningType, size, minIops, maxIops, parentVolume, userSpecifiedName, _uuidMgr.generateUuid(Volume.class, cmd.getCustomId()));
/** * Performs the validations required for replacing the disk offering while migrating the volume of storage. If no new disk offering is provided, we do not execute any validation. * If a disk offering is informed, we then proceed with the following checks. * <ul> * <li>We check if the given volume is of ROOT type. We cannot change the disk offering of a ROOT volume. Therefore, we thrown an {@link InvalidParameterValueException}; * <li>We the disk is being migrated to shared storage and the new disk offering is for local storage (or vice versa), we throw an {@link InvalidParameterValueException}. Bear in mind that we are validating only the new disk offering. If none is provided we can override the current disk offering. This means, placing a volume with shared disk offering in local storage and vice versa; * <li>We then proceed checking the target storage pool supports the new disk offering {@link #doesTargetStorageSupportNewDiskOffering(StoragePool, DiskOfferingVO)}. * </ul> * * If all of the above validations pass, we check if the size of the new disk offering is different from the volume. If it is, we log a warning message. */ protected void validateConditionsToReplaceDiskOfferingOfVolume(VolumeVO volume, DiskOfferingVO newDiskOffering, StoragePool destPool) { if (newDiskOffering == null) { return; } if ((destPool.isShared() && newDiskOffering.isUseLocalStorage()) || destPool.isLocal() && newDiskOffering.isShared()) { throw new InvalidParameterValueException("You cannot move the volume to a shared storage and assing a disk offering for local storage and vice versa."); } if (!doesTargetStorageSupportDiskOffering(destPool, newDiskOffering)) { throw new InvalidParameterValueException(String.format("Target Storage [id=%s] tags [%s] does not match new disk offering [id=%s] tags [%s].", destPool.getUuid(), getStoragePoolTags(destPool), newDiskOffering.getUuid(), newDiskOffering.getTags())); } if (volume.getSize() != newDiskOffering.getDiskSize()) { DiskOfferingVO oldDiskOffering = this._diskOfferingDao.findById(volume.getDiskOfferingId()); s_logger.warn(String.format( "You are migrating a volume [id=%s] and changing the disk offering[from id=%s to id=%s] to reflect this migration. However, the sizes of the volume and the new disk offering are different.", volume.getUuid(), oldDiskOffering.getUuid(), newDiskOffering.getUuid())); } s_logger.info(String.format("Changing disk offering to [uuid=%s] while migrating volume [uuid=%s, name=%s].", newDiskOffering.getUuid(), volume.getUuid(), volume.getName())); }
@Override @ActionEvent(eventType = EventTypes.EVENT_VOLUME_ATTACH, eventDescription = "attaching volume", async = true) public Volume attachVolumeToVM(AttachVolumeCmd command) { return attachVolumeToVM(command.getVirtualMachineId(), command.getId(), command.getDeviceId()); }