Github user jburwell commented on a diff in the pull request:
https://github.com/apache/cloudstack/pull/1371#discussion_r62782933
--- Diff: server/src/com/cloud/network/vpc/VpcManagerImpl.java ---
@@ -747,6 +810,67 @@ public VpcOffering updateVpcOffering(final long
vpcOffId, final String vpcOfferi
}
@Override
+ public CIDR[] getZoneSuperCidrList(final long zoneId) throws
BadCIDRException {
+ final String superCIDRList = _dcDao.getDetail(zoneId,
Params.SUPER_CIDR.name());
+ if (superCIDRList != null) {
+ String[] str_cidr_list = superCIDRList.split(",");
+ CIDR[] cidr_list = NetUtils.convertToCIDR(str_cidr_list);
+ if (!NetUtils.cidrListConsistency(cidr_list)) {
+ throw new InvalidParameterValueException("The cidr list is
not consistent " + Arrays.toString(cidr_list));
+ }
+ return cidr_list;
+ } else {
+ throw new InvalidParameterValueException("Zone super cidr is
null check cloud.data_center_details for zone id=" + zoneId);
+ }
+ }
+
+ private List<CIDR> getAllVpcCidrs() throws BadCIDRException {
+ // get all the used cidrs
+ List<CIDR> usedSubnets = new ArrayList<CIDR>();
+ for (Vpc vpc : _vpcDao.listAll()) {
+ if (_vpcSrvcDao.areServicesSupportedInVpc(vpc.getId(),
Service.VPCDynamicRouting)) {
+ usedSubnets.add(CIDRFactory.getCIDR(vpc.getCidr()));
+ }
+ }
+ return usedSubnets;
+ }
+
+ @Override
+ @ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription
= "creating vpc", create = true)
+ public synchronized Vpc createDynamicVpc(final long zoneId, final long
vpcOffId, final long vpcOwnerId, final String vpcName, final String
displayText, final String netmask,
+ String networkDomain, final Boolean displayVpc) throws
ResourceAllocationException, BadCIDRException {
+ if (netmask != null) {
+ if (!NetUtils.isValidNetmask(netmask)) {
+ throw new InvalidParameterValueException("Invalid netmask
" + netmask);
+ }
+ final CIDR[] superCidr = getZoneSuperCidrList(zoneId);
+ final List<CIDR> usedSubnets = getAllVpcCidrs();
+ //find cidr that does not overlap with the used cidrs
+ List<CIDR> allSubnets = NetUtils.getAllSubnets(superCidr,
netmask);
+ //check for overlap with usedSubnets
+ CIDR unused_cidr = null;
+ for (CIDR subnet : allSubnets) {
+ if (NetUtils.isCidrOverlap(subnet, usedSubnets)) {
+ continue;
+ } else {
+ unused_cidr = subnet;
+ break;
+ }
+ }
--- End diff --
Consider moving this for loop to ``CIDR.findUnusedSubnet`` method and
adding a unit test for it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---