From 0e13bb58e3c144139a9129ddd15f3269bd305c02 Mon Sep 17 00:00:00 2001 From: Alena Prokharchyk Date: Tue, 24 Jan 2012 12:49:30 -0800 Subject: [PATCH] bug 13250: don't check physicalNetworkId for control traffic type --- .../com/cloud/network/NetworkManagerImpl.java | 52 +++++++++++++++---- .../network/element/VirtualRouterElement.java | 19 ++++--- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 5cb9b390f35..49dd1cc5b88 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -4973,7 +4973,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (pNtwkId == null) { throw new InvalidParameterValueException("Unable to find physical network which match the tags " + tag); } - return pNtwkId; } else { return pNtwks.get(0).getId(); @@ -5207,6 +5206,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public boolean isSecurityGroupSupportedInNetwork(Network network) { + if (network.getTrafficType() != TrafficType.Guest) { + s_logger.trace("Security group can be enabled for Guest networks only; and network " + network + " has a diff traffic type"); + return false; + } + Long physicalNetworkId = network.getPhysicalNetworkId(); //physical network id can be null in Guest Network in Basic zone, so locate the physical network @@ -5558,6 +5562,34 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public String getNetworkTag(HypervisorType hType, Network network) { + //no network tag for control traffic type + if (network.getTrafficType() == TrafficType.Control) { + return null; + } + + Long physicalNetworkId = null; + if (network.getTrafficType() != TrafficType.Guest) { + physicalNetworkId = getNonGuestNetworkPhysicalNetworkId(network); + } else { + NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); + physicalNetworkId = findPhysicalNetworkId(network.getDataCenterId(), offering.getTags()); + } + + if (physicalNetworkId == null) { + assert (false) : "Can't get the physical network"; + s_logger.warn("Can't get the physical network"); + return null; + } + + return _pNTrafficTypeDao.getNetworkTag(physicalNetworkId, network.getTrafficType(), hType); + } + + protected Long getNonGuestNetworkPhysicalNetworkId(Network network) { + //no physical network for control traffic type + if (network.getTrafficType() == TrafficType.Control) { + return null; + } + Long physicalNetworkId = network.getPhysicalNetworkId(); if (physicalNetworkId == null) { @@ -5575,15 +5607,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } } - - if (physicalNetworkId == null) { - assert (false) : "Can't get the physical network"; - s_logger.warn("Can't get the physical network"); - return null; - } - - return _pNTrafficTypeDao.getNetworkTag(physicalNetworkId, network.getTrafficType(), hType); - } + return physicalNetworkId; + } @Override @@ -5681,9 +5706,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag @Override public Long getPhysicalNetworkId(Network network) { + if (network.getTrafficType() != TrafficType.Guest) { + return getNonGuestNetworkPhysicalNetworkId(network); + } + Long physicalNetworkId = network.getPhysicalNetworkId(); + NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); if (physicalNetworkId == null) { - physicalNetworkId = findPhysicalNetworkId(network.getDataCenterId(), null); + physicalNetworkId = findPhysicalNetworkId(network.getDataCenterId(), offering.getTags()); } return physicalNetworkId; } diff --git a/server/src/com/cloud/network/element/VirtualRouterElement.java b/server/src/com/cloud/network/element/VirtualRouterElement.java index b7e183f48a9..8a59a5c9bd6 100644 --- a/server/src/com/cloud/network/element/VirtualRouterElement.java +++ b/server/src/com/cloud/network/element/VirtualRouterElement.java @@ -108,7 +108,12 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @Inject VirtualRouterProviderDao _vrProviderDao; protected boolean canHandle(Network network, Service service) { - if (!_networkMgr.isProviderEnabledInPhysicalNetwork(_networkMgr.getPhysicalNetworkId(network), "VirtualRouter")) { + Long physicalNetworkId = _networkMgr.getPhysicalNetworkId(network); + if (physicalNetworkId == null) { + return false; + } + + if (!_networkMgr.isProviderEnabledInPhysicalNetwork(physicalNetworkId, "VirtualRouter")) { return false; } @@ -144,7 +149,11 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl @Override public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - if (!canHandle(network, null)) { + if (vm.getType() != VirtualMachine.Type.User) { + return false; + } + + if (!canHandle(network, null)) { return false; } @@ -154,11 +163,7 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl } if (!_networkMgr.isProviderEnabledInPhysicalNetwork(_networkMgr.getPhysicalNetworkId(network), "VirtualRouter")) { return false; - } - - if (vm.getType() != VirtualMachine.Type.User) { - return false; - } + } @SuppressWarnings("unchecked") VirtualMachineProfile uservm = (VirtualMachineProfile)vm;