ipv6: disable IPv6-only shared network with VR (#5810)

* ipv6: disable IPv6-only shared network with VR

* Update #5810: import org.apache.commons.lang3.StringUtils
* Update #5810: do not import org.apache.commons.lang3.StringUtils
* Update server/src/main/java/com/cloud/network/NetworkServiceImpl.java
* Update engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java

Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com>
This commit is contained in:
Wei Zhou 2022-01-12 09:03:35 +01:00 committed by GitHub
parent 223bc11d2a
commit 216bea1978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -2642,7 +2642,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
&& !_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))); && !_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat)));
if (cidr == null && ip6Cidr == null && cidrRequired) { if (cidr == null && ip6Cidr == null && cidrRequired) {
if (ntwkOff.getGuestType() == GuestType.Shared) { if (ntwkOff.getGuestType() == GuestType.Shared) {
throw new InvalidParameterValueException("StartIp/endIp/gateway/netmask are required when create network of" + " type " + Network.GuestType.Shared); throw new InvalidParameterValueException(String.format("Gateway/netmask are required when creating %s networks.", Network.GuestType.Shared));
} else { } else {
throw new InvalidParameterValueException("gateway/netmask are required when create network of" + " type " + GuestType.Isolated + " with service " + Service.SourceNat.getName() + " disabled"); throw new InvalidParameterValueException("gateway/netmask are required when create network of" + " type " + GuestType.Isolated + " with service " + Service.SourceNat.getName() + " disabled");
} }

View File

@ -1252,8 +1252,8 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
} }
} }
boolean ipv4 = true, ipv6 = false; boolean ipv4 = false, ipv6 = false;
if (startIP != null) { if (org.apache.commons.lang3.StringUtils.isNoneBlank(gateway, netmask)) {
ipv4 = true; ipv4 = true;
} }
if (isNotBlank(ip6Cidr) && isNotBlank(ip6Gateway)) { if (isNotBlank(ip6Cidr) && isNotBlank(ip6Gateway)) {
@ -1297,14 +1297,10 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
} else if (!NetUtils.isValidIp4(endIP)) { } else if (!NetUtils.isValidIp4(endIP)) {
throw new InvalidParameterValueException("Invalid format for the endIp parameter"); throw new InvalidParameterValueException("Invalid format for the endIp parameter");
} }
}
if (startIP != null && endIP != null) {
if (!(gateway != null && netmask != null)) { if (!(gateway != null && netmask != null)) {
throw new InvalidParameterValueException("gateway and netmask should be defined when startIP/endIP are passed in"); throw new InvalidParameterValueException("gateway and netmask should be defined when startIP/endIP are passed in");
} }
} }
if (gateway != null && netmask != null) { if (gateway != null && netmask != null) {
if (NetUtils.isNetworkorBroadcastIP(gateway, netmask)) { if (NetUtils.isNetworkorBroadcastIP(gateway, netmask)) {
if (s_logger.isDebugEnabled()) { if (s_logger.isDebugEnabled()) {
@ -1338,6 +1334,10 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
if(isBlank(zone.getIp6Dns1()) && isBlank(zone.getIp6Dns2())) { if(isBlank(zone.getIp6Dns1()) && isBlank(zone.getIp6Dns2())) {
throw new InvalidParameterValueException("Can only create IPv6 network if the zone has IPv6 DNS! Please configure the zone IPv6 DNS1 and/or IPv6 DNS2."); throw new InvalidParameterValueException("Can only create IPv6 network if the zone has IPv6 DNS! Please configure the zone IPv6 DNS1 and/or IPv6 DNS2.");
} }
if (!ipv4 && ntwkOff.getGuestType() == GuestType.Shared && _networkModel.isProviderForNetworkOffering(Provider.VirtualRouter, networkOfferingId)) {
throw new InvalidParameterValueException("Currently IPv6-only Shared network with Virtual Router provider is not supported.");
}
} }
validateRouterIps(routerIp, routerIpv6, startIP, endIP, gateway, netmask, startIPv6, endIPv6, ip6Cidr); validateRouterIps(routerIp, routerIpv6, startIP, endIP, gateway, netmask, startIPv6, endIPv6, ip6Cidr);