cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From muralire...@apache.org
Subject git commit: updated refs/heads/portablepublicip to bd058f5
Date Sun, 12 May 2013 17:22:50 GMT
Updated Branches:
  refs/heads/portablepublicip 27504d909 -> bd058f58c


enhance disasociateIPAddr API to release protable IP associated with a
guest network or VPC


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/bd058f58
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bd058f58
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bd058f58

Branch: refs/heads/portablepublicip
Commit: bd058f58c2d8d36ec25e31ed9de4cd414e0ca051
Parents: 27504d9
Author: Murali Reddy <muralimmreddy@gmail.com>
Authored: Sun May 12 21:14:48 2013 +0530
Committer: Murali Reddy <muralimmreddy@gmail.com>
Committed: Sun May 12 21:14:48 2013 +0530

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkManagerImpl.java  |   30 +++++++++++++++
 .../src/com/cloud/network/NetworkServiceImpl.java  |    4 +-
 .../apache/cloudstack/region/PortableIpDao.java    |    4 ++
 .../cloudstack/region/PortableIpDaoImpl.java       |   26 +++++++++++++
 .../org/apache/cloudstack/region/PortableIpVO.java |    2 +-
 5 files changed, 64 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd058f58/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 44a60f0..03c606b 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -940,12 +940,42 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         }
 
         if (success) {
+            if (ip.isPortable()) {
+                releasePortableIpAddress(addrId);
+            }
             s_logger.debug("Released a public ip id=" + addrId);
         }
 
         return success;
     }
 
+    @DB
+    private void releasePortableIpAddress(long addrId) {
+        Transaction txn = Transaction.currentTxn();
+        GlobalLock portableIpLock = GlobalLock.getInternLock("PortablePublicIpRange");
+
+        txn.start();
+        try {
+            portableIpLock.lock(5);
+            IPAddressVO ip = _ipAddressDao.findById(addrId);
+
+            // unassign portable IP
+            PortableIpVO portableIp = _portableIpDao.findByIpAddress(ip.getAddress().addr());
+            _portableIpDao.unassignIpAddress(portableIp.getId());
+
+            // removed the provisioned vlan
+            VlanVO vlan = _vlanDao.findById(ip.getVlanId());
+            _vlanDao.expunge(vlan.getId());
+
+            // remove the provisioned public ip address
+            _ipAddressDao.expunge(ip.getId());
+
+            txn.commit();
+        } finally {
+            portableIpLock.releaseRef();
+        }
+    }
+
     @Override
     @DB
     public boolean configure(final String name, final Map<String, Object> params) throws
ConfigurationException {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd058f58/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 1e6aca4..e67026c 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -846,6 +846,9 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
         boolean success = _networkMgr.disassociatePublicIpAddress(ipAddressId, userId, caller);
 
         if (success) {
+            if (!ipVO.isPortable()) {
+                return success;
+            }
             Long networkId = ipVO.getAssociatedWithNetworkId();
             if (networkId != null) {
                 Network guestNetwork = getNetwork(networkId);
@@ -862,7 +865,6 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
         return success;
     }
 
-
     @Override
     @DB
     public Network getNetwork(long id) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd058f58/server/src/org/apache/cloudstack/region/PortableIpDao.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/PortableIpDao.java b/server/src/org/apache/cloudstack/region/PortableIpDao.java
index ca6ca14..9f5341f 100755
--- a/server/src/org/apache/cloudstack/region/PortableIpDao.java
+++ b/server/src/org/apache/cloudstack/region/PortableIpDao.java
@@ -32,4 +32,8 @@ public interface PortableIpDao  extends GenericDao<PortableIpVO, Long>
{
     List<PortableIpVO> listByRangeIdAndState(long rangeId, PortableIp.State state);
 
     List<PortableIpVO> listByRegionIdAndState(int regionId, PortableIp.State state);
+
+    PortableIpVO findByIpAddress(String ipAddress);
+
+    void unassignIpAddress(long ipAddressId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd058f58/server/src/org/apache/cloudstack/region/PortableIpDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/PortableIpDaoImpl.java b/server/src/org/apache/cloudstack/region/PortableIpDaoImpl.java
index fb813a9..488761b 100755
--- a/server/src/org/apache/cloudstack/region/PortableIpDaoImpl.java
+++ b/server/src/org/apache/cloudstack/region/PortableIpDaoImpl.java
@@ -52,6 +52,7 @@ public class PortableIpDaoImpl extends GenericDaoBase<PortableIpVO, Long>
implem
     private final SearchBuilder<PortableIpVO> listByRangeIDSearch;
     private final SearchBuilder<PortableIpVO> listByRangeIDAndStateSearch;
     private final SearchBuilder<PortableIpVO> listByRegionIDAndStateSearch;
+    private final SearchBuilder<PortableIpVO> findByIpAddressSearch;
 
     public PortableIpDaoImpl() {
         listByRegionIDSearch = createSearchBuilder();
@@ -71,6 +72,10 @@ public class PortableIpDaoImpl extends GenericDaoBase<PortableIpVO,
Long> implem
         listByRegionIDAndStateSearch.and("regionId", listByRegionIDAndStateSearch.entity().getRangeId(),
SearchCriteria.Op.EQ);
         listByRegionIDAndStateSearch.and("state", listByRegionIDAndStateSearch.entity().getState(),
SearchCriteria.Op.EQ);
         listByRegionIDAndStateSearch.done();
+
+        findByIpAddressSearch = createSearchBuilder();
+        findByIpAddressSearch.and("address", findByIpAddressSearch.entity().getAddress(),
SearchCriteria.Op.EQ);
+        findByIpAddressSearch.done();
     }
 
     @Override
@@ -102,4 +107,25 @@ public class PortableIpDaoImpl extends GenericDaoBase<PortableIpVO,
Long> implem
         sc.setParameters("state", state);
         return listBy(sc);
     }
+
+    @Override
+    public PortableIpVO findByIpAddress(String ipAddress) {
+        SearchCriteria<PortableIpVO> sc = findByIpAddressSearch.create();
+        sc.setParameters("address", ipAddress);
+        return findOneBy(sc);
+    }
+
+    @Override
+    public void unassignIpAddress(long ipAddressId) {
+        PortableIpVO address = createForUpdate();
+        address.setAllocatedToAccountId(null);
+        address.setAllocatedInDomainId(null);
+        address.setAllocatedTime(null);
+        address.setState(PortableIp.State.Free);
+        address.setAssociatedWithNetworkId(null);
+        address.setAssociatedDataCenterId(null);
+        address.setAssociatedWithVpcId(null);
+        address.setPhysicalNetworkId(null);
+        update(ipAddressId, address);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bd058f58/server/src/org/apache/cloudstack/region/PortableIpVO.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/region/PortableIpVO.java b/server/src/org/apache/cloudstack/region/PortableIpVO.java
index 61ea870..9a63009 100644
--- a/server/src/org/apache/cloudstack/region/PortableIpVO.java
+++ b/server/src/org/apache/cloudstack/region/PortableIpVO.java
@@ -68,7 +68,7 @@ public class PortableIpVO  implements PortableIp  {
     private Long physicalNetworkId;
 
     @Column(name="data_center_id")
-    private long dataCenterId;
+    private Long dataCenterId;
 
     @Column(name="network_id")
     private Long networkId;


Mime
View raw message