From 8871cdc03a4009b309fde6d9baa4f9d5e89f7ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Will=C2=A0Stevens=C2=A0?= Date: Wed, 30 Oct 2013 10:14:14 -0700 Subject: [PATCH] Add support for multiple networks in the 'per account' source nat type setting in external network devices Signed-off-by: Sheng Yang --- .../ExternalFirewallDeviceManagerImpl.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java index fa171ab273a..b0e1b39b870 100644 --- a/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalFirewallDeviceManagerImpl.java @@ -434,17 +434,20 @@ public abstract class ExternalFirewallDeviceManagerImpl extends AdapterBase impl IPAddressVO sourceNatIp = null; if (!sharedSourceNat) { - // Get the source NAT IP address for this account + // Get the source NAT IP address for this network List sourceNatIps = _networkModel.listPublicIpsAssignedToAccount(network.getAccountId(), zoneId, true); - if (sourceNatIps.size() != 1) { - String errorMsg = "External firewall was unable to find the source NAT IP address for account " - + account.getAccountName(); + for (IpAddress ipAddress : sourceNatIps) { + if (ipAddress.getAssociatedWithNetworkId().longValue() == network.getId()) { + sourceNatIp = _ipAddressDao.findById(ipAddress.getId()); + break; + } + } + if (sourceNatIp == null) { + String errorMsg = "External firewall was unable to find the source NAT IP address for network " + network.getName(); s_logger.error(errorMsg); return true; - } else { - sourceNatIp = _ipAddressDao.findById(sourceNatIps.get(0).getId()); } }