mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-2088. Dedicated Public IP Addresses per tenant. Guest Network in a project acquires IPs at random even from the IP ranges which are dedicated to other accounts.
Modified search to return only IP's belonging to system pool
This commit is contained in:
parent
977162b9f0
commit
f8d4a23343
|
|
@ -50,4 +50,6 @@ public interface VlanDao extends GenericDao<VlanVO, Long> {
|
|||
List<VlanVO> listVlansByNetworkId(long networkId);
|
||||
|
||||
List<VlanVO> listVlansByPhysicalNetworkId(long physicalNetworkId);
|
||||
|
||||
List<VlanVO> listZoneWideNonDedicatedVlans(long zoneId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
|||
protected SearchBuilder<VlanVO> ZoneVlanSearch;
|
||||
protected SearchBuilder<VlanVO> NetworkVlanSearch;
|
||||
protected SearchBuilder<VlanVO> PhysicalNetworkVlanSearch;
|
||||
protected SearchBuilder<VlanVO> ZoneWideNonDedicatedVlanSearch;
|
||||
|
||||
protected SearchBuilder<AccountVlanMapVO> AccountVlanMapSearch;
|
||||
|
||||
@Inject protected PodVlanMapDao _podVlanMapDao;
|
||||
@Inject protected AccountVlanMapDao _accountVlanMapDao;
|
||||
|
|
@ -198,6 +201,14 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
|||
PodVlanSearch2.done();
|
||||
ZoneTypePodSearch.done();
|
||||
|
||||
ZoneWideNonDedicatedVlanSearch = createSearchBuilder();
|
||||
ZoneWideNonDedicatedVlanSearch.and("zoneId", ZoneWideNonDedicatedVlanSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
AccountVlanMapSearch = _accountVlanMapDao.createSearchBuilder();
|
||||
AccountVlanMapSearch.and("accountId", AccountVlanMapSearch.entity().getAccountId(), SearchCriteria.Op.NULL);
|
||||
ZoneWideNonDedicatedVlanSearch.join("AccountVlanMapSearch", AccountVlanMapSearch, ZoneWideNonDedicatedVlanSearch.entity().getId(), AccountVlanMapSearch.entity().getVlanDbId(), JoinBuilder.JoinType.LEFTOUTER);
|
||||
ZoneWideNonDedicatedVlanSearch.done();
|
||||
AccountVlanMapSearch.done();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -312,4 +323,12 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
|||
sc.setParameters("physicalNetworkId", physicalNetworkId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VlanVO> listZoneWideNonDedicatedVlans(long zoneId) {
|
||||
SearchCriteria<VlanVO> sc = ZoneWideNonDedicatedVlanSearch.create();
|
||||
sc.setParameters("ZoneWideNonDedicatedVlanSearch", "zoneId", zoneId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -581,6 +581,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
|||
VlanType vlanType = VlanType.VirtualNetwork;
|
||||
boolean assign = false;
|
||||
boolean allocateFromDedicatedRange = false;
|
||||
List<Long> dedicatedVlanDbIds = new ArrayList<Long>();
|
||||
List<Long> nonDedicatedVlanDbIds = new ArrayList<Long>();
|
||||
|
||||
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
|
||||
// zone is of type DataCenter. See DataCenterVO.java.
|
||||
|
|
@ -615,18 +617,17 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
|||
txn.start();
|
||||
|
||||
// If account has dedicated Public IP ranges, allocate IP from the dedicated range
|
||||
List<Long> vlanDbIds = new ArrayList<Long>();
|
||||
List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(ipOwner.getId());
|
||||
for (AccountVlanMapVO map : maps) {
|
||||
vlanDbIds.add(map.getVlanDbId());
|
||||
dedicatedVlanDbIds.add(map.getVlanDbId());
|
||||
}
|
||||
if (vlanDbIds != null && !vlanDbIds.isEmpty()) {
|
||||
if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
|
||||
allocateFromDedicatedRange = true;
|
||||
}
|
||||
|
||||
try {
|
||||
if (allocateFromDedicatedRange) {
|
||||
ip = fetchNewPublicIp(zone.getId(), null, vlanDbIds, ipOwner, vlanType, null,
|
||||
ip = fetchNewPublicIp(zone.getId(), null, dedicatedVlanDbIds, ipOwner, vlanType, null,
|
||||
false, assign, null, isSystem, null);
|
||||
}
|
||||
} catch(InsufficientAddressCapacityException e) {
|
||||
|
|
@ -637,12 +638,15 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
|
|||
}
|
||||
|
||||
if (!allocateFromDedicatedRange) {
|
||||
ip = fetchNewPublicIp(zone.getId(), null, null, ipOwner, vlanType, null, false, assign, null,
|
||||
List<VlanVO> nonDedicatedVlans = _vlanDao.listZoneWideNonDedicatedVlans(zone.getId());
|
||||
for (VlanVO nonDedicatedVlan : nonDedicatedVlans) {
|
||||
nonDedicatedVlanDbIds.add(nonDedicatedVlan.getId());
|
||||
}
|
||||
ip = fetchNewPublicIp(zone.getId(), null, nonDedicatedVlanDbIds, ipOwner, vlanType, null, false, assign, null,
|
||||
isSystem, null);
|
||||
}
|
||||
|
||||
if (ip == null) {
|
||||
|
||||
InsufficientAddressCapacityException ex = new InsufficientAddressCapacityException
|
||||
("Unable to find available public IP addresses", DataCenter.class, zone.getId());
|
||||
ex.addProxyObject(ApiDBUtils.findZoneById(zone.getId()).getUuid());
|
||||
|
|
|
|||
Loading…
Reference in New Issue