Skip to content

Commit 6556c98

Browse files
committed
check tags while fetching storage pool for importing vm
1 parent ed1b145 commit 6556c98

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ private Map<String, Network.IpAddresses> getNicIpAddresses(final List<UnmanagedI
536536
return nicIpAddresses;
537537
}
538538

539-
private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final DataCenter zone, final Cluster cluster) {
539+
private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final DataCenter zone, final Cluster cluster, String diskOfferingTags) {
540540
StoragePool storagePool = null;
541541
final String dsHost = disk.getDatastoreHost();
542542
final String dsPath = disk.getDatastorePath();
@@ -546,7 +546,8 @@ private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final Da
546546
List<StoragePoolVO> pools = primaryDataStoreDao.listPoolByHostPath(dsHost, dsPath);
547547
for (StoragePool pool : pools) {
548548
if (pool.getDataCenterId() == zone.getId() &&
549-
(pool.getClusterId() == null || pool.getClusterId().equals(cluster.getId()))) {
549+
(pool.getClusterId() == null || pool.getClusterId().equals(cluster.getId())) &&
550+
volumeApiService.doesTargetStorageSupportDiskOffering(pool, diskOfferingTags)) {
550551
storagePool = pool;
551552
break;
552553
}
@@ -558,7 +559,8 @@ private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final Da
558559
pools.addAll(primaryDataStoreDao.listByDataCenterId(zone.getId()));
559560
for (StoragePool pool : pools) {
560561
String searchPoolParam = StringUtils.isNotBlank(dsPath) ? dsPath : dsName;
561-
if (StringUtils.contains(pool.getPath(), searchPoolParam)) {
562+
if (StringUtils.contains(pool.getPath(), searchPoolParam) &&
563+
volumeApiService.doesTargetStorageSupportDiskOffering(pool, diskOfferingTags)) {
562564
storagePool = pool;
563565
break;
564566
}
@@ -621,7 +623,7 @@ private void checkUnmanagedDiskAndOfferingForImport(String instanceName, Unmanag
621623
if (diskOffering != null && !diskOffering.isCustomized() && diskOffering.getDiskSize() < disk.getCapacity()) {
622624
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Size of disk offering(ID: %s) %dGB is found less than the size of disk(ID: %s) %dGB during VM import", diskOffering.getUuid(), (diskOffering.getDiskSize() / Resource.ResourceType.bytesToGiB), disk.getDiskId(), (disk.getCapacity() / (Resource.ResourceType.bytesToGiB))));
623625
}
624-
StoragePool storagePool = getStoragePool(disk, zone, cluster);
626+
StoragePool storagePool = getStoragePool(disk, zone, cluster, diskOffering != null ? diskOffering.getTags() : null);
625627
if (diskOffering != null && !migrateAllowed && !storagePoolSupportsDiskOffering(storagePool, diskOffering)) {
626628
throw new InvalidParameterValueException(String.format("Disk offering: %s is not compatible with storage pool: %s of unmanaged disk: %s", diskOffering.getUuid(), storagePool.getUuid(), disk.getDiskId()));
627629
}
@@ -858,7 +860,7 @@ private Pair<DiskProfile, StoragePool> importDisk(UnmanagedInstanceTO.Disk disk,
858860
diskInfo.setDiskChain(new String[]{disk.getImagePath()});
859861
chainInfo = gson.toJson(diskInfo);
860862
}
861-
StoragePool storagePool = getStoragePool(disk, zone, cluster);
863+
StoragePool storagePool = getStoragePool(disk, zone, cluster, diskOffering != null ? diskOffering.getTags() : null);
862864
DiskProfile profile = volumeManager.importVolume(type, name, diskOffering, diskSize,
863865
minIops, maxIops, vm.getDataCenterId(), vm.getHypervisorType(), vm, template, owner, deviceId, storagePool.getId(), path, chainInfo);
864866

0 commit comments

Comments
 (0)