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 895a27c
Date Mon, 13 May 2013 09:45:42 GMT
Updated Branches:
  refs/heads/portablepublicip 51509751b -> 895a27c27


- establish model for transferring portable IP association from a network
  with which it is associated to another network.

- enabling static nat api, extended to transfer potrtable IP across the
  networks if the VM/network is different from the current associate
  network of the portable ip


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

Branch: refs/heads/portablepublicip
Commit: 895a27c2771dbb497ecc6fe0d212589f012a48d8
Parents: 5150975
Author: Murali Reddy <muralimmreddy@gmail.com>
Authored: Mon May 13 15:12:19 2013 +0530
Committer: Murali Reddy <muralimmreddy@gmail.com>
Committed: Mon May 13 15:12:19 2013 +0530

----------------------------------------------------------------------
 .../api/command/user/nat/EnableStaticNatCmd.java   |    5 ++
 server/src/com/cloud/network/NetworkManager.java   |    2 +
 .../src/com/cloud/network/NetworkManagerImpl.java  |   27 ++++++++++++
 .../com/cloud/network/rules/RulesManagerImpl.java  |   33 +++++++++++++++
 .../com/cloud/network/MockNetworkManagerImpl.java  |    5 ++
 .../test/com/cloud/vpc/MockNetworkManagerImpl.java |    5 ++
 6 files changed, 77 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/895a27c2/api/src/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java b/api/src/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java
index 902dbae..f78e544 100644
--- a/api/src/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/nat/EnableStaticNatCmd.java
@@ -91,6 +91,11 @@ public class EnableStaticNatCmd extends BaseCmd{
         } else {
             ntwkId = networkId;
         }
+
+        if (ip.isPortable() && networkId!= null ) {
+            ntwkId = networkId;
+        }
+
         if (ntwkId == null) {
             throw new InvalidParameterValueException("Unable to enable static nat for the
ipAddress id=" + ipAddressId +
                     " as ip is not associated with any network and no networkId is passed
in");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/895a27c2/server/src/com/cloud/network/NetworkManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManager.java b/server/src/com/cloud/network/NetworkManager.java
index 2bb40c8..9a11a3f 100755
--- a/server/src/com/cloud/network/NetworkManager.java
+++ b/server/src/com/cloud/network/NetworkManager.java
@@ -245,6 +245,8 @@ public interface NetworkManager  {
     IPAddressVO disassociatePortableIPToGuestNetwork(long ipAddrId, long networkId) throws
ResourceAllocationException, ResourceUnavailableException,
             InsufficientAddressCapacityException, ConcurrentOperationException;
 
+    boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId);
+
     /**
      * @param network
      * @param provider

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/895a27c2/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 cac6bf2..aaade3c 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -990,6 +990,33 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
     }
 
     @Override
+    public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) {
+        Network network = _networksDao.findById(networkId);
+        if (network == null) {
+            throw new InvalidParameterValueException("Invalid network id is given");
+        }
+
+        IPAddressVO ip = _ipAddressDao.findById(ipAddrId);
+        if (ip == null) {
+            throw new InvalidParameterValueException("Invalid network id is given");
+        }
+
+        // Check if IP has any services (rules) associated in the network
+        List<PublicIpAddress> ipList = new ArrayList<PublicIpAddress>();
+        PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
+        ipList.add(publicIp);
+        Map<PublicIpAddress, Set<Service>> ipToServices = _networkModel.getIpToServices(ipList,
false, true);
+        if (ipToServices != null & !ipToServices.isEmpty()) {
+            Set<Service> ipServices = ipToServices.get(publicIp);
+            if (ipServices != null && !ipServices.isEmpty()) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
     @DB
     public boolean disassociatePublicIpAddress(long addrId, long userId, Account caller)
{
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/895a27c2/server/src/com/cloud/network/rules/RulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/rules/RulesManagerImpl.java b/server/src/com/cloud/network/rules/RulesManagerImpl.java
index c9b47b4..1c24ee5 100755
--- a/server/src/com/cloud/network/rules/RulesManagerImpl.java
+++ b/server/src/com/cloud/network/rules/RulesManagerImpl.java
@@ -492,6 +492,39 @@ public class RulesManagerImpl extends ManagerBase implements RulesManager,
Rules
                         }
                         performedIpAssoc = true;
                     }
+
+                    if (ipAddress.isPortable()) {
+                        s_logger.info("Portable IP " + ipAddress.getUuid() + " is not associated
with the network, so" +
+                                "associated IP with the network " + network.getUuid());
+                        try {
+                            _networkMgr.associatePortableIPToGuestNetwork(ipId, networkId,
false);
+                        } catch (Exception e) {
+                            s_logger.warn("Failed to associate portable id=" + ipId + " to
network id=" + networkId + " as " +
+                                    "a part of enable static nat");
+                            return false;
+                        }
+                    }
+                } else  if (ipAddress.getAssociatedWithNetworkId() != networkId) {
+                    if (ipAddress.isPortable()) {
+                        // check if portable IP can transferred across the network
+                        if (_networkMgr.isPortableIpTransferableFromNetwork(ipId, ipAddress.getAssociatedWithNetworkId()
)) {
+                            try {
+                                _networkMgr.disassociatePortableIPToGuestNetwork(ipId, ipAddress.getAssociatedWithNetworkId());
+                                _networkMgr.associatePortableIPToGuestNetwork(ipId, networkId,
false);
+                            } catch (Exception e) {
+                                s_logger.warn("Failed to associate portable id=" + ipId +
" to network id=" + networkId + " as " +
+                                        "a part of enable static nat");
+                                return false;
+                            }
+                        } else {
+                            throw new InvalidParameterValueException("Portable IP: " + ipId
+ " has associated services" +
+                                    "in network " + ipAddress.getAssociatedWithNetworkId()
+ " so can not be transferred to " +
+                                    " network " + networkId);
+                        }
+                    } else {
+                        throw new InvalidParameterValueException("Invalid network Id=" +
networkId + " IP is associated with"
+                            + " a different network than passed network id");
+                    }
                 } else {
                     _networkModel.checkIpForService(ipAddress, Service.StaticNat, null);
                 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/895a27c2/server/test/com/cloud/network/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/network/MockNetworkManagerImpl.java b/server/test/com/cloud/network/MockNetworkManagerImpl.java
index c521058..29493b0 100755
--- a/server/test/com/cloud/network/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/network/MockNetworkManagerImpl.java
@@ -98,6 +98,11 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
     }
 
     @Override
+    public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) {
+        return false;
+    }
+
+    @Override
     public boolean releaseIpAddress(long ipAddressId) {
         // TODO Auto-generated method stub
         return false;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/895a27c2/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
index c770000..345106c 100644
--- a/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
+++ b/server/test/com/cloud/vpc/MockNetworkManagerImpl.java
@@ -213,6 +213,11 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
         return false;// TODO Auto-generated method stub
     }
 
+    @Override
+    public boolean isPortableIpTransferableFromNetwork(long ipAddrId, long networkId) {
+        return false;
+    }
+
     /* (non-Javadoc)
     * @see com.cloud.network.NetworkService#releaseIpAddress(long)
     */


Mime
View raw message