Skip to content

Commit df35ef7

Browse files
committed
Allow updating of Load Balancer source CIDR list
* Should fix #9313
1 parent 70a4503 commit df35ef7

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
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: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,17 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22572257
}
22582258

22592259
validateInputsForExternalNetworkProvider(lb, algorithm, lbProtocol);
2260+
2261+
List<String> cidrList = cmd.getCidrList();
2262+
2263+
if (cidrList != null) {
2264+
String cidrListStr = StringUtils.join(cidrList, ",");
2265+
if (!cidrListStr.isEmpty() && !NetUtils.isValidCidrList(cidrListStr)) {
2266+
throw new InvalidParameterValueException("Invalid CIDR list: " + cidrListStr);
2267+
}
2268+
lb.setCidrList(cidrListStr);
2269+
}
2270+
22602271
// Validate rule in LB provider
22612272
LoadBalancingRule rule = getLoadBalancerRuleToApply(lb);
22622273
if (!validateLbRule(rule)) {
@@ -2266,10 +2277,12 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22662277
LoadBalancerVO tmplbVo = _lbDao.findById(lbRuleId);
22672278
boolean success = _lbDao.update(lbRuleId, lb);
22682279

2269-
// If algorithm or lb protocol is changed, have to reapply the lb config
2270-
boolean needToReApplyRule = (algorithm != null && !algorithm.equals(tmplbVo.getAlgorithm()))
2271-
|| (lbProtocol != null && !lbProtocol.equals(tmplbVo.getLbProtocol()));
2272-
if (needToReApplyRule) {
2280+
// Check if algorithm, lb protocol, or cidrlist has changed, and reapply the lb config if needed
2281+
boolean algorithmChanged = !Objects.equals(algorithm, tmplbVo.getAlgorithm());
2282+
boolean protocolChanged = !Objects.equals(lbProtocol, tmplbVo.getLbProtocol());
2283+
boolean cidrListChanged = !Objects.equals(tmplbVo.getCidrList(), lb.getCidrList());
2284+
2285+
if (algorithmChanged || protocolChanged || cidrListChanged) {
22732286
try {
22742287
lb.setState(FirewallRule.State.Add);
22752288
_lbDao.persist(lb);
@@ -2296,6 +2309,8 @@ public LoadBalancer updateLoadBalancerRule(UpdateLoadBalancerRuleCmd cmd) {
22962309
if (lbBackup.getLbProtocol() != null) {
22972310
lb.setLbProtocol(lbBackup.getLbProtocol());
22982311
}
2312+
2313+
lb.setCidrList(lbBackup.getCidrList());
22992314
lb.setState(lbBackup.getState());
23002315
_lbDao.update(lb.getId(), lb);
23012316
_lbDao.persist(lb);

0 commit comments

Comments
 (0)