diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index c1ef4281453..be644ad81dd 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -294,5 +294,6 @@ public class ApiConstants { public static final String SERVICE_LIST = "servicelist"; public static final String CAN_ENABLE_INDIVIDUAL_SERVICE = "canenableindividualservice"; public static final String SUPPORTED_SERVICES = "supportedservices"; + public static final String SOURCE_NAT_ENABLED = "sourcenatenabled"; } diff --git a/api/src/com/cloud/api/commands/ListNetworksCmd.java b/api/src/com/cloud/api/commands/ListNetworksCmd.java index 3cc770667d1..412e8d8ed6e 100644 --- a/api/src/com/cloud/api/commands/ListNetworksCmd.java +++ b/api/src/com/cloud/api/commands/ListNetworksCmd.java @@ -72,6 +72,9 @@ public class ListNetworksCmd extends BaseListCmd { @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="list networks by physical network id") private Long physicalNetworkId; + + @Parameter(name=ApiConstants.SOURCE_NAT_ENABLED, type=CommandType.BOOLEAN, description="list networks that support/don't support sourceNat service") + private Boolean sourceNatEnabled; ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// @@ -121,6 +124,10 @@ public class ListNetworksCmd extends BaseListCmd { return physicalNetworkId; } + public Boolean getSourceNatEnabled() { + return sourceNatEnabled; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/com/cloud/network/Network.java b/api/src/com/cloud/network/Network.java index e362ac8ca09..4fefdf0cdb8 100644 --- a/api/src/com/cloud/network/Network.java +++ b/api/src/com/cloud/network/Network.java @@ -110,8 +110,7 @@ public interface Network extends ControlledEntity { */ public static class Provider { private static List supportedProviders = new ArrayList(); - - + public static final Provider VirtualRouter = new Provider("VirtualRouter", false); public static final Provider JuniperSRX = new Provider("JuniperSRX", true); public static final Provider F5BigIp = new Provider("F5BigIp", true); diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index d3d41d33a40..cdc0495bd22 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -2018,6 +2018,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag String path = null; Long sharedNetworkDomainId = null; Long physicalNetworkId = cmd.getPhysicalNetworkId(); + Boolean sourceNatEnabled = cmd.getSourceNatEnabled(); //1) default is system to false if not specified //2) reset parameter to false if it's specified by the regular user @@ -2102,10 +2103,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag sb.and("removed", sb.entity().getRemoved(), Op.NULL); + List networksToReturn = new ArrayList(); if (isSystem == null || !isSystem) { //Get domain level + account/zone level networks - List networksToReturn = new ArrayList(); - if (sharedNetworkDomainId != null) { networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, isDefault, trafficType, isShared, physicalNetworkId), searchFilter, sharedNetworkDomainId)); } else { @@ -2119,11 +2119,25 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag if (!permittedAccounts.isEmpty() || (domainId == null && accountName == null && projectId == null)) { networksToReturn.addAll(listAccountSpecificAndZoneLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, isDefault, trafficType, isShared, physicalNetworkId), searchFilter, path, permittedAccounts)); } - - return networksToReturn; - } else { - return _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, isDefault, trafficType, isShared, physicalNetworkId), searchFilter); + networksToReturn = _networksDao.search(buildNetworkSearchCriteria(sb, keyword, id, isSystem, zoneId, guestIpType, isDefault, trafficType, isShared, physicalNetworkId), searchFilter); + } + + //sort networks by sourceNatEnabled parameter + if (sourceNatEnabled != null) { + List supportedNetworks = new ArrayList(); + + for (Network network : networksToReturn) { + NetworkOffering offering = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); + boolean isSupported = areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat); + if (isSupported == sourceNatEnabled.booleanValue()) { + supportedNetworks.add(network); + } + } + + return supportedNetworks; + } else { + return networksToReturn; } } diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java index 4bf7a339100..fbc7c5df477 100644 --- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java +++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java @@ -75,17 +75,9 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru { NetworkOfferingDao _networkOfferingDao; protected boolean canHandle(NetworkOffering offering, DataCenter dc) { - // this guru handles only non-system network with: - //1) type=Shared - //2) type=Isolated and Source nat service disabled - //TODO - after broadCastDomainType + physical network are introduced, don't rely on network type of the dc + // this guru handles only Guest networks in Advance zone with source nat service disabled if (dc.getNetworkType() == NetworkType.Advanced && !_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)&& offering.getTrafficType() == TrafficType.Guest) { - if (_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SecurityGroup)) { - return true; - } else if (!offering.isSystemOnly()) { - return true; - } - return false; + return true; } else { s_logger.trace("We only take care of Guest Direct networks"); return false; diff --git a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java index 1760f20f36d..33d4d4f95b8 100644 --- a/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/ExternalGuestNetworkGuru.java @@ -80,7 +80,6 @@ public class ExternalGuestNetworkGuru extends GuestNetworkGuru { @Override public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) { - if (_ovsNetworkMgr.isOvsNetworkEnabled() || _tunnelMgr.isOvsTunnelEnabled()) { return null; } diff --git a/server/src/com/cloud/network/guru/GuestNetworkGuru.java b/server/src/com/cloud/network/guru/GuestNetworkGuru.java index 4019c33a461..2d9c804ba47 100644 --- a/server/src/com/cloud/network/guru/GuestNetworkGuru.java +++ b/server/src/com/cloud/network/guru/GuestNetworkGuru.java @@ -79,11 +79,11 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru { } protected boolean canHandle(NetworkOffering offering, DataCenter dc) { - // This guru handles only non-system Guest Isolated network that supports Source nat service - if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && offering.getGuestType() == Network.GuestType.Isolated && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat) && !offering.isSystemOnly()) { + // This guru handles only Guest Isolated network that supports Source nat service + if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && offering.getGuestType() == Network.GuestType.Isolated && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)) { return true; } else { - s_logger.trace("We only take care of Guest Virtual networks in zone of type " + NetworkType.Advanced); + s_logger.trace("We only take care of Guest networks with service " + Service.SourceNat + " enabled in zone of type " + NetworkType.Advanced); return false; } }