cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [42/51] [abbrv] git commit: refs/heads/vim51_win8 - Fix the situation where only a gateway and a netmask is passed with the createNetwork command.
Date Tue, 05 Feb 2013 18:06:57 GMT
Fix the situation where only a gateway and a netmask is passed with the
createNetwork command.

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

Branch: refs/heads/vim51_win8
Commit: f8a22d7520b5a741df78ccb42926ef864f03b776
Parents: 6b3da5f
Author: Hugo Trippaers <htrippaers@schubergphilis.com>
Authored: Mon Feb 4 15:07:12 2013 +0100
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Mon Feb 4 15:08:53 2013 +0100

----------------------------------------------------------------------
 .../src/com/cloud/network/NetworkServiceImpl.java  |   42 ++++++++-------
 1 files changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/f8a22d75/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 8eeb16c..235762e 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -16,6 +16,9 @@
 // under the License.
 package com.cloud.network;
 
+import java.net.InetAddress;
+import java.net.Inet6Address;
+import java.net.UnknownHostException;
 import java.security.InvalidParameterException;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -72,20 +75,6 @@ import com.cloud.network.Networks.TrafficType;
 import com.cloud.network.PhysicalNetwork.BroadcastDomainRange;
 import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
 import com.cloud.network.addr.PublicIp;
-import com.cloud.network.dao.FirewallRulesDao;
-import com.cloud.network.dao.IPAddressDao;
-import com.cloud.network.dao.IPAddressVO;
-import com.cloud.network.dao.NetworkDao;
-import com.cloud.network.dao.NetworkDomainDao;
-import com.cloud.network.dao.NetworkDomainVO;
-import com.cloud.network.dao.NetworkServiceMapDao;
-import com.cloud.network.dao.NetworkVO;
-import com.cloud.network.dao.PhysicalNetworkDao;
-import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
-import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
-import com.cloud.network.dao.PhysicalNetworkTrafficTypeDao;
-import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO;
-import com.cloud.network.dao.PhysicalNetworkVO;
 import com.cloud.network.dao.*;
 import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.VirtualRouterElement;
@@ -116,11 +105,6 @@ import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Filter;
-import com.cloud.utils.db.JoinBuilder;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.*;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.exception.CloudRuntimeException;
@@ -717,7 +701,7 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
 
         UserContext.current().setAccountId(owner.getAccountId());
 
-        boolean ipv4 = false, ipv6 = false;
+        boolean ipv4 = true, ipv6 = false;
         if (startIP != null) {
         	ipv4 = true;
         }
@@ -725,6 +709,24 @@ public class NetworkServiceImpl extends ManagerBase implements  NetworkService
{
         	ipv6 = true;
         }
         
+        if (gateway != null) {
+        	try {
+        		// getByName on a literal representation will only check validity of the address
+        		// http://docs.oracle.com/javase/6/docs/api/java/net/InetAddress.html#getByName(java.lang.String)
+        		InetAddress gatewayAddress = InetAddress.getByName(gateway);
+        		if (gatewayAddress instanceof Inet6Address) {
+        			ipv6 = true;
+        		} else {
+        			ipv4 = true;
+        		}
+        	}
+        	catch (UnknownHostException e) {
+        		s_logger.error("Unable to convert gateway IP to a InetAddress", e);
+        		throw new InvalidParameterValueException("Gateway parameter is invalid");
+        	}
+        }
+        
+        
         String cidr = null;
         if (ipv4) {
         	// if end ip is not specified, default it to startIp


Mime
View raw message