shwstppr commented on a change in pull request #4591:
URL: https://github.com/apache/cloudstack/pull/4591#discussion_r564507970



##########
File path: 
server/src/main/java/org/apache/cloudstack/vm/VmImportManagerImpl.java
##########
@@ -500,6 +500,35 @@ private StoragePool getStoragePool(final 
UnmanagedInstanceTO.Disk disk, final Da
         return storagePool;
     }
 
+    private Pair<UnmanagedInstanceTO.Disk, List<UnmanagedInstanceTO.Disk>> 
getRootAndDataDisks(List<UnmanagedInstanceTO.Disk> disks, final Map<String, 
Long> dataDiskOfferingMap) {
+        UnmanagedInstanceTO.Disk rootDisk = null;
+        List<UnmanagedInstanceTO.Disk> dataDisks = new ArrayList<>();
+        if (disks.size() == 1) {
+            rootDisk = disks.get(0);
+            return new Pair<>(rootDisk, dataDisks);
+        }
+        Set<String> callerDiskIds = dataDiskOfferingMap.keySet();
+        if (callerDiskIds.size() != disks.size() - 1) {
+            String msg = String.format("VM has total %d disks for which %d 
disk offering mappings provided. %d disks need a disk offering for import", 
disks.size(), callerDiskIds.size(), disks.size()-1);
+            LOGGER.error(String.format("%s. %s parameter can be used to 
provide disk offerings for the disks", msg, 
ApiConstants.DATADISK_OFFERING_LIST));
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, msg);
+        }
+        List<String> diskIdsWithoutOffering = new ArrayList<>();
+        for (UnmanagedInstanceTO.Disk disk : disks) {
+            String diskId = disk.getDiskId();
+            if (!callerDiskIds.contains(diskId)) {
+                diskIdsWithoutOffering.add(diskId);

Review comment:
       Same as above




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to