Skip to content

Commit 62febc2

Browse files
committed
Validate if given CIDR belongs to a bigger allocation in Netris before creating the zone-level allocation (#48)
* Validate if given CIDR belongs to a bigger allocation in Netris before creating * rename method
1 parent e7ef9b6 commit 62febc2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import com.cloud.utils.Pair;
2020
import com.cloud.utils.exception.CloudRuntimeException;
21+
import inet.ipaddr.IPAddress;
22+
import inet.ipaddr.IPAddressString;
2123
import io.netris.ApiClient;
2224
import io.netris.ApiException;
2325
import io.netris.ApiResponse;
@@ -815,11 +817,19 @@ private BigDecimal getIpamAllocationIdByPrefixAndVpc(String superCidrPrefix, VPC
815817
filterByVpc.add(vpc.getId());
816818
IpTree ipamTree = ipamApi.apiV2IpamGet(filterBySites, filterByVpc);
817819
List<IpTreeAllocation> superCidrList = ipamTree.getData().stream()
818-
.filter(x -> x.getPrefix().equals(superCidrPrefix))
820+
.filter(x -> x.getPrefix().equals(superCidrPrefix) || isAllocationPartOfBiggerAllocation(x.getPrefix(), superCidrPrefix))
819821
.collect(Collectors.toList());
820822
return CollectionUtils.isEmpty(superCidrList) ? null : superCidrList.get(0).getId();
821823
}
822824

825+
private boolean isAllocationPartOfBiggerAllocation(String netrisAllocation, String providedAllocation) {
826+
IPAddress biggerAllocation = new IPAddressString(netrisAllocation).getAddress();
827+
IPAddress smallerAllocation = new IPAddressString(providedAllocation).getAddress();
828+
829+
return biggerAllocation.contains(smallerAllocation);
830+
831+
}
832+
823833
private IpTreeSubnet getIpamSubnetByAllocationAndPrefixAndPurposeAndVpc(BigDecimal ipamAllocationId, String exactCidr, IpTreeSubnet.PurposeEnum purpose, VPCListing vpc) throws ApiException {
824834
IpamApi ipamApi = apiClient.getApiStubForMethod(IpamApi.class);
825835
FilterByVpc filterByVpc = new FilterByVpc();

0 commit comments

Comments
 (0)