Skip to content

Commit 7911153

Browse files
committed
[4.22] Prevent Load Balancer rule creation when adding a VM from a different network
1 parent 7aa0558 commit 7911153

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

server/src/main/java/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,8 @@ public LoadBalancer createPublicLoadBalancerRule(String xId, String name, String
17381738
throw new NetworkRuleConflictException("Can't do load balance on IP address: " + ipVO.getAddress());
17391739
}
17401740

1741+
verifyLoadBalancerRuleNetwork(name, network, ipVO);
1742+
17411743
String cidrString = generateCidrString(cidrList);
17421744

17431745
boolean performedIpAssoc = false;
@@ -1790,7 +1792,17 @@ public LoadBalancer createPublicLoadBalancerRule(String xId, String name, String
17901792

17911793
return result;
17921794
}
1793-
/**
1795+
1796+
protected void verifyLoadBalancerRuleNetwork(String lbName, Network network, IPAddressVO ipVO) {
1797+
if (ipVO.getAssociatedWithNetworkId() != null && network.getId() != ipVO.getAssociatedWithNetworkId()) {
1798+
String msg = String.format("Cannot create Load Balancer rule %s as the IP address %s is not associated " +
1799+
"with the network %s (ID=%s)", lbName, ipVO.getAddress(), network.getName(), network.getUuid());
1800+
logger.error(msg);
1801+
throw new InvalidParameterValueException(msg);
1802+
}
1803+
}
1804+
1805+
/**
17941806
* Transforms the cidrList from a List of Strings to a String which contains all the CIDRs from cidrList separated by whitespaces. This is used to facilitate both the persistence
17951807
* in the DB and also later when building the configuration String in the getRulesForPool method of the HAProxyConfigurator class.
17961808
*/

0 commit comments

Comments
 (0)