mirror of https://github.com/apache/cloudstack.git
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
This commit is contained in:
parent
5289fe4b62
commit
7f31803232
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue