Skip to content

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
wants to merge 19 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ jobs:
smoke/test_vpc_ipv6
smoke/test_vpc_redundant
smoke/test_vpc_router_nics
smoke/test_vpc_vpn",
smoke/test_vpc_vpn
smoke/test_vpc_hypervisor_max_networks",
"component/find_hosts_for_migration
component/test_acl_isolatednetwork
component/test_acl_isolatednetwork_delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ public interface NetworkOrchestrationService {

static final ConfigKey<Boolean> TUNGSTEN_ENABLED = new ConfigKey<>(Boolean.class, "tungsten.plugin.enable", "Advanced", "false",
"Indicates whether to enable the Tungsten plugin", false, ConfigKey.Scope.Zone, null);
ConfigKey<Integer> VirtualMachineMaxNicsKvm = new ConfigKey<>("Advanced", Integer.class, "virtual.machine.max.nics.kvm", "23",
"The maximum number of NICs supported by the KVM hypervsior.", true, Scope.Cluster);

ConfigKey<Integer> VirtualMachineMaxNicsVmware = new ConfigKey<>("Advanced", Integer.class, "virtual.machine.max.nics.vmware", "10",
"The maximum number of NICs supported by the VMware hypervsior.", true, Scope.Cluster);

ConfigKey<Integer> VirtualMachineMaxNicsXenserver = new ConfigKey<>("Advanced", Integer.class, "virtual.machine.max.nics.xenserver", "7",
"The maximum number of NICs supported by the XenServer hypervsior.", true, Scope.Cluster);

static final ConfigKey<Boolean> NSX_ENABLED = new ConfigKey<>(Boolean.class, "nsx.plugin.enable", "Advanced", "false",
"Indicates whether to enable the NSX plugin", false, ConfigKey.Scope.Zone, null);
Expand Down Expand Up @@ -352,5 +360,16 @@ void implementNetworkElementsAndResources(DeployDestination dest, ReservationCon

void unmanageNics(VirtualMachineProfile vm);

/**
* Returns the maximum number of NICs that the given virtual machine can have considering its hypervisor.
* <br/><br/>
* First we try to retrieve the setting value from the cluster where the virtual machine is deployed. If the cluster does not exist, we try to retrieve the setting value from the virtual machine hypervisor type.
* Returns null if the setting value could not be extracted.
*
* @param virtualMachine Virtual machine to get the maximum number of NICs.
* @return The maximum number of NICs that the virtual machine can have.
*/
Integer getVirtualMachineMaxNicsValue(VirtualMachine virtualMachine);

void expungeLbVmRefs(List<Long> vmIds, Long batchSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.cloud.utils.Pair;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.framework.config.ConfigKey;

import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
Expand All @@ -39,6 +40,9 @@
import com.cloud.user.Account;

public interface VpcManager {
ConfigKey<Integer> VpcMaxNetworks = new ConfigKey<>("Advanced", Integer.class, "vpc.max.networks", "3",
"Maximum number of networks per VPC.", true, ConfigKey.Scope.Account);

/**
* Returns all the Guest networks that are part of VPC
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,13 @@ private NicVO checkForRaceAndAllocateNic(final NicProfile requested, final Netwo
public Pair<NicProfile, Integer> allocateNic(final NicProfile requested, final Network network, final Boolean isDefaultNic, int deviceId, final VirtualMachineProfile vm)
throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {

Integer virtualMachineMaxNicsValue = getVirtualMachineMaxNicsValue(vm.getVirtualMachine());
List<NicVO> nics = _nicDao.listByVmId(vm.getId());

if (virtualMachineMaxNicsValue != null && 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));
}

if (requested != null && requested.getMode() == null) {
requested.setMode(network.getMode());
}
Expand All @@ -1148,6 +1155,91 @@ public Pair<NicProfile, Integer> allocateNic(final NicProfile requested, final N
return new Pair<NicProfile, Integer>(vmNic, Integer.valueOf(deviceId));
}

@Override
public Integer getVirtualMachineMaxNicsValue(VirtualMachine virtualMachine) {
Integer virtualMachineMaxNicsValue = getVirtualMachineMaxNicsValueFromCluster(virtualMachine);

if (virtualMachineMaxNicsValue != null) {
return virtualMachineMaxNicsValue;
}

if (virtualMachine.getHypervisorType() == null) {
logger.debug("Not considering the hypervisor maximum limits as we were unable to find a compatible hypervisor on the VM and VM cluster for virtual machine maximum NICs settings.");
return null;
}

return getVirtualMachineMaxNicsValueFromVmHypervisorType(virtualMachine);
}

/**
* Searches the maximum virtual machine NICs based on 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;
}

return getVirtualMachineMaxNicsValueFromCluster(cluster);
}

/**
* Searches the maximum virtual machine NICs based on the hypervisor type of the cluster where the instance is deployed.
*
* @param cluster Cluster to get the virtual machine max NICs value from.
* @return The maximum number of NICs that the virtual machine can have.
*/
protected Integer getVirtualMachineMaxNicsValueFromCluster(ClusterVO cluster) {
HypervisorType clusterHypervisor = cluster.getHypervisorType();
String logMessage = "The cluster {} where the VM is deployed uses the {} hypervisor. Therefore, the {} setting value [{}] will be used.";

if (clusterHypervisor.equals(HypervisorType.KVM)) {
logger.debug(logMessage, cluster.getName(), clusterHypervisor, VirtualMachineMaxNicsKvm, VirtualMachineMaxNicsKvm.valueIn(cluster.getId()));
return VirtualMachineMaxNicsKvm.valueIn(cluster.getId());
} else if (clusterHypervisor.equals(HypervisorType.VMware)) {
logger.debug(logMessage, cluster.getName(), clusterHypervisor, VirtualMachineMaxNicsKvm, VirtualMachineMaxNicsVmware.valueIn(cluster.getId()));
return VirtualMachineMaxNicsVmware.valueIn(cluster.getId());
} else if (clusterHypervisor.equals(HypervisorType.XenServer)) {
logger.debug(logMessage, cluster.getName(), clusterHypervisor, VirtualMachineMaxNicsXenserver, VirtualMachineMaxNicsXenserver.valueIn(cluster.getId()));
return VirtualMachineMaxNicsXenserver.valueIn(cluster.getId());
}

return null;
}

/**
* 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 Integer getVirtualMachineMaxNicsValueFromVmHypervisorType(VirtualMachine virtualMachine) {
HypervisorType virtualMachineHypervisorType = virtualMachine.getHypervisorType();
String logMessage = "Using the {} setting global value {} as the VM {} has the {} hypervisor type and is not deployed on either a host or a cluster.";

if (virtualMachineHypervisorType.equals(HypervisorType.KVM)) {
logger.debug(logMessage, VirtualMachineMaxNicsKvm, VirtualMachineMaxNicsKvm.value(), virtualMachine.getUuid(), virtualMachineHypervisorType);
return VirtualMachineMaxNicsKvm.value();
} else if (virtualMachineHypervisorType.equals(HypervisorType.VMware)) {
logger.debug(logMessage, VirtualMachineMaxNicsVmware, VirtualMachineMaxNicsVmware.value(), virtualMachine.getUuid(), virtualMachineHypervisorType);
return VirtualMachineMaxNicsVmware.value();
} else if (virtualMachineHypervisorType.equals(HypervisorType.XenServer)) {
logger.debug(logMessage, VirtualMachineMaxNicsXenserver, VirtualMachineMaxNicsXenserver.value(), virtualMachine.getUuid(), virtualMachineHypervisorType);
return VirtualMachineMaxNicsXenserver.value();
}

logger.debug("Not considering the hypervisor maximum limits as we were unable to find a compatible hypervisor on the VM and VM cluster for virtual machine maximum NICs configurations.");
return null;
}

private boolean isNicAllocatedForNsxPublicNetworkOnVR(Network network, NicProfile requested, VirtualMachineProfile vm) {
if (ObjectUtils.anyNull(network, requested, vm)) {
return false;
Expand Down Expand Up @@ -4866,6 +4958,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 };
}
}
Loading
Loading