Skip to content

Commit d365d95

Browse files
committed
check tags while fetching storage pool for importing vm
1 parent e666dca commit d365d95

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
@@ -534,7 +534,7 @@ private Map<String, Network.IpAddresses> getNicIpAddresses(final List<UnmanagedI
534534
return nicIpAddresses;
535535
}
536536

537-
private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final DataCenter zone, final Cluster cluster) {
537+
private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final DataCenter zone, final Cluster cluster, String diskOfferingTags) {
538538
StoragePool storagePool = null;
539539
final String dsHost = disk.getDatastoreHost();
540540
final String dsPath = disk.getDatastorePath();
@@ -544,7 +544,8 @@ private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final Da
544544
List<StoragePoolVO> pools = primaryDataStoreDao.listPoolByHostPath(dsHost, dsPath);
545545
for (StoragePool pool : pools) {
546546
if (pool.getDataCenterId() == zone.getId() &&
547-
(pool.getClusterId() == null || pool.getClusterId().equals(cluster.getId()))) {
547+
(pool.getClusterId() == null || pool.getClusterId().equals(cluster.getId())) &&
548+
volumeApiService.doesTargetStorageSupportDiskOffering(pool, diskOfferingTags)) {
548549
storagePool = pool;
549550
break;
550551
}
@@ -556,7 +557,8 @@ private StoragePool getStoragePool(final UnmanagedInstanceTO.Disk disk, final Da
556557
pools.addAll(primaryDataStoreDao.listByDataCenterId(zone.getId()));
557558
for (StoragePool pool : pools) {
558559
String searchPoolParam = StringUtils.isNotBlank(dsPath) ? dsPath : dsName;
559-
if (StringUtils.contains(pool.getPath(), searchPoolParam)) {
560+
if (StringUtils.contains(pool.getPath(), searchPoolParam) &&
561+
volumeApiService.doesTargetStorageSupportDiskOffering(pool, diskOfferingTags)) {
560562
storagePool = pool;
561563
break;
562564
}
@@ -619,7 +621,7 @@ private void checkUnmanagedDiskAndOfferingForImport(String instanceName, Unmanag
619621
if (diskOffering != null && !diskOffering.isCustomized() && diskOffering.getDiskSize() < disk.getCapacity()) {
620622
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))));
621623
}
622-
StoragePool storagePool = getStoragePool(disk, zone, cluster);
624+
StoragePool storagePool = getStoragePool(disk, zone, cluster, diskOffering != null ? diskOffering.getTags() : null);
623625
if (diskOffering != null && !migrateAllowed && !storagePoolSupportsDiskOffering(storagePool, diskOffering)) {
624626
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()));
625627
}
@@ -856,7 +858,7 @@ private Pair<DiskProfile, StoragePool> importDisk(UnmanagedInstanceTO.Disk disk,
856858
diskInfo.setDiskChain(new String[]{disk.getImagePath()});
857859
chainInfo = gson.toJson(diskInfo);
858860
}
859-
StoragePool storagePool = getStoragePool(disk, zone, cluster);
861+
StoragePool storagePool = getStoragePool(disk, zone, cluster, diskOffering != null ? diskOffering.getTags() : null);
860862
DiskProfile profile = volumeManager.importVolume(type, name, diskOffering, diskSize,
861863
minIops, maxIops, vm.getDataCenterId(), vm.getHypervisorType(), vm, template, owner, deviceId, storagePool.getId(), path, chainInfo);
862864

0 commit comments

Comments
 (0)