DaanHoogland commented on code in PR #8654:
URL: https://github.com/apache/cloudstack/pull/8654#discussion_r1551087739


##########
engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java:
##########
@@ -1090,6 +1098,77 @@ public Pair<NicProfile, Integer> allocateNic(final 
NicProfile requested, final N
         return new Pair<NicProfile, Integer>(vmNic, Integer.valueOf(deviceId));
     }
 
+    @Override
+    public int getVirtualMachineMaxNicsValue(VirtualMachine virtualMachine) {
+        Integer virtualMachineMaxNicsValue = 
getVirtualMachineMaxNicsValueFromCluster(virtualMachine);
+
+        if (virtualMachineMaxNicsValue != null) {
+            return virtualMachineMaxNicsValue;
+        }
+
+        if (virtualMachine.getHypervisorType() == null) {
+            logger.debug("Using the smallest setting global value between {}, 
{} and {} as the VM {} does not have a hypervisor type and is not deployed on 
either a host or a cluster.", VirtualMachineMaxNicsKvm, 
VirtualMachineMaxNicsVmware, VirtualMachineMaxNicsXenserver, 
virtualMachine.getUuid());
+            return NumberUtils.min(VirtualMachineMaxNicsKvm.value(), 
VirtualMachineMaxNicsVmware.value(), VirtualMachineMaxNicsXenserver.value());
+        }
+
+        return 
getVirtualMachineMaxNicsValueFromVmHypervisorType(virtualMachine);
+    }
+
+    /**
+     * Searches the maximum virtual machine NICs based on the hypervisor type 
of the cluster where the instance is deployed.
+     *
+     * @param virtualMachine Virtual machine to get the cluster.
+     * @return The maximum number of NICs that the virtual machine can have.
+     */
+    protected Integer getVirtualMachineMaxNicsValueFromCluster(VirtualMachine 
virtualMachine) {
+        HostVO host  = _hostDao.findById(virtualMachine.getHostId());
+        if (host == null) {
+            return null;
+        }
+
+        ClusterVO cluster = clusterDao.findById(host.getClusterId());
+        if (cluster == null) {
+            return null;
+        }
+
+        int virtualMachineMaxNicsValue;
+        HypervisorType hypervisor = cluster.getHypervisorType();
+
+        if (HypervisorType.KVM.equals(hypervisor)) {
+            virtualMachineMaxNicsValue = 
VirtualMachineMaxNicsKvm.valueIn(cluster.getId());
+            logger.debug("The cluster {} where the VM is deployed uses the {} 
hypervisor. Therefore, the {} setting value [{}] will be used.", 
cluster.getName(), hypervisor, VirtualMachineMaxNicsKvm, 
virtualMachineMaxNicsValue);
+        } else if (HypervisorType.VMware.equals(hypervisor)) {
+            virtualMachineMaxNicsValue = 
VirtualMachineMaxNicsVmware.valueIn(cluster.getId());
+            logger.debug("The cluster {} where the VM is deployed uses the {} 
hypervisor. Therefore, the {} setting value [{}] will be used.", 
cluster.getName(), hypervisor, VirtualMachineMaxNicsVmware, 
virtualMachineMaxNicsValue);
+        } else {
+            virtualMachineMaxNicsValue = 
VirtualMachineMaxNicsXenserver.valueIn(cluster.getId());
+            logger.debug("The cluster {} where the VM is deployed uses the {} 
hypervisor. Therefore, the {} setting value [{}] will be used.", 
cluster.getName(), hypervisor, VirtualMachineMaxNicsXenserver, 
virtualMachineMaxNicsValue);
+        }

Review Comment:
   can you extract this ?



##########
server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java:
##########
@@ -1930,16 +1933,25 @@ protected void validateNewVpcGuestNetwork(final String 
cidr, final String gatewa
         Transaction.execute(new TransactionCallbackNoReturn() {
             @Override
             public void doInTransactionWithoutResult(final TransactionStatus 
status) {

Review Comment:
   can you refactor this block to make it more readable? Or at least disect the 
new validation out, please.



-- 
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: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to