CS-14622: fixed adding vlan range per account - associate it with the Guest network, not public

This commit is contained in:
Alena Prokharchyk 2012-04-24 11:41:37 -07:00
parent e1e67b40ec
commit 10eb2d8411
4 changed files with 15 additions and 11 deletions

View File

@ -2276,7 +2276,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
Vlan vlan = createVlanAndPublicIpRange(userId, zoneId, podId, startIP, endIP, vlanGateway, vlanNetmask, forVirtualNetwork, vlanId, account, networkId, physicalNetworkId);
if (associateIpRangeToAccount) {
_networkMgr.associateIpAddressListToAccount(userId, account.getId(), zoneId, vlan.getId(), network);
_networkMgr.associateIpAddressListToAccount(userId, account.getId(), zoneId, vlan.getId(), null);
}
txn.commit();

View File

@ -177,7 +177,7 @@ public interface NetworkManager extends NetworkService {
* @throws InsufficientAddressCapacityException
* @throws
*/
boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network networkToAssociateWith) throws InsufficientCapacityException, ConcurrentOperationException,
boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network guestNetwork) throws InsufficientCapacityException, ConcurrentOperationException,
ResourceUnavailableException, ResourceAllocationException;
Nic getNicInNetwork(long vmId, long networkId);

View File

@ -3572,21 +3572,25 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
@DB
public boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network network) throws InsufficientCapacityException, ConcurrentOperationException,
public boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network guestNetwork)
throws InsufficientCapacityException, ConcurrentOperationException,
ResourceUnavailableException, ResourceAllocationException {
Account owner = _accountMgr.getActiveAccountById(accountId);
boolean createNetwork = false;
if (guestNetwork != null && guestNetwork.getTrafficType() != TrafficType.Guest) {
throw new InvalidParameterValueException("Network " + guestNetwork + " is not of a type " + TrafficType.Guest);
}
Transaction txn = Transaction.currentTxn();
txn.start();
if (network == null) {
if (guestNetwork == null) {
List<? extends Network> networks = getIsolatedNetworksWithSourceNATOwnedByAccountInZone(zoneId, owner);
if (networks.size() == 0) {
createNetwork = true;
} else if (networks.size() == 1) {
network = networks.get(0);
guestNetwork = networks.get(0);
}else{
throw new InvalidParameterValueException("Error, more than 1 Guest Isolated Networks with SourceNAT service enabled found for this account, cannot assosiate the IP range, please provide the network ID");
}
@ -3602,9 +3606,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) {
s_logger.debug("Creating network for account " + owner + " from the network offering id=" + requiredOfferings.get(0).getId() + " as a part of createVlanIpRange process");
network = createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null, null, null, owner, false, null, physicalNetwork, zoneId,
guestNetwork = createGuestNetwork(requiredOfferings.get(0).getId(), owner.getAccountName() + "-network", owner.getAccountName() + "-network", null, null, null, null, owner, false, null, physicalNetwork, zoneId,
ACLType.Account, null);
if (network == null) {
if (guestNetwork == null) {
s_logger.warn("Failed to create default Virtual network for the account " + accountId + "in zone " + zoneId);
throw new CloudRuntimeException("Failed to create a Guest Isolated Networks with SourceNAT service enabled as a part of createVlanIpRange, for the account " + accountId + "in zone " + zoneId);
}
@ -3615,7 +3619,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
// Check if there is a source nat ip address for this account; if not - we have to allocate one
boolean allocateSourceNat = false;
List<IPAddressVO> sourceNat = _ipAddressDao.listByAssociatedNetwork(network.getId(), true);
List<IPAddressVO> sourceNat = _ipAddressDao.listByAssociatedNetwork(guestNetwork.getId(), true);
if (sourceNat.isEmpty()) {
allocateSourceNat = true;
}
@ -3631,7 +3635,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
} else {
addr.setSourceNat(false);
}
addr.setAssociatedWithNetworkId(network.getId());
addr.setAssociatedWithNetworkId(guestNetwork.getId());
addr.setAllocatedTime(new Date());
addr.setAllocatedInDomainId(owner.getDomainId());
addr.setAllocatedToAccountId(owner.getId());

View File

@ -317,7 +317,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
}
@Override
public boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network networkToAssociateWith) throws InsufficientCapacityException,
public boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId, Network guestNetwork) throws InsufficientCapacityException,
ConcurrentOperationException, ResourceUnavailableException, ResourceAllocationException {
// TODO Auto-generated method stub
return false;