Skip to content

Commit aae95b1

Browse files
committed
Allow updating of Load Balancer source CIDR list
* Should fix #9313
1 parent 3d6ec29 commit aae95b1

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-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
@@ -33,6 +33,7 @@
3333
import com.cloud.network.rules.FirewallRule;
3434
import com.cloud.network.rules.LoadBalancer;
3535
import com.cloud.user.Account;
36+
import java.util.List;
3637

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

68+
@Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
69+
private List<String> cidrList;
70+
6771
/////////////////////////////////////////////////////
6872
/////////////////// Accessors ///////////////////////
6973
/////////////////////////////////////////////////////
@@ -92,6 +96,9 @@ public String getLbProtocol() {
9296
return lbProtocol;
9397
}
9498

99+
public List<String> getCidrList() {
100+
return cidrList;
101+
}
95102
/////////////////////////////////////////////////////
96103
/////////////// API Implementation///////////////////
97104
/////////////////////////////////////////////////////

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
@@ -144,4 +144,8 @@ public String toString() {
144144
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(
145145
this, "id", "uuid", "name", "purpose", "state"));
146146
}
147+
148+
public void setCidrList(String cidrList) {
149+
this.cidrList = cidrList;
150+
}
147151
}

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,17 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22482248
}
22492249

22502250
validateInputsForExternalNetworkProvider(lb, algorithm, lbProtocol);
2251+
2252+
List<String> cidrList = cmd.getCidrList();
2253+
2254+
if (cidrList != null) {
2255+
String cidrListStr = StringUtils.join(cidrList, ",");
2256+
if (!cidrListStr.isEmpty() && !NetUtils.isValidCidrList(cidrListStr)) {
2257+
throw new InvalidParameterValueException("Invalid CIDR list: " + cidrListStr);
2258+
}
2259+
lb.setCidrList(cidrListStr);
2260+
}
2261+
22512262
// Validate rule in LB provider
22522263
LoadBalancingRule rule = getLoadBalancerRuleToApply(lb);
22532264
if (!validateLbRule(rule)) {
@@ -2257,8 +2268,14 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22572268
LoadBalancerVO tmplbVo = _lbDao.findById(lbRuleId);
22582269
boolean success = _lbDao.update(lbRuleId, lb);
22592270

2260-
// If algorithm is changed, have to reapply the lb config
2261-
if ((algorithm != null) && (tmplbVo.getAlgorithm().compareTo(algorithm) != 0)){
2271+
// Check if algorithm or cidrlist has changed, and reapply the lb config if needed
2272+
boolean algorithmChanged = (algorithm != null) && (tmplbVo.getAlgorithm().compareTo(algorithm) != 0);
2273+
boolean cidrListChanged = (tmplbVo.getCidrList() == null && lb.getCidrList() != null) ||
2274+
(tmplbVo.getCidrList() != null && lb.getCidrList() == null) ||
2275+
(tmplbVo.getCidrList() != null && lb.getCidrList() != null &&
2276+
!tmplbVo.getCidrList().equals(lb.getCidrList()));
2277+
2278+
if (algorithmChanged || cidrListChanged) {
22622279
try {
22632280
lb.setState(FirewallRule.State.Add);
22642281
_lbDao.persist(lb);
@@ -2279,6 +2296,9 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22792296
if (lbBackup.getAlgorithm() != null) {
22802297
lb.setAlgorithm(lbBackup.getAlgorithm());
22812298
}
2299+
if (lbBackup.getCidrList() != null || lb.getCidrList() != null) { // Added for cidrlist rollback
2300+
lb.setCidrList(lbBackup.getCidrList());
2301+
}
22822302
lb.setState(lbBackup.getState());
22832303
_lbDao.update(lb.getId(), lb);
22842304
_lbDao.persist(lb);

0 commit comments

Comments
 (0)