@Override public boolean isAttachedVM() { return (volumeVO.getInstanceId() == null) ? false : true; }
@Override public Long getInstanceId() { return volumeVO.getInstanceId(); }
@Override public VirtualMachine getAttachedVM() { Long vmId = volumeVO.getInstanceId(); if (vmId != null) { VMInstanceVO vm = vmInstanceDao.findById(vmId); return vm; } return null; } @Override
private void checkForUnattachedVolumes(long vmId, List<VolumeVO> volumes) { StringBuilder sb = new StringBuilder(); for (VolumeVO volume : volumes) { if (volume.getInstanceId() == null || vmId != volume.getInstanceId()) { sb.append(volume.toString() + "; "); } } if (!StringUtils.isEmpty(sb.toString())) { throw new InvalidParameterValueException("The following supplied volumes are not attached to the VM: " + sb.toString()); } }
private void detachVolumesFromVm(List<VolumeVO> volumes) { for (VolumeVO volume : volumes) { Volume detachResult = _volumeService.detachVolumeViaDestroyVM(volume.getInstanceId(), volume.getId()); if (detachResult == null) { s_logger.error("DestroyVM remove volume - failed to detach and delete volume " + volume.getInstanceId() + " from instance " + volume.getId()); } } }
@Override public String getAttachedVmName() { Long vmId = volumeVO.getInstanceId(); if (vmId != null) { VMInstanceVO vm = vmInstanceDao.findById(vmId); if (vm == null) { return null; } return vm.getInstanceName(); } return null; }
private void deleteVolumesFromVm(List<VolumeVO> volumes) { for (VolumeVO volume : volumes) { boolean deleteResult = _volumeService.deleteVolume(volume.getId(), CallContext.current().getCallingAccount()); if (!deleteResult) { s_logger.error("DestroyVM remove volume - failed to delete volume " + volume.getInstanceId() + " from instance " + volume.getId()); } } } }
private List<Map<String, String>> getTargets(long clusterId, long storagePoolId) { List<Map<String, String>> targets = new ArrayList<>(); StoragePoolVO storagePool = storagePoolDao.findById(storagePoolId); // If you do not pass in null for the second parameter, you only get back applicable ROOT disks. List<VolumeVO> volumes = volumeDao.findByPoolId(storagePoolId, null); if (volumes != null) { for (VolumeVO volume : volumes) { Long instanceId = volume.getInstanceId(); if (instanceId != null) { VMInstanceVO vmInstance = vmDao.findById(instanceId); Long hostIdForVm = vmInstance.getHostId() != null ? vmInstance.getHostId() : vmInstance.getLastHostId(); if (hostIdForVm != null) { HostVO hostForVm = hostDao.findById(hostIdForVm); if (hostForVm.getClusterId().equals(clusterId)) { Map<String, String> details = new HashMap<>(); details.put(ModifyTargetsCommand.IQN, volume.get_iScsiName()); details.put(ModifyTargetsCommand.STORAGE_HOST, storagePool.getHostAddress()); details.put(ModifyTargetsCommand.STORAGE_PORT, String.valueOf(storagePool.getPort())); targets.add(details); } } } } } return targets; }
private List<String> getStoragePaths(long clusterId, long storagePoolId) { List<String> storagePaths = new ArrayList<>(); // If you do not pass in null for the second parameter, you only get back applicable ROOT disks. List<VolumeVO> volumes = volumeDao.findByPoolId(storagePoolId, null); if (volumes != null) { for (VolumeVO volume : volumes) { Long instanceId = volume.getInstanceId(); if (instanceId != null) { VMInstanceVO vmInstance = vmDao.findById(instanceId); Long hostIdForVm = vmInstance.getHostId() != null ? vmInstance.getHostId() : vmInstance.getLastHostId(); if (hostIdForVm != null) { HostVO hostForVm = hostDao.findById(hostIdForVm); if (hostForVm != null && hostForVm.getClusterId().equals(clusterId)) { storagePaths.add(volume.get_iScsiName()); } } } } } return storagePaths; }
private HostVO getHost(long volumeId) { VolumeVO volumeVO = volumeDao.findById(volumeId); Long vmInstanceId = volumeVO.getInstanceId(); VMInstanceVO vmInstanceVO = vmInstanceDao.findById(vmInstanceId); Long hostId = null; // if the volume to snapshot is associated with a VM if (vmInstanceVO != null) { hostId = vmInstanceVO.getHostId(); // if the VM is not associated with a host if (hostId == null) { hostId = vmInstanceVO.getLastHostId(); } } return getHost(volumeVO.getDataCenterId(), hostId); }
final Long instanceId = volume.getInstanceId(); VMInstanceVO vm = null; if (instanceId != null) {
Long instanceId = volume.getInstanceId();
Long instanceId = volume.getInstanceId();
@Override @DB public boolean updateUuid(long srcVolId, long destVolId) { TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); try { VolumeVO srcVol = findById(srcVolId); VolumeVO destVol = findById(destVolId); String uuid = srcVol.getUuid(); Long instanceId = srcVol.getInstanceId(); srcVol.setUuid(null); destVol.setUuid(uuid); destVol.setInstanceId(instanceId); update(srcVolId, srcVol); update(destVolId, destVol); _tagsDao.updateResourceId(srcVolId, destVolId, ResourceObjectType.Volume); } catch (Exception e) { throw new CloudRuntimeException("Unable to persist the sequence number for this host"); } txn.commit(); return true; }
vmClusterId = hs.getClusterId(); } else if (storeForExistingStoreScope.getScopeType() == ScopeType.ZONE) { Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId(); if (hostId != null) { HostVO host = _hostDao.findById(hostId); Long hostId = _vmInstanceDao.findById(existingVolume.getInstanceId()).getHostId(); if (storeForNewStoreScope.getScopeId().equals(hostId)) { return false;
throw new InvalidParameterValueException("There are snapshot operations in progress on the volume, unable to delete it"); if (volume.getInstanceId() != null) { throw new InvalidParameterValueException("Please specify a volume that is not attached to any VM.");
volumeSearch.and("poolId", volumeSearch.entity().getPoolId(), SearchCriteria.Op.EQ); volumeSearch.and("state", volumeSearch.entity().getState(), SearchCriteria.Op.EQ); StoragePoolSearch.join("vmVolume", volumeSearch, volumeSearch.entity().getInstanceId(), StoragePoolSearch.entity().getId(), JoinBuilder.JoinType.INNER); StoragePoolSearch.done();
@Override public boolean isLocalStorageActiveOnHost(Long hostId) { List<StoragePoolHostVO> storagePoolHostRefs = _storagePoolHostDao.listByHostId(hostId); for (StoragePoolHostVO storagePoolHostRef : storagePoolHostRefs) { StoragePoolVO PrimaryDataStoreVO = _storagePoolDao.findById(storagePoolHostRef.getPoolId()); if (PrimaryDataStoreVO.getPoolType() == StoragePoolType.LVM || PrimaryDataStoreVO.getPoolType() == StoragePoolType.EXT) { SearchBuilder<VolumeVO> volumeSB = _volsDao.createSearchBuilder(); volumeSB.and("poolId", volumeSB.entity().getPoolId(), SearchCriteria.Op.EQ); volumeSB.and("removed", volumeSB.entity().getRemoved(), SearchCriteria.Op.NULL); volumeSB.and("state", volumeSB.entity().getState(), SearchCriteria.Op.NIN); SearchBuilder<VMInstanceVO> activeVmSB = _vmInstanceDao.createSearchBuilder(); activeVmSB.and("state", activeVmSB.entity().getState(), SearchCriteria.Op.IN); volumeSB.join("activeVmSB", activeVmSB, volumeSB.entity().getInstanceId(), activeVmSB.entity().getId(), JoinBuilder.JoinType.INNER); SearchCriteria<VolumeVO> volumeSC = volumeSB.create(); volumeSC.setParameters("poolId", PrimaryDataStoreVO.getId()); volumeSC.setParameters("state", Volume.State.Expunging, Volume.State.Destroy); volumeSC.setJoinParameters("activeVmSB", "state", State.Starting, State.Running, State.Stopping, State.Migrating); List<VolumeVO> volumes = _volsDao.search(volumeSC, null); if (volumes.size() > 0) { return true; } } } return false; }
if (volume.getVolumeType() == Volume.Type.ROOT && volume.getInstanceId() != null) { VMInstanceVO instance = ApiDBUtils.findVMInstanceById(volume.getInstanceId()); if (instance != null) { GuestOS guestOs = ApiDBUtils.findGuestOSById(instance.getGuestOSId());
volumeSearch.join("instanceVolumes", instanceSearch, instanceSearch.entity().getId(), volumeSearch.entity().getInstanceId(), JoinType.INNER);