private DiskOfferingVO getDiskOfferingVO(Volume volume) { Long diskOfferingId = volume.getDiskOfferingId(); return _diskOfferingDao.findById(diskOfferingId); }
public static DiskOfferingVO findDiskOfferingById(Long diskOfferingId) { DiskOfferingVO off = s_diskOfferingDao.findByIdIncludingRemoved(diskOfferingId); if (off.getType() == DiskOfferingVO.Type.Disk) { return off; } return null; }
/** * Retrieves the new disk offering UUID that might be sent to replace the current one in the volume being migrated. * If no disk offering UUID is provided we return null. Otherwise, we perform the following checks. * <ul> * <li>Is the disk offering UUID entered valid? If not, an {@link InvalidParameterValueException} is thrown; * <li>If the disk offering was already removed, we thrown an {@link InvalidParameterValueException} is thrown; * <li>We then check if the user executing the operation has access to the given disk offering. * </ul> * * If all checks pass, we move forward returning the disk offering object. */ private DiskOfferingVO retrieveAndValidateNewDiskOffering(MigrateVolumeCmd cmd) { String newDiskOfferingUuid = cmd.getNewDiskOfferingUuid(); if (org.apache.commons.lang.StringUtils.isBlank(newDiskOfferingUuid)) { return null; } DiskOfferingVO newDiskOffering = _diskOfferingDao.findByUuid(newDiskOfferingUuid); if (newDiskOffering == null) { throw new InvalidParameterValueException(String.format("The disk offering informed is not valid [id=%s].", newDiskOfferingUuid)); } if (newDiskOffering.getRemoved() != null) { throw new InvalidParameterValueException(String.format("We cannot assign a removed disk offering [id=%s] to a volume. ", newDiskOffering.getUuid())); } Account caller = CallContext.current().getCallingAccount(); _accountMgr.checkAccess(caller, newDiskOffering); return newDiskOffering; }
protected void cleanupDomainOfferings(Long domainId) { // delete the service and disk offerings associated with this domain List<DiskOfferingVO> diskOfferingsForThisDomain = _diskOfferingDao.listByDomainId(domainId); for (DiskOfferingVO diskOffering : diskOfferingsForThisDomain) { _diskOfferingDao.remove(diskOffering.getId()); } List<ServiceOfferingVO> serviceOfferingsForThisDomain = _offeringsDao.findServiceOfferingByDomainId(domainId); for (ServiceOfferingVO serviceOffering : serviceOfferingsForThisDomain) { _offeringsDao.remove(serviceOffering.getId()); } }
return _diskOfferingDao.findById(diskOfferingId); final DiskOfferingVO diskOffering = _diskOfferingDao.createForUpdate(diskOfferingId); if (_diskOfferingDao.update(diskOfferingId, diskOffering)) { CallContext.current().setEventDetails("Disk offering id=" + diskOffering.getId()); return _diskOfferingDao.findById(diskOfferingId); } else { return null;
DiskOfferingVO diskOfferingVO = _diskOfferingDao.findByUniqueName("Cloud.com-Custom"); if (diskOfferingVO != null) { long defaultDiskOfferingId = diskOfferingVO.getId(); volume.setDiskOfferingId(diskOfferingId); DiskOfferingVO diskOfferingVO = _diskOfferingDao.findById(diskOfferingId);
private DiskOfferingVO getDiskOfferingVO() { if (getDiskOfferingId() != null) { DiskOfferingVO diskOfferingVO = diskOfferingDao.findById(getDiskOfferingId()); return diskOfferingVO; } return null; }
DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId()); SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
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); }
DiskOfferingVO diskOffering = _diskOfferingDao.findByIdIncludingRemoved(volumeInfo.getDiskOfferingId()); SnapshotVO snapshot = _snapshotDao.findById(snapshotInfo.getId());
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; }
DiskOfferingVO diskOffering = _diskOfferingDao.findById(vm.getDiskOfferingId()); if (diskOffering == null) { throw new InvalidParameterValueException("Unable to find disk offering " + vm.getDiskOfferingId());
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; }