Skip to content

Commit df44724

Browse files
authored
Update IPAM subnet purpose to nat before NAT operations if its different (apache#71)
1 parent dc7cf7c commit df44724

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,9 +1495,14 @@ private void createNatSubnet(NetrisCommand cmd, String natIp, Integer netrisVpcI
14951495
if (matchedSubnets.isEmpty()) {
14961496
VPCListing systemVpc = getSystemVpc();
14971497
createIpamSubnetInternal(netrisSubnetName, natIp, SubnetBody.PurposeEnum.NAT, systemVpc, null);
1498-
return;
1498+
} else {
1499+
IpTreeSubnet existingSubnet = matchedSubnets.stream().filter(x -> x.getPrefix().equals(natIp)).collect(Collectors.toList()).get(0);
1500+
if (existingSubnet.getPurpose() != IpTreeSubnet.PurposeEnum.NAT) {
1501+
VPCListing systemVpc = getSystemVpc();
1502+
logger.debug("Subnet: {} already exists, but purpose is not NAT, updating its purpose to 'nat'", natIp);
1503+
updateIpamSubnetInternal(existingSubnet.getId().intValue(), netrisSubnetName, natIp, SubnetBody.PurposeEnum.NAT, systemVpc, null);
1504+
}
14991505
}
1500-
logger.debug("NAT subnet: {} already exists", natIp);
15011506
} catch (ApiException e) {
15021507
throw new CloudRuntimeException(String.format("Failed to create subnet for %s with NAT purpose", natIp));
15031508
}
@@ -1762,7 +1767,8 @@ private InlineResponse2004Data createIpamSubnetInternal(String subnetName, Strin
17621767
}
17631768
}
17641769

1765-
private InlineResponse2004Data updateIpamSubnetInternal(Integer netrisSubnetId, String subnetName, String subnetPrefix, SubnetBody.PurposeEnum purpose, VPCListing vpc, Boolean isGlobalRouting) {
1770+
private InlineResponse2004Data updateIpamSubnetInternal(Integer netrisSubnetId, String subnetName, String subnetPrefix,
1771+
SubnetBody.PurposeEnum purpose, VPCListing vpc, Boolean isGlobalRouting) {
17661772
logger.debug("Updating Netris IPAM Subnet {} for VPC {}", subnetPrefix, vpc.getName());
17671773
try {
17681774

0 commit comments

Comments
 (0)