|
18 | 18 |
|
19 | 19 | import com.cloud.utils.Pair;
|
20 | 20 | import com.cloud.utils.exception.CloudRuntimeException;
|
| 21 | +import inet.ipaddr.IPAddress; |
| 22 | +import inet.ipaddr.IPAddressString; |
21 | 23 | import io.netris.ApiClient;
|
22 | 24 | import io.netris.ApiException;
|
23 | 25 | import io.netris.ApiResponse;
|
@@ -815,11 +817,19 @@ private BigDecimal getIpamAllocationIdByPrefixAndVpc(String superCidrPrefix, VPC
|
815 | 817 | filterByVpc.add(vpc.getId());
|
816 | 818 | IpTree ipamTree = ipamApi.apiV2IpamGet(filterBySites, filterByVpc);
|
817 | 819 | List<IpTreeAllocation> superCidrList = ipamTree.getData().stream()
|
818 |
| - .filter(x -> x.getPrefix().equals(superCidrPrefix)) |
| 820 | + .filter(x -> x.getPrefix().equals(superCidrPrefix) || isAllocationPartOfBiggerAllocation(x.getPrefix(), superCidrPrefix)) |
819 | 821 | .collect(Collectors.toList());
|
820 | 822 | return CollectionUtils.isEmpty(superCidrList) ? null : superCidrList.get(0).getId();
|
821 | 823 | }
|
822 | 824 |
|
| 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 | + |
823 | 833 | private IpTreeSubnet getIpamSubnetByAllocationAndPrefixAndPurposeAndVpc(BigDecimal ipamAllocationId, String exactCidr, IpTreeSubnet.PurposeEnum purpose, VPCListing vpc) throws ApiException {
|
824 | 834 | IpamApi ipamApi = apiClient.getApiStubForMethod(IpamApi.class);
|
825 | 835 | FilterByVpc filterByVpc = new FilterByVpc();
|
|
0 commit comments