ravening commented on a change in pull request #4010:
URL: https://github.com/apache/cloudstack/pull/4010#discussion_r521254025
##########
File path:
server/src/main/java/com/cloud/configuration/ConfigurationManagerImpl.java
##########
@@ -1463,6 +1464,175 @@ public void doInTransactionWithoutResult(final
TransactionStatus status) {
}
}
+ @Override
+ @DB
+ public void updatePodIpRange(final UpdatePodManagementNetworkIpRangeCmd
cmd) throws ConcurrentOperationException {
+ final long podId = cmd.getPodId();
+ final String currentStartIP = cmd.getCurrentStartIP();
+ final String currentEndIP = cmd.getCurrentEndIP();
+ final HostPodVO pod = _podDao.findById(podId);
+
+ String newStartIP = cmd.getNewStartIP();
+ String newEndIP = cmd.getNewEndIP();
+
+ if (newStartIP == null) {
+ newStartIP = currentStartIP;
+ }
+
+ if (newEndIP == null) {
+ newEndIP = currentEndIP;
+ }
+
+ if (pod == null) {
+ throw new InvalidParameterValueException("Unable to find pod by id
" + podId);
+ }
+
+ final String[] existingPodIpRanges = pod.getDescription().split(",");
+ if (existingPodIpRanges.length == 0) {
+ throw new InvalidParameterValueException("The IP range cannot be
found since the existing IP range is empty.");
+ }
+
+ verifyIpRangeParameters(currentStartIP,currentEndIP);
+ verifyIpRangeParameters(newStartIP,newEndIP);
+
checkIpRangeContainsTakenAddresses(pod,currentStartIP,currentEndIP,newStartIP,newEndIP);
+
+ String vlan =
verifyPodIpRangeExists(podId,existingPodIpRanges,currentStartIP,currentEndIP,newStartIP,newEndIP);
+
+ List<Long> currentIpRange =
listAllIPsWithintheRange(currentStartIP,currentEndIP);
+ List<Long> newIpRange = listAllIPsWithintheRange(newStartIP,newEndIP);
+
+ try {
+ final String finalNewEndIP = newEndIP;
+ final String finalNewStartIP = newStartIP;
+ final Integer vlanId = vlan.equals(Vlan.UNTAGGED) ? null :
Integer.parseInt(vlan);
+
+ Transaction.execute(new TransactionCallbackNoReturn() {
+ @Override
+ public void doInTransactionWithoutResult(final
TransactionStatus status) {
+ final long zoneId = pod.getDataCenterId();
+
pod.setDescription(pod.getDescription().replace(currentStartIP + "-",
+ finalNewStartIP + "-").replace(currentEndIP,
finalNewEndIP));
+
updatePodIpRangeInDb(zoneId,podId,vlanId,pod,newIpRange,currentIpRange);
+ }
+ });
+ } catch (final Exception e) {
+ s_logger.error("Unable to update Pod " + podId + " IP range due to
" + e.getMessage(), e);
+ throw new CloudRuntimeException("Failed to update Pod " + podId +
" IP range. Please contact Cloud Support.");
+ }
+ }
+
+ private String verifyPodIpRangeExists(long podId,String[]
existingPodIpRanges, String currentStartIP,
+ String currentEndIP, String newStartIP, String newEndIP) {
+ boolean foundRange = false;
+ String vlan = null;
+
+ for (String podIpRange: existingPodIpRanges) {
+ final String[] existingPodIpRange = podIpRange.split("-");
+
+ if (existingPodIpRange.length > 1) {
+ if (!NetUtils.isValidIp4(existingPodIpRange[0]) ||
!NetUtils.isValidIp4(existingPodIpRange[1])) {
+ continue;
+ }
+ if (currentStartIP.equals(existingPodIpRange[0]) &&
currentEndIP.equals(existingPodIpRange[1])) {
+ foundRange = true;
+ vlan = existingPodIpRange[3];
+ }
+ if (!foundRange && NetUtils.ipRangesOverlap(newStartIP,
newEndIP, existingPodIpRange[0], existingPodIpRange[1])) {
+ throw new InvalidParameterValueException("The Start IP and
EndIP address range overlap with private IP :" + existingPodIpRange[0] + "-" +
existingPodIpRange[1]);
Review comment:
Small optimization is you can just display `podIpRange` instead of [0]
and [1]
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]