sureshanaparti commented on a change in pull request #5411:
URL: https://github.com/apache/cloudstack/pull/5411#discussion_r710896907
##########
File path:
server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
##########
@@ -4569,6 +4835,59 @@ protected boolean savePublicIPRange(final String
startIP, final String endIP, fi
return problemIps != null && problemIps.size() == 0;
}
+ @DB
+ protected boolean updatePublicIPRange(final String newStartIP, final
String currentStartIP, final String newEndIP, final String currentEndIP, final
long zoneId, final long vlanDbId, final long sourceNetworkid, final long
physicalNetworkId, final boolean isRangeForSystemVM, final Boolean
forSystemVms) {
+ long newStartIPLong = NetUtils.ip2Long(newStartIP);
+ long newEndIPLong = NetUtils.ip2Long(newEndIP);
+ long currentStartIPLong = NetUtils.ip2Long(currentStartIP);
+ long currentEndIPLong = NetUtils.ip2Long(currentEndIP);
+
+ List<Long> currentIPRange = new ArrayList<>();
+ List<Long> newIPRange = new ArrayList<>();
+ while (newStartIPLong <= newEndIPLong) {
+ newIPRange.add(newStartIPLong);
+ newStartIPLong++;
+ }
+ while (currentStartIPLong <= currentEndIPLong) {
+ currentIPRange.add(currentStartIPLong);
+ currentStartIPLong++;
+ }
+
+ final List<String> problemIps = Transaction.execute(new
TransactionCallback<List<String>>() {
+
+ @Override
+ public List<String> doInTransaction(final TransactionStatus
status) {
+ final IPRangeConfig config = new IPRangeConfig();
+ Vector<String> configResult = new Vector<>();
+ List<Long> ipAddressesToAdd = new ArrayList(newIPRange);
+ ipAddressesToAdd.removeAll(currentIPRange);
+ if (ipAddressesToAdd.size() > 0) {
+ for (Long startIP : ipAddressesToAdd) {
+
configResult.addAll(config.savePublicIPRange(TransactionLegacy.currentTxn(),
startIP, startIP, zoneId, vlanDbId, sourceNetworkid, physicalNetworkId,
forSystemVms != null ? forSystemVms : isRangeForSystemVM));
+ }
+ }
+ List<Long> ipAddressesToDelete = new ArrayList(currentIPRange);
+ ipAddressesToDelete.removeAll(newIPRange);
+ if (ipAddressesToDelete.size() > 0) {
+ for (Long startIP : ipAddressesToDelete) {
+
configResult.addAll(config.deletePublicIPRange(TransactionLegacy.currentTxn(),
startIP, startIP, vlanDbId));
+ }
+ }
+ if (forSystemVms != null && isRangeForSystemVM !=
forSystemVms) {
+ List<Long> ipAddressesToUpdate = new
ArrayList(currentIPRange);
+ ipAddressesToUpdate.removeAll(ipAddressesToDelete);
+ if (ipAddressesToUpdate.size() > 0) {
+ for (Long startIP : ipAddressesToUpdate) {
+
configResult.addAll(config.updatePublicIPRange(TransactionLegacy.currentTxn(),
startIP, startIP, vlanDbId, forSystemVms));
+ }
+ }
+ }
+ return configResult;
+ }
+ });
+ return problemIps != null && problemIps.size() == 0;
Review comment:
```suggestion
return CollectionUtils.isEmpty(problemIps);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]