final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr(); primaryPool = storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid()); disksize = dskch.getSize(); vol = libvirtComputingResource.templateToPrimaryDownload(command.getTemplateUrl(), primaryPool, dskch.getPath()); } else { baseVol = primaryPool.getPhysicalDisk(command.getTemplateUrl()); vol = storagePoolMgr.createDiskFromTemplate(baseVol, dskch.getPath(), dskch.getProvisioningType(), primaryPool, baseVol.getSize(), 0); vol = primaryPool.createPhysicalDisk(dskch.getPath(), dskch.getProvisioningType(), dskch.getSize()); if (vol == null) { return new Answer(command, false, " Can't create Physical Disk"); final VolumeTO volume = new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), pool.getPath(), vol.getName(), vol.getName(), disksize, null); volume.setBytesReadRate(dskch.getBytesReadRate()); volume.setBytesWriteRate(dskch.getBytesWriteRate()); volume.setIopsReadRate(dskch.getIopsReadRate()); volume.setIopsWriteRate(dskch.getIopsWriteRate()); volume.setCacheMode(dskch.getCacheMode()); return new CreateAnswer(command, volume); } catch (final CloudRuntimeException e) {
if (clusterId != null) { ClusterVO cluster = clusterDao.findById(clusterId); if (!(cluster.getHypervisorType() == dskCh.getHypervisorType())) { if (s_logger.isDebugEnabled()) { s_logger.debug("StoragePool's Cluster does not have required hypervisorType, skipping this pool"); } else if (pool.getHypervisor() != null && !pool.getHypervisor().equals(HypervisorType.Any) && !(pool.getHypervisor() == dskCh.getHypervisorType())) { if (s_logger.isDebugEnabled()) { s_logger.debug("StoragePool does not have required hypervisorType, skipping this pool"); if(!checkHypervisorCompatibility(dskCh.getHypervisorType(), dskCh.getType(), pool.getPoolType())){ return false; Volume volume = volumeDao.findById(dskCh.getVolumeId()); List<Volume> requestVolumes = new ArrayList<>(); requestVolumes.add(volume);
LOGGER.debug("ZoneWideStoragePoolAllocator to find storage pool"); if (dskCh.useLocalStorage()) { return null; List<StoragePoolVO> storagePools = storagePoolDao.findZoneWideStoragePoolsByTags(plan.getDataCenterId(), dskCh.getTags()); if (storagePools == null) { storagePools = new ArrayList<>(); List<StoragePoolVO> storagePoolsByHypervisor = storagePoolDao.findZoneWideStoragePoolsByHypervisor(plan.getDataCenterId(), dskCh.getHypervisorType()); storagePools.retainAll(storagePoolsByHypervisor); storagePools.addAll(anyHypervisorStoragePools);
protected CreateAnswer execute(CreateCommand cmd) { StorageFilerTO primaryStorage = cmd.getPool(); DiskProfile disk = cmd.getDiskCharacteristics(); try { OvmVolume.Details vol = null; if (cmd.getTemplateUrl() != null) { vol = OvmVolume.createFromTemplate(_conn, primaryStorage.getUuid(), cmd.getTemplateUrl()); } else { vol = OvmVolume.createDataDsik(_conn, primaryStorage.getUuid(), Long.toString(disk.getSize()), disk.getType() == Volume.Type.ROOT); } VolumeTO volume = new VolumeTO(cmd.getVolumeId(), disk.getType(), primaryStorage.getType(), primaryStorage.getUuid(), primaryStorage.getPath(), vol.name, vol.path, vol.size, null); return new CreateAnswer(cmd, volume); } catch (Exception e) { s_logger.debug("CreateCommand failed", e); return new CreateAnswer(cmd, e.getMessage()); } }
vdi.setNameLabel(conn, dskch.getName()); } else { final VDI.Record vdir = new VDI.Record(); vdir.nameLabel = dskch.getName(); vdir.SR = poolSr; vdir.type = Types.VdiType.USER; vdir.virtualSize = dskch.getSize(); vdi = VDI.create(conn, vdir); new VolumeTO(command.getVolumeId(), dskch.getType(), pool.getType(), pool.getUuid(), vdir.nameLabel, pool.getPath(), vdir.uuid, vdir.virtualSize, null);
/** * 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; }
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; }
for (final VolumeVO volume : volumes) { final DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId()); final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType()); if (diskProfile.useLocalStorage()) { usesLocal = true; break;
@Override public VolumeInfo moveVolume(VolumeInfo volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId, HypervisorType dataDiskHyperType) throws ConcurrentOperationException, StorageUnavailableException { // Find a destination storage pool with the specified criteria DiskOffering diskOffering = _entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId()); DiskProfile dskCh = new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(), diskOffering.isUseLocalStorage(), diskOffering.isRecreatable(), null); dskCh.setHyperType(dataDiskHyperType); storageMgr.setDiskProfileThrottling(dskCh, null, diskOffering); DataCenter destPoolDataCenter = _entityMgr.findById(DataCenter.class, destPoolDcId); Pod destPoolPod = _entityMgr.findById(Pod.class, destPoolPodId); StoragePool destPool = findStoragePool(dskCh, destPoolDataCenter, destPoolPod, destPoolClusterId, null, null, new HashSet<StoragePool>()); if (destPool == null) { throw new CloudRuntimeException("Failed to find a storage pool with enough capacity to move the volume to."); } Volume newVol = migrateVolume(volume, destPool); return volFactory.getVolume(newVol.getId()); }
s_logger.debug("LocalStoragePoolAllocator trying to find storage pool to fit the vm"); if (!dskCh.useLocalStorage()) { return null; List<StoragePoolVO> hostTagsPools = storagePoolDao.findLocalStoragePoolsByHostAndTags(plan.getHostId(), dskCh.getTags()); for (StoragePoolVO pool : hostTagsPools) { if (pool != null && pool.isLocal()) { storagePoolDao.findLocalStoragePoolsByTags(plan.getDataCenterId(), plan.getPodId(), plan.getClusterId(), dskCh.getTags()); for (StoragePoolVO pool : availablePools) { if (suitablePools.size() == returnUpTo) {
/** * Construction for regular volumes. * @param diskCharacteristics * @param pool * @param executeInSequence TODO * @param vol * @param vm */ public CreateCommand(DiskProfile diskCharacteristics, StorageFilerTO pool, boolean executeInSequence) { this.volId = diskCharacteristics.getVolumeId(); this.diskCharacteristics = diskCharacteristics; this.pool = pool; this.templateUrl = null; this.executeInSequence = executeInSequence; }
@Override public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) { s_logger.debug("GarbageCollectingStoragePoolAllocator looking for storage pool"); if (!_storagePoolCleanupEnabled) { s_logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped."); return null; } // Clean up all storage pools storageMgr.cleanupStorage(false); // Determine what allocator to use StoragePoolAllocator allocator; if (dskCh.useLocalStorage()) { allocator = _localStoragePoolAllocator; } else { allocator = _firstFitStoragePoolAllocator; } // Try to find a storage pool after cleanup ExcludeList myAvoids = new ExcludeList(avoid.getDataCentersToAvoid(), avoid.getPodsToAvoid(), avoid.getClustersToAvoid(), avoid.getHostsToAvoid(), avoid.getPoolsToAvoid()); return allocator.allocateToPool(dskCh, vmProfile, plan, myAvoids, returnUpTo); }
DiskProfile diskProfile = new DiskProfile(volume, diskOffering, type); diskProfile.setUseLocalStorage(true);
/** * 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(); }
DiskProfile diskProfile = new DiskProfile(toBeCreated, diskOffering, vmProfile.getHypervisorType()); boolean useLocalStorage = false; if (vmProfile.getType() != VirtualMachine.Type.User) { diskProfile.setUseLocalStorage(useLocalStorage);
protected DiskProfile toDiskProfile(Volume vol, DiskOffering offering) { return new DiskProfile(vol.getId(), vol.getVolumeType(), vol.getName(), offering.getId(), vol.getSize(), offering.getTagsArray(), offering.isUseLocalStorage(), offering.isRecreatable(), vol.getTemplateId()); }
protected DiskProfile createDiskCharacteristics(VolumeInfo volume, VirtualMachineTemplate template, DataCenter dc, DiskOffering diskOffering) { if (volume.getVolumeType() == Type.ROOT && Storage.ImageFormat.ISO != template.getFormat()) { TemplateDataStoreVO ss = _vmTemplateStoreDao.findByTemplateZoneDownloadStatus(template.getId(), dc.getId(), VMTemplateStorageResourceAssoc.Status.DOWNLOADED); if (ss == null) { throw new CloudRuntimeException("Template " + template.getName() + " has not been completely downloaded to zone " + dc.getId()); } return new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), ss.getSize(), diskOffering.getTagsArray(), diskOffering.isUseLocalStorage(), diskOffering.isRecreatable(), Storage.ImageFormat.ISO != template.getFormat() ? template.getId() : null); } else { return new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(), diskOffering.isUseLocalStorage(), diskOffering.isRecreatable(), null); } }
DiskProfile dskCh = new DiskProfile(volume, diskOffering, snapshot.getHypervisorType());