AssociateIPAddress - first IP associated with the network should always be a source nat

This commit is contained in:
alena 2011-03-24 14:23:35 -07:00
parent 6e60539427
commit a2619b902f
3 changed files with 20 additions and 5 deletions

View File

@ -93,9 +93,10 @@ public interface NetworkManager extends NetworkService {
* @param accountId - account that the IP address should belong to * @param accountId - account that the IP address should belong to
* @param dcId - zone that the IP address should belong to * @param dcId - zone that the IP address should belong to
* @param sourceNat - (optional) true if the IP address should be a source NAT address * @param sourceNat - (optional) true if the IP address should be a source NAT address
* @param associatedNetworkId TODO
* @return - list of IP addresses * @return - list of IP addresses
*/ */
List<IPAddressVO> listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat); List<IPAddressVO> listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId);
List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isShared, boolean isDefault) throws ConcurrentOperationException; List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isShared, boolean isDefault) throws ConcurrentOperationException;
List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isShared, boolean isDefault, boolean errorIfAlreadySetup, Long domainId) throws ConcurrentOperationException; List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isShared, boolean isDefault, boolean errorIfAlreadySetup, Long domainId) throws ConcurrentOperationException;

View File

@ -333,7 +333,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
} }
IPAddressVO sourceNat = null; IPAddressVO sourceNat = null;
List<IPAddressVO> addrs = listPublicIpAddressesInVirtualNetwork(ownerId, dcId, null); List<IPAddressVO> addrs = listPublicIpAddressesInVirtualNetwork(ownerId, dcId, null, network.getId());
if (addrs.size() == 0) { if (addrs.size() == 0) {
// Check that the maximum number of public IPs for the given accountId will not be exceeded // Check that the maximum number of public IPs for the given accountId will not be exceeded
if (_accountMgr.resourceLimitExceeded(owner, ResourceType.public_ip)) { if (_accountMgr.resourceLimitExceeded(owner, ResourceType.public_ip)) {
@ -544,9 +544,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
rae.setResourceType("ip"); rae.setResourceType("ip");
throw rae; throw rae;
} }
boolean isSourceNat = false;
txn.start(); txn.start();
ip = fetchNewPublicIp(zoneId, null, null, ipOwner, VlanType.VirtualNetwork, network.getId(), false, false); //First IP address should be source nat
List<IPAddressVO> addrs = listPublicIpAddressesInVirtualNetwork(ownerId, zoneId, true, networkId);
if (addrs.isEmpty()) {
isSourceNat = true;
}
ip = fetchNewPublicIp(zoneId, null, null, ipOwner, VlanType.VirtualNetwork, network.getId(), isSourceNat, false);
if (ip == null) { if (ip == null) {
throw new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zoneId); throw new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zoneId);
@ -758,6 +767,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
IpAddressSearch = _ipAddressDao.createSearchBuilder(); IpAddressSearch = _ipAddressDao.createSearchBuilder();
IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ); IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ);
IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ); IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ);
IpAddressSearch.and("associatedWithNetworkId", IpAddressSearch.entity().getAssociatedWithNetworkId(), Op.EQ);
SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder(); SearchBuilder<VlanVO> virtualNetworkVlanSB = _vlanDao.createSearchBuilder();
virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ); virtualNetworkVlanSB.and("vlanType", virtualNetworkVlanSB.entity().getVlanType(), Op.EQ);
IpAddressSearch.join("virtualNetworkVlanSB", virtualNetworkVlanSB, IpAddressSearch.entity().getVlanId(), virtualNetworkVlanSB.entity().getId(), JoinBuilder.JoinType.INNER); IpAddressSearch.join("virtualNetworkVlanSB", virtualNetworkVlanSB, IpAddressSearch.entity().getVlanId(), virtualNetworkVlanSB.entity().getId(), JoinBuilder.JoinType.INNER);
@ -797,10 +807,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
} }
@Override @Override
public List<IPAddressVO> listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat) { public List<IPAddressVO> listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat, Long associatedNetworkId) {
SearchCriteria<IPAddressVO> sc = IpAddressSearch.create(); SearchCriteria<IPAddressVO> sc = IpAddressSearch.create();
sc.setParameters("accountId", accountId); sc.setParameters("accountId", accountId);
sc.setParameters("dataCenterId", dcId); sc.setParameters("dataCenterId", dcId);
if (associatedNetworkId != null) {
sc.setParameters("associatedWithNetworkId", associatedNetworkId);
}
if (sourceNat != null) { if (sourceNat != null) {
sc.addAnd("sourceNat", SearchCriteria.Op.EQ, sourceNat); sc.addAnd("sourceNat", SearchCriteria.Op.EQ, sourceNat);
} }

View File

@ -1006,7 +1006,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
long zoneId = router.getDataCenterId(); long zoneId = router.getDataCenterId();
final List<IPAddressVO> userIps = _networkMgr.listPublicIpAddressesInVirtualNetwork(ownerId, zoneId, null); final List<IPAddressVO> userIps = _networkMgr.listPublicIpAddressesInVirtualNetwork(ownerId, zoneId, null, null);
List<PublicIpAddress> publicIps = new ArrayList<PublicIpAddress>(); List<PublicIpAddress> publicIps = new ArrayList<PublicIpAddress>();
if (userIps != null && !userIps.isEmpty()) { if (userIps != null && !userIps.isEmpty()) {
for (IPAddressVO userIp : userIps) { for (IPAddressVO userIp : userIps) {