diff --git a/cosmic-core/cosmic-flyway/src/main/resources/db/migration/V2_38__nullify_DNS_servers_private.sql b/cosmic-core/cosmic-flyway/src/main/resources/db/migration/V2_38__nullify_DNS_servers_private.sql new file mode 100644 index 0000000000..9ea602d1ba --- /dev/null +++ b/cosmic-core/cosmic-flyway/src/main/resources/db/migration/V2_38__nullify_DNS_servers_private.sql @@ -0,0 +1,2 @@ +-- Nullify DNS servers for Private networks +UPDATE `networks` SET dns1=NULL, dns2=NULL WHERE guest_type = 'Private' AND removed is NULL; diff --git a/cosmic-core/engine/orchestration/src/main/java/com/cloud/engine/orchestration/NetworkOrchestrator.java b/cosmic-core/engine/orchestration/src/main/java/com/cloud/engine/orchestration/NetworkOrchestrator.java index f4c65046cf..935ff847fa 100644 --- a/cosmic-core/engine/orchestration/src/main/java/com/cloud/engine/orchestration/NetworkOrchestrator.java +++ b/cosmic-core/engine/orchestration/src/main/java/com/cloud/engine/orchestration/NetworkOrchestrator.java @@ -2216,7 +2216,6 @@ public NetworkProfile convertNetworkToNetworkProfile(final long networkId) { profile.setDns2(network.getDns2()); profile.setDhcpTftpServer(network.getDhcpTftpServer()); profile.setDhcpBootfileName(network.getDhcpBootfileName()); - guru.updateNetworkProfile(profile); return profile; } diff --git a/cosmic-core/server/src/main/java/com/cloud/network/NetworkServiceImpl.java b/cosmic-core/server/src/main/java/com/cloud/network/NetworkServiceImpl.java index 9f551a8d15..f6bbe2bae4 100644 --- a/cosmic-core/server/src/main/java/com/cloud/network/NetworkServiceImpl.java +++ b/cosmic-core/server/src/main/java/com/cloud/network/NetworkServiceImpl.java @@ -901,6 +901,10 @@ && areServicesSupportedByNetworkOffering(ntwkOff.getId(), Service.SourceNat))) { ip6Gateway = NetUtils.getCidrHostAddress6(ip6Cidr); } + if (ntwkOff.getGuestType() == GuestType.Private && (dns1 != null || dns2 != null)) { + throw new InvalidParameterValueException("Network of type Private does not support setting DNS servers"); + } + Network network = commitNetwork(networkOfferingId, gateway, startIP, endIP, netmask, networkDomain, vlanId, name, displayText, caller, physicalNetworkId, zoneId, domainId, isDomainSpecific, subdomainAccess, vpcId, startIPv6, endIPv6, ip6Gateway, ip6Cidr, displayNetwork, aclId, isolatedPvlan, ntwkOff, pNtwk, aclType, owner, cidr, createVlan, dns1, dns2, ipExclusionList, getDhcpTftpServer, getDhcpBootfileName); diff --git a/cosmic-core/server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java b/cosmic-core/server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java index 729badf711..6e8bbb9e82 100644 --- a/cosmic-core/server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java +++ b/cosmic-core/server/src/main/java/com/cloud/network/guru/GuestNetworkGuru.java @@ -466,7 +466,6 @@ public boolean trash(final Network network, final NetworkOffering offering) { @Override public void updateNetworkProfile(final NetworkProfile networkProfile) { - final DataCenter dc = _dcDao.findById(networkProfile.getDataCenterId()); if (networkProfile.getDns1() != null && networkProfile.getDns1().equals("")) { networkProfile.setDns1(null); } diff --git a/cosmic-core/server/src/main/java/com/cloud/network/guru/PrivateNetworkGuru.java b/cosmic-core/server/src/main/java/com/cloud/network/guru/PrivateNetworkGuru.java index 5c961e3c07..784bbee4ab 100644 --- a/cosmic-core/server/src/main/java/com/cloud/network/guru/PrivateNetworkGuru.java +++ b/cosmic-core/server/src/main/java/com/cloud/network/guru/PrivateNetworkGuru.java @@ -251,8 +251,8 @@ protected void getIp(final NicProfile nic, final DataCenter dc, final Network ne nic.setMacAddress(ip.getMacAddress()); } - nic.setIPv4Dns1(dc.getDns1()); - nic.setIPv4Dns2(dc.getDns2()); + nic.setIPv4Dns1(null); + nic.setIPv4Dns2(null); } @Override @@ -284,10 +284,9 @@ public void deallocate(final Network network, final NicProfile nic, final Virtua @Override public void updateNicProfile(final NicProfile profile, final Network network) { - final DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId()); if (profile != null) { - profile.setIPv4Dns1(dc.getDns1()); - profile.setIPv4Dns2(dc.getDns2()); + profile.setIPv4Dns1(null); + profile.setIPv4Dns2(null); } } @@ -303,9 +302,6 @@ public boolean trash(final Network network, final NetworkOffering offering) { @Override public void updateNetworkProfile(final NetworkProfile networkProfile) { - final DataCenter dc = _entityMgr.findById(DataCenter.class, networkProfile.getDataCenterId()); - networkProfile.setDns1(dc.getDns1()); - networkProfile.setDns2(dc.getDns2()); } @Override