You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/02/01 09:32:04 UTC

[GitHub] [cloudstack] sureshanaparti commented on a change in pull request #4591: server: select root disk based on user input during vm import

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



##########
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);
+                rootDisk = disk;
+            } else {
+                dataDisks.add(disk);
+            }
+        }
+        if (diskIdsWithoutOffering.size() > 1) {

Review comment:
       Ok got that @shwstppr 




----------------------------------------------------------------
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:
users@infra.apache.org