From a678988f33943d95cf1aacf1741cfed1138bc20a 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 Conflicts: server/src/com/cloud/configuration/ConfigurationManagerImpl.java server/test/com/cloud/network/MockNetworkManagerImpl.java --- .../ConfigurationManagerImpl.java | 2 +- .../src/com/cloud/network/NetworkManager.java | 2 +- .../com/cloud/network/NetworkManagerImpl.java | 20 +++++++++++-------- .../cloud/network/MockNetworkManagerImpl.java | 9 +++++++++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 4f9560198ec..d2bbb91e8d9 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2195,7 +2195,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura Vlan vlan = createVlanAndPublicIpRange(zoneId, networkId, physicalNetworkId, forVirtualNetwork, podId, startIP, endIP, vlanGateway, vlanNetmask, vlanId, vlanOwner); if (associateIpRangeToAccount) { - _networkMgr.associateIpAddressListToAccount(userId, vlanOwner.getId(), zoneId, vlan.getId(), network); + _networkMgr.associateIpAddressListToAccount(userId, vlanOwner.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 c53985a95ee..daf2d61d3ac 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 49b4d30bed6..da490f70348 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -3684,21 +3684,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"); } @@ -3714,9 +3718,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); } @@ -3727,7 +3731,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; } @@ -3743,7 +3747,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 8bf3421ae3f..54c3025c10f 100755 --- a/server/test/com/cloud/network/MockNetworkManagerImpl.java +++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java @@ -861,4 +861,13 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS return null; } + /* (non-Javadoc) + * @see com.cloud.network.NetworkManager#listAllNetworksInAllZonesByType(com.cloud.network.Network.GuestType) + */ + @Override + public List listAllNetworksInAllZonesByType(GuestType type) { + // TODO Auto-generated method stub + return null; + } + }