From 1abc121e34689b6bcef5d01c4b93da3264c0eed0 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 1 Nov 2023 14:38:50 +0530 Subject: [PATCH] vm-import: fix diskoffering checks for root disk Use disk offering linked with the service offering while checking for root disk during import Signed-off-by: Abhishek Kumar --- .../cloudstack/vm/UnmanagedVMsManagerImpl.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java index 79d8c7f457b0..8e7cea8790d0 100644 --- a/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java +++ b/server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java @@ -523,26 +523,24 @@ private Pair> getRootAn return new Pair<>(rootDisk, dataDisks); } - private void checkUnmanagedDiskAndOfferingForImport(UnmanagedInstanceTO.Disk disk, DiskOffering diskOffering, ServiceOffering serviceOffering, final Account owner, final DataCenter zone, final Cluster cluster, final boolean migrateAllowed) + private void checkUnmanagedDiskAndOfferingForImport(UnmanagedInstanceTO.Disk disk, DiskOffering diskOffering, final Account owner, final DataCenter zone, final Cluster cluster, final boolean migrateAllowed) throws ServerApiException, PermissionDeniedException, ResourceAllocationException { - if (serviceOffering == null && diskOffering == null) { + if (diskOffering == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Disk offering for disk ID: %s not found during VM import", disk.getDiskId())); } - if (diskOffering != null) { - accountService.checkAccess(owner, diskOffering, zone); - } + accountService.checkAccess(owner, diskOffering, zone); resourceLimitService.checkResourceLimit(owner, Resource.ResourceType.volume); if (disk.getCapacity() == null || disk.getCapacity() == 0) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Size of disk(ID: %s) is found invalid during VM import", disk.getDiskId())); } - if (diskOffering != null && !diskOffering.isCustomized() && diskOffering.getDiskSize() == 0) { + if (!diskOffering.isCustomized() && diskOffering.getDiskSize() == 0) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Size of fixed disk offering(ID: %s) is found invalid during VM import", diskOffering.getUuid())); } - if (diskOffering != null && !diskOffering.isCustomized() && diskOffering.getDiskSize() < disk.getCapacity()) { + if (!diskOffering.isCustomized() && diskOffering.getDiskSize() < disk.getCapacity()) { 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)))); } StoragePool storagePool = getStoragePool(disk, zone, cluster); - if (diskOffering != null && !migrateAllowed && !storagePoolSupportsDiskOffering(storagePool, diskOffering)) { + if (!migrateAllowed && !storagePoolSupportsDiskOffering(storagePool, diskOffering)) { 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())); } } @@ -564,7 +562,7 @@ private void checkUnmanagedDiskAndOfferingForImport(List