Skip to content

Commit ce658ac

Browse files
Deploy ipv6 network if zone has IPv6 DNS
If you have a IPv6 enabled network and you haven't specified the IPv6 DNS 1 and DNS 2 under the zone it causes dnsmasq inside the Virtual Router not to start
1 parent 0d4f67a commit ce658ac

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

server/src/main/java/com/cloud/network/NetworkModelImpl.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.inject.Inject;
3535
import javax.naming.ConfigurationException;
3636

37+
import com.cloud.utils.StringUtils;
3738
import org.apache.commons.collections.CollectionUtils;
3839
import org.apache.log4j.Logger;
3940

@@ -110,7 +111,6 @@
110111
import com.cloud.user.AccountVO;
111112
import com.cloud.user.DomainManager;
112113
import com.cloud.user.dao.AccountDao;
113-
import com.cloud.utils.StringUtils;
114114
import com.cloud.utils.component.AdapterBase;
115115
import com.cloud.utils.component.ManagerBase;
116116
import com.cloud.utils.db.DB;
@@ -2187,14 +2187,8 @@ public boolean isNetworkInlineMode(Network network) {
21872187

21882188
@Override
21892189
public void checkIp6Parameters(String startIPv6, String endIPv6, String ip6Gateway, String ip6Cidr) throws InvalidParameterValueException {
2190-
if (!NetUtils.isValidIp6(startIPv6)) {
2191-
throw new InvalidParameterValueException("Invalid format for the startIPv6 parameter");
2192-
}
2193-
if (!NetUtils.isValidIp6(endIPv6)) {
2194-
throw new InvalidParameterValueException("Invalid format for the endIPv6 parameter");
2195-
}
21962190

2197-
if (!(ip6Gateway != null && ip6Cidr != null)) {
2191+
if (org.apache.commons.lang3.StringUtils.isNotBlank(ip6Gateway) && org.apache.commons.lang3.StringUtils.isNotBlank(ip6Cidr)) {
21982192
throw new InvalidParameterValueException("ip6Gateway and ip6Cidr should be defined when startIPv6/endIPv6 are passed in");
21992193
}
22002194

@@ -2204,16 +2198,29 @@ public void checkIp6Parameters(String startIPv6, String endIPv6, String ip6Gatew
22042198
if (!NetUtils.isValidIp6Cidr(ip6Cidr)) {
22052199
throw new InvalidParameterValueException("Invalid ip6cidr");
22062200
}
2207-
if (!NetUtils.isIp6InNetwork(startIPv6, ip6Cidr)) {
2208-
throw new InvalidParameterValueException("startIPv6 is not in ip6cidr indicated network!");
2209-
}
2210-
if (!NetUtils.isIp6InNetwork(endIPv6, ip6Cidr)) {
2211-
throw new InvalidParameterValueException("endIPv6 is not in ip6cidr indicated network!");
2212-
}
2201+
22132202
if (!NetUtils.isIp6InNetwork(ip6Gateway, ip6Cidr)) {
22142203
throw new InvalidParameterValueException("ip6Gateway is not in ip6cidr indicated network!");
22152204
}
22162205

2206+
if (org.apache.commons.lang3.StringUtils.isNotBlank(startIPv6)) {
2207+
if (!NetUtils.isValidIp6(startIPv6)) {
2208+
throw new InvalidParameterValueException("Invalid format for the startIPv6 parameter");
2209+
}
2210+
if (!NetUtils.isIp6InNetwork(startIPv6, ip6Cidr)) {
2211+
throw new InvalidParameterValueException("startIPv6 is not in ip6cidr indicated network!");
2212+
}
2213+
}
2214+
2215+
if (org.apache.commons.lang3.StringUtils.isNotBlank(endIPv6)) {
2216+
if (!NetUtils.isValidIp6(endIPv6)) {
2217+
throw new InvalidParameterValueException("Invalid format for the endIPv6 parameter");
2218+
}
2219+
if (!NetUtils.isIp6InNetwork(endIPv6, ip6Cidr)) {
2220+
throw new InvalidParameterValueException("endIPv6 is not in ip6cidr indicated network!");
2221+
}
2222+
}
2223+
22172224
int cidrSize = NetUtils.getIp6CidrSize(ip6Cidr);
22182225
// we only support cidr == 64
22192226
if (cidrSize != 64) {

server/src/main/java/com/cloud/network/NetworkServiceImpl.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,10 @@ public NicSecondaryIp allocateSecondaryGuestIP(final long nicId, IpAddresses req
726726
String ip6addr = null;
727727
//Isolated network can exist in Basic zone only, so no need to verify the zone type
728728
if (network.getGuestType() == Network.GuestType.Isolated) {
729-
if ((ipv4Address != null || NetUtils.isIpv4(network.getGateway()) && org.apache.commons.lang3.StringUtils.isBlank(ipv6Address))) {
729+
if ((ipv4Address != null || NetUtils.isIpv4(network.getGateway()) && isBlank(ipv6Address))) {
730730
ipaddr = _ipAddrMgr.allocateGuestIP(network, ipv4Address);
731731
}
732-
if (ipv6Address != null) {
732+
if (isNotBlank(ipv6Address)) {
733733
ip6addr = ipv6AddrMgr.allocateGuestIpv6(network, ipv6Address);
734734
}
735735
} else if (network.getGuestType() == Network.GuestType.Shared) {
@@ -763,7 +763,7 @@ public NicSecondaryIp allocateSecondaryGuestIP(final long nicId, IpAddresses req
763763
return null;
764764
}
765765

766-
if (ipaddr != null || ip6addr != null) {
766+
if (isNotBlank(ipaddr) || isNotBlank(ip6addr)) {
767767
// we got the ip addr so up the nics table and secodary ip
768768
final String ip4AddrFinal = ipaddr;
769769
final String ip6AddrFinal = ip6addr;
@@ -1195,7 +1195,7 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
11951195
if (startIP != null) {
11961196
ipv4 = true;
11971197
}
1198-
if (startIPv6 != null) {
1198+
if (isNotBlank(ip6Cidr) && isNotBlank(ip6Gateway)) {
11991199
ipv6 = true;
12001200
}
12011201

@@ -1273,6 +1273,10 @@ public Network createGuestNetwork(CreateNetworkCmd cmd) throws InsufficientCapac
12731273
if (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() != Network.GuestType.Shared) {
12741274
throw new InvalidParameterValueException("Can only support create IPv6 network with advance shared network!");
12751275
}
1276+
1277+
if(isBlank(zone.getIp6Dns1()) && isBlank(zone.getIp6Dns2())) {
1278+
throw new InvalidParameterValueException("Can only create IPv6 network if the zone has IPv6 DNS! Please configure the zone IPv6 DNS1 and/or IPv6 DNS2.");
1279+
}
12761280
}
12771281

12781282
if (isNotBlank(isolatedPvlan) && (zone.getNetworkType() != NetworkType.Advanced || ntwkOff.getGuestType() == GuestType.Isolated)) {
@@ -2749,7 +2753,7 @@ private void verifyAlreadyMigratedTiers(long migratedVpcId, long vpcOfferingId,
27492753
for (Network tier : migratedTiers) {
27502754
String tierNetworkOfferingUuid = networkToOffering.get(tier.getUuid());
27512755

2752-
if (!StringUtils.isNotBlank(tierNetworkOfferingUuid)) {
2756+
if (!isNotBlank(tierNetworkOfferingUuid)) {
27532757
throwInvalidIdException("Failed to resume migrating VPC as the specified tierNetworkOfferings is not complete", String.valueOf(tier.getUuid()), "networkUuid");
27542758
}
27552759

0 commit comments

Comments
 (0)