Skip to content

Commit b2175d2

Browse files
committed
Allow updating of Load Balancer source CIDR list
* Should fix #9313
1 parent 5be6b79 commit b2175d2

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/loadbalancer/UpdateLoadBalancerRuleCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.cloud.network.rules.FirewallRule;
3535
import com.cloud.network.rules.LoadBalancer;
3636
import com.cloud.user.Account;
37+
import java.util.List;
3738

3839
@APICommand(name = "updateLoadBalancerRule", description = "Updates load balancer", responseObject = LoadBalancerResponse.class,
3940
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -66,6 +67,9 @@ public class UpdateLoadBalancerRuleCmd extends BaseAsyncCustomIdCmd {
6667
@Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, description = "The protocol for the LB")
6768
private String lbProtocol;
6869

70+
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
71+
private List<String> cidrList;
72+
6973
/////////////////////////////////////////////////////
7074
/////////////////// Accessors ///////////////////////
7175
/////////////////////////////////////////////////////
@@ -94,6 +98,9 @@ public String getLbProtocol() {
9498
return lbProtocol;
9599
}
96100

101+
public List<String> getCidrList() {
102+
return cidrList;
103+
}
97104
/////////////////////////////////////////////////////
98105
/////////////// API Implementation///////////////////
99106
/////////////////////////////////////////////////////

engine/schema/src/main/java/com/cloud/network/dao/LoadBalancerVO.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,8 @@ public Scheme getScheme() {
136136
public String getCidrList() {
137137
return cidrList;
138138
}
139+
140+
public void setCidrList(String cidrList) {
141+
this.cidrList = cidrList;
142+
}
139143
}

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,6 +2251,16 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22512251
lb.setLbProtocol(lbProtocol);
22522252
}
22532253

2254+
List<String> cidrList = cmd.getCidrList();
2255+
2256+
if (cidrList != null) {
2257+
String cidrListStr = StringUtils.join(cidrList, ",");
2258+
if (!cidrListStr.isEmpty() && !NetUtils.isValidCidrList(cidrListStr)) {
2259+
throw new InvalidParameterValueException("Invalid CIDR list: " + cidrListStr);
2260+
}
2261+
lb.setCidrList(cidrListStr);
2262+
}
2263+
22542264
// Validate rule in LB provider
22552265
LoadBalancingRule rule = getLoadBalancerRuleToApply(lb);
22562266
if (!validateLbRule(rule)) {
@@ -2260,8 +2270,14 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22602270
LoadBalancerVO tmplbVo = _lbDao.findById(lbRuleId);
22612271
boolean success = _lbDao.update(lbRuleId, lb);
22622272

2263-
// If algorithm is changed, have to reapply the lb config
2264-
if ((algorithm != null) && (tmplbVo.getAlgorithm().compareTo(algorithm) != 0)){
2273+
// Check if algorithm or cidrlist has changed, and reapply the lb config if needed
2274+
boolean algorithmChanged = (algorithm != null) && (tmplbVo.getAlgorithm().compareTo(algorithm) != 0);
2275+
boolean cidrListChanged = (tmplbVo.getCidrList() == null && lb.getCidrList() != null) ||
2276+
(tmplbVo.getCidrList() != null && lb.getCidrList() == null) ||
2277+
(tmplbVo.getCidrList() != null && lb.getCidrList() != null &&
2278+
!tmplbVo.getCidrList().equals(lb.getCidrList()));
2279+
2280+
if (algorithmChanged || cidrListChanged) {
22652281
try {
22662282
lb.setState(FirewallRule.State.Add);
22672283
_lbDao.persist(lb);
@@ -2282,6 +2298,9 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22822298
if (lbBackup.getAlgorithm() != null) {
22832299
lb.setAlgorithm(lbBackup.getAlgorithm());
22842300
}
2301+
if (lbBackup.getCidrList() != null || lb.getCidrList() != null) { // Added for cidrlist rollback
2302+
lb.setCidrList(lbBackup.getCidrList());
2303+
}
22852304
lb.setState(lbBackup.getState());
22862305
_lbDao.update(lb.getId(), lb);
22872306
_lbDao.persist(lb);

0 commit comments

Comments
 (0)