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


##########
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)) {

Review Comment:
   use switch-case ?



##########
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);
+        }
+
+        return virtualMachineMaxNicsValue;
+    }
+
+    /**
+     * Searches the maximum virtual machine NICs based on the virtual machine 
hypervisor type.
+     *
+     * @param virtualMachine Virtual machine to get the hypervisor type.
+     * @return The maximum number of NICs that the virtual machine can have.
+     */
+    protected int 
getVirtualMachineMaxNicsValueFromVmHypervisorType(VirtualMachine 
virtualMachine) {
+        HypervisorType virtualMachineHypervisorType = 
virtualMachine.getHypervisorType();
+
+        if (HypervisorType.KVM.equals(virtualMachineHypervisorType)) {

Review Comment:
   also switch-case here ?



##########
server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java:
##########
@@ -1983,6 +1995,20 @@ public void doInTransactionWithoutResult(final 
TransactionStatus status) {
         });
     }
 
+    protected boolean existsVpcDomainRouterWithSufficientNicCapacity(long 
vpcId) {
+        int countRouterDefaultNics = 2;
+        long countVpcNetworks = _ntwkDao.countVpcNetworks(vpcId);
+        DomainRouterVO vpcDomainRouter = routerDao.findOneByVpcId(vpcId);
+
+        if (vpcDomainRouter == null) {
+            return false;
+        }
+
+        int totalNicsAvailable = 
networkOrchestrationService.getVirtualMachineMaxNicsValue(vpcDomainRouter) - 
countRouterDefaultNics;
+
+        return totalNicsAvailable > countVpcNetworks;
+    }

Review Comment:
   the nics for public networks in VPC VRs need to be considered as well.
   
   



##########
server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java:
##########
@@ -412,8 +416,7 @@ public void doInTransactionWithoutResult(final 
TransactionStatus status) {
         final String value = configs.get(Config.VpcCleanupInterval.key());
         _cleanupInterval = NumbersUtil.parseInt(value, 60 * 60); // 1 hour
 
-        final String maxNtwks = configs.get(Config.VpcMaxNetworks.key());
-        _maxNetworks = NumbersUtil.parseInt(maxNtwks, 3); // max=3 is default
+        _maxNetworks = VpcMaxNetworks.value();

Review Comment:
   is it needed any more ?



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