if (!Volume.State.Ready.equals(volume.getState())) { s_logger.info("Volume " + volume + " must be in ready state for migration."); return new Pair<List<? extends StoragePool>, List<? extends StoragePool>>(allPools, suitablePools);
private VMSnapshot orchestrateCreateVMSnapshot(Long vmId, Long vmSnapshotId, Boolean quiescevm) { UserVmVO userVm = _userVMDao.findById(vmId); if (userVm == null) { throw new InvalidParameterValueException("Create vm to snapshot failed due to vm: " + vmId + " is not found"); } List<VolumeVO> volumeVos = _volumeDao.findByInstanceAndType(vmId, Type.ROOT); if(volumeVos == null ||volumeVos.isEmpty()) { throw new CloudRuntimeException("Create vm to snapshot failed due to no root disk found"); } VolumeVO rootVolume = volumeVos.get(0); if(!rootVolume.getState().equals(Volume.State.Ready)) { throw new CloudRuntimeException("Create vm to snapshot failed due to vm: " + vmId + " has root disk in " + rootVolume.getState() + " state"); } VMSnapshotVO vmSnapshot = _vmSnapshotDao.findById(vmSnapshotId); if (vmSnapshot == null) { throw new CloudRuntimeException("VM snapshot id: " + vmSnapshotId + " can not be found"); } VMSnapshotOptions options = new VMSnapshotOptions(quiescevm); vmSnapshot.setOptions(options); try { VMSnapshotStrategy strategy = findVMSnapshotStrategy(vmSnapshot); VMSnapshot snapshot = strategy.takeVMSnapshot(vmSnapshot); return snapshot; } catch (Exception e) { s_logger.debug("Failed to create vm snapshot: " + vmSnapshotId, e); return null; } }
if (!volume.getState().equals(Volume.State.Destroy)) { try { volumeService.deleteVolume(volume.getId(), caller);
if ( !Volume.State.Allocated.equals(root.getState()) || newTemplateId != null ){ Long templateId = root.getTemplateId(); boolean isISO = false;
if (exstingVolumeOfVm != null && !exstingVolumeOfVm.getState().equals(Volume.State.Allocated)) { destPrimaryStorage = _storagePoolDao.findById(exstingVolumeOfVm.getPoolId());
private void handleManagedStorage(UserVmVO vm, VolumeVO root) { if (Volume.State.Allocated.equals(root.getState())) { return;
private synchronized void checkAndSetAttaching(Long volumeId, Long hostId) { VolumeInfo volumeToAttach = volFactory.getVolume(volumeId); if (volumeToAttach.isAttachedVM()) { throw new CloudRuntimeException("volume: " + volumeToAttach.getName() + " is already attached to a VM: " + volumeToAttach.getAttachedVmName()); } if (volumeToAttach.getState().equals(Volume.State.Ready)) { volumeToAttach.stateTransit(Volume.Event.AttachRequested); } else { String error = null; if (hostId == null) { error = "Please try attach operation after starting VM once"; } else { error = "Volume: " + volumeToAttach.getName() + " is in " + volumeToAttach.getState() + ". It should be in Ready state"; } s_logger.error(error); throw new CloudRuntimeException(error); } }
private void cleanupVolumeDuringAttachFailure(Long volumeId, Long vmId) { VolumeVO volume = _volsDao.findById(volumeId); if (volume == null) { return; } if (volume.getState().equals(Volume.State.Creating)) { s_logger.debug("Remove volume: " + volume.getId() + ", as it's leftover from last mgt server stop"); _volsDao.remove(volume.getId()); } if (volume.getState().equals(Volume.State.Attaching)) { s_logger.warn("Vol: " + volume.getName() + " failed to attach to VM: " + _userVmDao.findById(vmId).getHostName() + " on last mgt server stop, changing state back to Ready"); volume.setState(Volume.State.Ready); _volsDao.update(volumeId, volume); } }
@Override public long getUsedIops(StoragePool storagePool) { long usedIops = 0; List<VolumeVO> volumes = volumeDao.findByPoolId(storagePool.getId(), null); if (volumes != null) { for (VolumeVO volume : volumes) { if (!Volume.State.Creating.equals(volume.getState())) { usedIops += volume.getMinIops() != null ? volume.getMinIops() : 0; } } } return usedIops; }