From 10eb2d84119fb37126caf9e77f2547d95df75eaa Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 24 Apr 2012 11:41:37 -0700 Subject: [PATCH] CS-14622: fixed adding vlan range per account - associate it with the Guest network, not public --- .../ConfigurationManagerImpl.java | 2 +- .../src/com/cloud/network/NetworkManager.java | 2 +- .../com/cloud/network/NetworkManagerImpl.java | 20 +++++++++++-------- .../cloud/network/MockNetworkManagerImpl.java | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 908a4ad282a..a2a0f7fc7a1 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -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(); diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java index 6aadf12df1e..d9e9f3ba8c3 100755 --- a/server/src/com/cloud/network/NetworkManager.java +++ b/server/src/com/cloud/network/NetworkManager.java @@ -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); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 57633bc47c7..b56b9547ffe 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -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 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 sourceNat = _ipAddressDao.listByAssociatedNetwork(network.getId(), true); + List 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()); diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java index a8e488407fc..f7fbed134a3 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -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;