This is an automated email from the ASF dual-hosted git repository.

pearl11594 pushed a commit to branch netris-integration-upstream
in repository https://gitbox.apache.org/repos/asf/cloudstack.git

commit 62febc27bb4e6a658a0958a96514392d77fd242e
Author: Pearl Dsilva <[email protected]>
AuthorDate: Wed Feb 5 10:37:46 2025 -0500

    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
---
 .../org/apache/cloudstack/service/NetrisApiClientImpl.java   | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git 
a/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java
 
b/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java
index 7f80947974d..e61482a3564 100644
--- 
a/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java
+++ 
b/plugins/network-elements/netris/src/main/java/org/apache/cloudstack/service/NetrisApiClientImpl.java
@@ -18,6 +18,8 @@ package org.apache.cloudstack.service;
 
 import com.cloud.utils.Pair;
 import com.cloud.utils.exception.CloudRuntimeException;
+import inet.ipaddr.IPAddress;
+import inet.ipaddr.IPAddressString;
 import io.netris.ApiClient;
 import io.netris.ApiException;
 import io.netris.ApiResponse;
@@ -815,11 +817,19 @@ public class NetrisApiClientImpl implements 
NetrisApiClient {
         filterByVpc.add(vpc.getId());
         IpTree ipamTree = ipamApi.apiV2IpamGet(filterBySites, filterByVpc);
         List<IpTreeAllocation> superCidrList = ipamTree.getData().stream()
-                .filter(x -> x.getPrefix().equals(superCidrPrefix))
+                .filter(x -> x.getPrefix().equals(superCidrPrefix) || 
isAllocationPartOfBiggerAllocation(x.getPrefix(), superCidrPrefix))
                 .collect(Collectors.toList());
         return CollectionUtils.isEmpty(superCidrList) ? null : 
superCidrList.get(0).getId();
     }
 
+    private boolean isAllocationPartOfBiggerAllocation(String 
netrisAllocation, String providedAllocation) {
+        IPAddress biggerAllocation = new 
IPAddressString(netrisAllocation).getAddress();
+        IPAddress smallerAllocation = new 
IPAddressString(providedAllocation).getAddress();
+
+        return biggerAllocation.contains(smallerAllocation);
+
+    }
+
     private IpTreeSubnet 
getIpamSubnetByAllocationAndPrefixAndPurposeAndVpc(BigDecimal ipamAllocationId, 
String exactCidr, IpTreeSubnet.PurposeEnum purpose, VPCListing vpc) throws 
ApiException {
         IpamApi ipamApi = apiClient.getApiStubForMethod(IpamApi.class);
         FilterByVpc filterByVpc = new FilterByVpc();

Reply via email to