winterhazel commented on code in PR #12884:
URL: https://github.com/apache/cloudstack/pull/12884#discussion_r2992092982


##########
server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java:
##########
@@ -2728,6 +2766,41 @@ private UserVm importKvmVirtualMachineFromDisk(final 
ImportSource importSource,
         }
     }
 
+    private void checkVmResourceLimitsForExternalKvmVmImport(Account owner, 
ServiceOfferingVO serviceOffering, VMTemplateVO template, Map<String, String> 
details, List<Reserver> reservations) throws ResourceAllocationException {
+        // When importing an external VM, the amount of CPUs and memory is 
always obtained from the compute offering,
+        // unlike the unmanaged instance import that obtains it from the 
hypervisor unless the VM is powered off and the offering is fixed
+        Integer cpu = serviceOffering.getCpu();
+        Integer memory = serviceOffering.getRamSize();
+
+        if (serviceOffering.isDynamic()) {
+            cpu = getDetailAsInteger(VmDetailConstants.CPU_NUMBER, details);
+            memory = getDetailAsInteger(VmDetailConstants.MEMORY, details);
+        }
+
+        List<String> resourceLimitHostTags = 
resourceLimitService.getResourceLimitHostTags(serviceOffering, template);
+
+        CheckedReservation vmReservation = new CheckedReservation(owner, 
Resource.ResourceType.user_vm, resourceLimitHostTags, 1L, reservationDao, 
resourceLimitService);
+        reservations.add(vmReservation);
+
+        CheckedReservation cpuReservation = new CheckedReservation(owner, 
Resource.ResourceType.cpu, resourceLimitHostTags, cpu.longValue(), 
reservationDao, resourceLimitService);
+        reservations.add(cpuReservation);
+
+        CheckedReservation memReservation = new CheckedReservation(owner, 
Resource.ResourceType.memory, resourceLimitHostTags, memory.longValue(), 
reservationDao, resourceLimitService);
+        reservations.add(memReservation);

Review Comment:
   Invalid suggestion. If either `getCpu()` or `getRamSize()` returns null, 
then `isDynamic()` will return `true`.



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to