private DiskOfferingVO getDiskOfferingVO(Volume volume) { Long diskOfferingId = volume.getDiskOfferingId(); return _diskOfferingDao.findById(diskOfferingId); }
private DiskOfferingVO getDiskOfferingVO() { if (getDiskOfferingId() != null) { DiskOfferingVO diskOfferingVO = diskOfferingDao.findById(getDiskOfferingId()); return diskOfferingVO; } return null; }
private Pair<Boolean, Boolean> findVMStorageRequirements(VirtualMachineProfile vmProfile) { boolean requiresShared = false, requiresLocal = false; List<VolumeVO> volumesTobeCreated = _volsDao.findUsableVolumesForInstance(vmProfile.getId()); // for each volume find whether shared or local pool is required for (VolumeVO toBeCreated : volumesTobeCreated) { DiskOfferingVO diskOffering = _diskOfferingDao.findById(toBeCreated.getDiskOfferingId()); if (diskOffering != null) { if (diskOffering.isUseLocalStorage()) { requiresLocal = true; } else { requiresShared = true; } } } return new Pair<Boolean, Boolean>(requiresShared, requiresLocal); }
throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk."); DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId); if (diskOffering == null) { throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
private boolean hasSuitablePoolsForVolume(final VolumeVO volume, final Host host, final VirtualMachineProfile vmProfile) { final DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType()); final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null); final ExcludeList avoid = new ExcludeList(); for (final StoragePoolAllocator allocator : _storagePoolAllocators) { final List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, 1); if (poolList != null && !poolList.isEmpty()) { return true; } } return false; }
private boolean isVMUsingLocalStorage(VMInstanceVO vm) { boolean usesLocalStorage = false; List<VolumeVO> volumes = _volsDao.findByInstance(vm.getId()); for (VolumeVO vol : volumes) { DiskOfferingVO diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId()); if (diskOffering.isUseLocalStorage()) { usesLocalStorage = true; break; } StoragePoolVO storagePool = _storagePoolDao.findById(vol.getPoolId()); if (storagePool.isLocal()) { usesLocalStorage = true; break; } } return usesLocalStorage; }
/** * Generates the volume path by appending the Volume UUID to the Libvirt destiny images path.</br> * Example: /var/lib/libvirt/images/f3d49ecc-870c-475a-89fa-fd0124420a9b */ @Override protected String generateDestPath(VirtualMachineTO vmTO, VolumeVO srcVolume, Host destHost, StoragePoolVO destStoragePool, VolumeInfo destVolumeInfo) { DiskOfferingVO diskOffering = _diskOfferingDao.findById(srcVolume.getDiskOfferingId()); DiskProfile diskProfile = new DiskProfile(destVolumeInfo, diskOffering, HypervisorType.KVM); String templateUuid = getTemplateUuid(destVolumeInfo.getTemplateId()); CreateCommand rootImageProvisioningCommand = new CreateCommand(diskProfile, templateUuid, destStoragePool, true); Answer rootImageProvisioningAnswer = _agentMgr.easySend(destHost.getId(), rootImageProvisioningCommand); if (rootImageProvisioningAnswer == null) { throw new CloudRuntimeException(String.format("Migration with storage of vm [%s] failed while provisioning root image", vmTO.getName())); } if (!rootImageProvisioningAnswer.getResult()) { throw new CloudRuntimeException(String.format("Unable to modify target volume on the host [host id:%s, name:%s]", destHost.getId(), destHost.getName())); } String libvirtDestImgsPath = null; if (rootImageProvisioningAnswer instanceof CreateAnswer) { libvirtDestImgsPath = ((CreateAnswer)rootImageProvisioningAnswer).getVolume().getName(); } // File.getAbsolutePath is used to keep the file separator as it should be and eliminate a verification to check if exists a file separator in the last character of libvirtDestImgsPath. return new File(libvirtDestImgsPath, destVolumeInfo.getUuid()).getAbsolutePath(); }
private void publishUsageEvent(String type, VMSnapshot vmSnapshot, UserVm userVm, VolumeObjectTO volumeTo) { VolumeVO volume = volumeDao.findById(volumeTo.getId()); Long diskOfferingId = volume.getDiskOfferingId(); Long offeringId = null; if (diskOfferingId != null) { DiskOfferingVO offering = diskOfferingDao.findById(diskOfferingId); if (offering != null && (offering.getType() == DiskOfferingVO.Type.Disk)) { offeringId = offering.getId(); } } UsageEventUtils.publishUsageEvent(type, vmSnapshot.getAccountId(), userVm.getDataCenterId(), userVm.getId(), vmSnapshot.getName(), offeringId, volume.getId(), // save volume's id into templateId field volumeTo.getSize(), VMSnapshot.class.getName(), vmSnapshot.getUuid()); }
_accountMgr.checkAccess(owner, _diskOfferingDao.findById(diskOfferingId));
/** * 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())); }
/** * We use {@link StoragePoolAllocator} objects to find storage pools connected to the targetHost where we would be able to allocate the given volume. */ protected List<StoragePool> getCandidateStoragePoolsToMigrateLocalVolume(VirtualMachineProfile profile, Host targetHost, Volume volume) { List<StoragePool> poolList = new ArrayList<>(); DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); DiskProfile diskProfile = new DiskProfile(volume, diskOffering, profile.getHypervisorType()); DataCenterDeployment plan = new DataCenterDeployment(targetHost.getDataCenterId(), targetHost.getPodId(), targetHost.getClusterId(), targetHost.getId(), null, null); ExcludeList avoid = new ExcludeList(); StoragePoolVO volumeStoragePool = _storagePoolDao.findById(volume.getPoolId()); if (volumeStoragePool.isLocal()) { diskProfile.setUseLocalStorage(true); } for (StoragePoolAllocator allocator : _storagePoolAllocators) { List<StoragePool> poolListFromAllocator = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL); if (CollectionUtils.isEmpty(poolListFromAllocator)) { continue; } for (StoragePool pool : poolListFromAllocator) { if (pool.isLocal() || isStorageCrossClusterMigration(targetHost, volumeStoragePool)) { poolList.add(pool); } } } return poolList; }
@ReflectionUse private Pair<JobInfo.Status, String> orchestrateMigrateVolume(VmWorkMigrateVolume work) throws Exception { VolumeVO volume = _volsDao.findById(work.getVolumeId()); StoragePoolVO targetStoragePool = _storagePoolDao.findById(work.getDestPoolId()); DiskOfferingVO newDiskOffering = _diskOfferingDao.findById(work.getNewDiskOfferingId()); Volume newVol = orchestrateMigrateVolume(volume, targetStoragePool, work.isLiveMigrate(), newDiskOffering); return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, _jobMgr.marshallResultObject(newVol.getId())); }
private void checkDestinationForTags(StoragePool destPool, VMInstanceVO vm) { List<VolumeVO> vols = _volsDao.findUsableVolumesForInstance(vm.getId()); // OfflineVmwareMigration: iterate over volumes // OfflineVmwareMigration: get disk offering List<String> storageTags = storageMgr.getStoragePoolTagList(destPool.getId()); for(Volume vol : vols) { DiskOfferingVO diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId()); List<String> volumeTags = StringUtils.csvTagsToList(diskOffering.getTags()); if(! matches(volumeTags, storageTags)) { String msg = String.format("destination pool '%s' with tags '%s', does not support the volume diskoffering for volume '%s' (tags: '%s') ", destPool.getName(), StringUtils.listToCsvTags(storageTags), vol.getName(), StringUtils.listToCsvTags(volumeTags) ); throw new CloudRuntimeException(msg); } } }
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId); if ((diskOffering == null) || diskOffering.getRemoved() != null || !DiskOfferingVO.Type.Disk.equals(diskOffering.getType())) { throw new InvalidParameterValueException("Please specify a valid disk offering.");
Long offeringId = null; if (diskOfferingId != null) { DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId); if (offering != null && (offering.getType() == DiskOfferingVO.Type.Disk)) { offeringId = offering.getId();
volume.setDiskOfferingId(diskOfferingId); DiskOfferingVO diskOfferingVO = _diskOfferingDao.findById(diskOfferingId);
final Long diskOfferingId = cmd.getId(); final DiskOfferingVO offering = _diskOfferingDao.findById(diskOfferingId);
DiskOfferingVO newROOTDiskOffering = _diskOfferingDao.findById(newServiceOffering.getId());