-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update vpc.max.networks setting & settings to limit the number of NICs for each hypervisor
#8654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hsato03
wants to merge
21
commits into
apache:main
Choose a base branch
from
scclouds:update-vpc.max.networks-setting-and-set-to-cluster-level
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5096a0b
Update vpc.max.networks setting
1b34e03
Change vpc.max.networks to account scope & create vm.max.nics settings
e0cddb7
Adjusts
e0e5801
Limit number of tiers
209dd67
Resolve conflicts
0c13784
Fix validation
10d58f0
Desconsider redundant routers in validation
88d92ee
Change query
63ab94a
Compare single VR
b9c4142
Refactor code
e86f28b
Remove unused import & improve VR NIC validation
5535203
Remove whitespaces
20877f3
Fix tests
aa4271b
Add integration tests
b9dd4da
Refactor
af3f0a8
Change tests file
b241a4c
Restore old tests file
bf70339
Resolve Conflicts
acde1d9
Resolve conflicts
7940a7c
Resolve conflicts
hsato03 f27804f
Fix tests
hsato03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -257,6 +257,7 @@ | |
| import com.cloud.vm.dao.UserVmDao; | ||
| import com.cloud.vm.dao.VMInstanceDao; | ||
| import com.googlecode.ipv6.IPv6Address; | ||
| import org.apache.commons.lang3.math.NumberUtils; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| /** | ||
|
|
@@ -1040,6 +1041,13 @@ public void saveExtraDhcpOptions(final String networkUuid, final Long nicId, fin | |
| public Pair<NicProfile, Integer> allocateNic(final NicProfile requested, final Network network, final Boolean isDefaultNic, int deviceId, final VirtualMachineProfile vm) | ||
| throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException { | ||
|
|
||
| int virtualMachineMaxNicsValue = getVirtualMachineMaxNicsValue(vm.getVirtualMachine()); | ||
| List<NicVO> nics = _nicDao.listByVmId(vm.getId()); | ||
|
|
||
| if (nics.size() >= virtualMachineMaxNicsValue) { | ||
| throw new CloudRuntimeException(String.format("Failed to allocate NIC on network [%s] because VM [%s] has reached its maximum NIC capacity [%s].", network.getUuid(), vm.getUuid(), virtualMachineMaxNicsValue)); | ||
| } | ||
|
|
||
| final NetworkVO ntwkVO = _networksDao.findById(network.getId()); | ||
| logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network + " with requested profile " + requested); | ||
| final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, ntwkVO.getGuruName()); | ||
|
|
@@ -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)) { | ||
weizhouapache marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| logger.debug("Using the {} setting global value {} as the VM {} has the {} hypervisor type and is not deployed on either a host or a cluster.", VirtualMachineMaxNicsKvm, VirtualMachineMaxNicsKvm.value(), virtualMachine.getUuid(), virtualMachineHypervisorType); | ||
| return VirtualMachineMaxNicsKvm.value(); | ||
| } else if (HypervisorType.VMware.equals(virtualMachineHypervisorType)) { | ||
| logger.debug("Using the {} setting global value {} as the VM {} has the {} hypervisor type and is not deployed on either a host or a cluster.", VirtualMachineMaxNicsVmware, VirtualMachineMaxNicsVmware.value(), virtualMachine.getUuid(), virtualMachineHypervisorType); | ||
| return VirtualMachineMaxNicsVmware.value(); | ||
| } | ||
|
|
||
| logger.debug("Using the {} setting global value {} as the VM {} has the {} hypervisor type and is not deployed on either a host or a cluster.", VirtualMachineMaxNicsXenserver, VirtualMachineMaxNicsXenserver.value(), virtualMachine.getUuid(), virtualMachineHypervisorType); | ||
| return VirtualMachineMaxNicsXenserver.value(); | ||
| } | ||
|
|
||
| private boolean isNicAllocatedForNsxPublicNetworkOnVR(Network network, NicProfile requested, VirtualMachineProfile vm) { | ||
| if (ObjectUtils.anyNull(network, requested, vm)) { | ||
| return false; | ||
|
|
@@ -4787,6 +4866,6 @@ public ConfigKey<?>[] getConfigKeys() { | |
| return new ConfigKey<?>[]{NetworkGcWait, NetworkGcInterval, NetworkLockTimeout, | ||
| GuestDomainSuffix, NetworkThrottlingRate, MinVRVersion, | ||
| PromiscuousMode, MacAddressChanges, ForgedTransmits, MacLearning, RollingRestartEnabled, | ||
| TUNGSTEN_ENABLED, NSX_ENABLED }; | ||
| TUNGSTEN_ENABLED, NSX_ENABLED, VirtualMachineMaxNicsKvm, VirtualMachineMaxNicsVmware, VirtualMachineMaxNicsXenserver }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.