DaanHoogland commented on code in PR #8654:
URL: https://github.com/apache/cloudstack/pull/8654#discussion_r1565321833
##########
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:
sorry, to reopen @hsato03 , but for readability this and Wei's remarks still
makes sense.
--
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]