Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B38921181A for ; Tue, 26 Aug 2014 09:00:39 +0000 (UTC) Received: (qmail 64057 invoked by uid 500); 26 Aug 2014 09:00:39 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 64025 invoked by uid 500); 26 Aug 2014 09:00:39 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 64005 invoked by uid 99); 26 Aug 2014 09:00:39 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Aug 2014 09:00:39 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 115F8A0130B; Tue, 26 Aug 2014 09:00:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jayapal@apache.org To: commits@cloudstack.apache.org Message-Id: <23554e1c619e40b58d27e1fc5c3cf291@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/master to 384025f Date: Tue, 26 Aug 2014 09:00:39 +0000 (UTC) Repository: cloudstack Updated Branches: refs/heads/master 30ecf935e -> 384025f25 CLOUDSTACK-7218: Remvoing all static nat associated with vm in case of secondary ips In vm secondary ips case static nat configured to vm primary/secondary ips IP1-->vm1Ip1, IP2-->vm1Ip2 While destroying vm deleting all static nats associated with the vm Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/384025f2 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/384025f2 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/384025f2 Branch: refs/heads/master Commit: 384025f258b454726be2556ed10c7e13a241f088 Parents: 30ecf93 Author: Jayapal Authored: Tue Aug 26 10:13:32 2014 +0530 Committer: Jayapal Committed: Tue Aug 26 14:29:23 2014 +0530 ---------------------------------------------------------------------- .../src/com/cloud/network/dao/IPAddressDao.java | 5 +++++ .../com/cloud/network/dao/IPAddressDaoImpl.java | 11 +++++++++++ server/src/com/cloud/vm/UserVmManagerImpl.java | 17 +++++++++-------- 3 files changed, 25 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/384025f2/engine/schema/src/com/cloud/network/dao/IPAddressDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java index fb92cf9..8d60b57 100755 --- a/engine/schema/src/com/cloud/network/dao/IPAddressDao.java +++ b/engine/schema/src/com/cloud/network/dao/IPAddressDao.java @@ -52,6 +52,10 @@ public interface IPAddressDao extends GenericDao { IPAddressVO findByAssociatedVmId(long vmId); + // for vm secondary ips case mapping is IP1--> vmIp1, IP2-->vmIp2, etc + // This method is used when one vm is mapped to muliple to public ips + List findAllByAssociatedVmId(long vmId); + IPAddressVO findByIpAndSourceNetworkId(long networkId, String ipAddress); public IPAddressVO findByIpAndDcId(long dcId, String ipAddress); @@ -79,4 +83,5 @@ public interface IPAddressDao extends GenericDao { boolean deletePublicIPRange(long vlanDbId); void lockRange(long vlandbId); + } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/384025f2/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java index e1530ca..6f6bfd2 100755 --- a/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/engine/schema/src/com/cloud/network/dao/IPAddressDaoImpl.java @@ -263,6 +263,17 @@ public class IPAddressDaoImpl extends GenericDaoBase implemen return findOneBy(sc); } + + // for vm secondary ips case mapping is IP1--> vmIp1, IP2-->vmIp2, etc + // Used when vm is mapped to muliple to public ips + @Override + public List findAllByAssociatedVmId(long vmId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("associatedWithVmId", vmId); + + return listBy(sc); + } + @Override public IPAddressVO findByVmIp(String vmIp) { SearchCriteria sc = AllFieldsSearch.create(); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/384025f2/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index e5de11f..0fbaca8 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -1776,19 +1776,20 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir // If vm is assigned to static nat, disable static nat for the ip // address and disassociate ip if elasticIP is enabled - IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(vmId); - try { - if (ip != null) { + List ips = _ipAddressDao.findAllByAssociatedVmId(vmId); + + for (IPAddressVO ip : ips) { + try { if (_rulesMgr.disableStaticNat(ip.getId(), _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM), User.UID_SYSTEM, true)) { s_logger.debug("Disabled 1-1 nat for ip address " + ip + " as a part of vm id=" + vmId + " expunge"); } else { s_logger.warn("Failed to disable static nat for ip address " + ip + " as a part of vm id=" + vmId + " expunge"); success = false; } + } catch (ResourceUnavailableException e) { + success = false; + s_logger.warn("Failed to disable static nat for ip address " + ip + " as a part of vm id=" + vmId + " expunge because resource is unavailable", e); } - } catch (ResourceUnavailableException e) { - success = false; - s_logger.warn("Failed to disable static nat for ip address " + ip + " as a part of vm id=" + vmId + " expunge because resource is unavailable", e); } return success; @@ -4340,8 +4341,8 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir throw new InvalidParameterValueException("Remove the load balancing rules for this VM before assigning to another user."); } // check for one on one nat - IPAddressVO ip = _ipAddressDao.findByAssociatedVmId(cmd.getVmId()); - if (ip != null) { + List ips = _ipAddressDao.findAllByAssociatedVmId(cmd.getVmId()); + for (IPAddressVO ip : ips) { if (ip.isOneToOneNat()) { throw new InvalidParameterValueException("Remove the one to one nat rule for this VM for ip " + ip.toString()); }