You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ya...@apache.org on 2013/02/01 02:17:24 UTC

git commit: refs/heads/network-refactor - IPv6: Fix generate random ip in range.

Updated Branches:
  refs/heads/network-refactor 2ca8af319 -> bec030fda


IPv6: Fix generate random ip in range.

Ported from ipv6 branch.


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

Branch: refs/heads/network-refactor
Commit: bec030fda858ad853fe4094b0d1f6f7e83ae7b9d
Parents: 2ca8af3
Author: Sheng Yang <sh...@citrix.com>
Authored: Thu Jan 31 17:16:53 2013 -0800
Committer: Sheng Yang <sh...@citrix.com>
Committed: Thu Jan 31 17:16:53 2013 -0800

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkManagerImpl.java  |   19 +++++++++++----
 1 files changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bec030fd/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 dd61715..1239110 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -302,11 +302,20 @@ public class NetworkManagerImpl implements NetworkManager, Manager, Listener {
     		s_logger.debug("Cannot find related vlan or too many vlan attached to network " + networkId);
     		return null;
     	}
-    	String ip = NetUtils.getIp6FromRange(vlan.getIp6Range());
-    	//Check for duplicate IP
-    	if (_ipv6Dao.findByDcIdAndIp(dcId, ip) != null) {
-    		//TODO regenerate ip
-    		throw new CloudRuntimeException("Fail to get unique ipv6 address");
+    	String ip = null;
+    	int count = 0;
+    	while (ip == null || count >= 10) {
+    		ip = NetUtils.getIp6FromRange(vlan.getIp6Range());
+    		//Check for duplicate IP
+    		if (_ipv6Dao.findByDcIdAndIp(dcId, ip) == null) {
+    			break;
+    		} else {
+    			ip = null;
+    		}
+    		count ++;
+    	}
+    	if (ip == null) {
+    		throw new CloudRuntimeException("Fail to get unique ipv6 address after 10 times trying!");
     	}
     	DataCenterVO dc = _dcDao.findById(dcId);
         Long mac = dc.getMacAddress();