hsato03 commented on code in PR #8654:
URL: https://github.com/apache/cloudstack/pull/8654#discussion_r1558153714
##########
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:
Since there aren't many conditionals, I don't think it's necessary here.
##########
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:
Same as above.
--
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]