You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2014/01/03 11:17:36 UTC

[03/50] [abbrv] git commit: updated refs/heads/opendaylight to 858fb69

isSameIsolationId


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

Branch: refs/heads/opendaylight
Commit: 2cf356e047e26977c1d294fafc57e986c04fc5f4
Parents: 04570ee
Author: Daan Hoogland <dh...@schubergphilis.com>
Authored: Tue Dec 31 12:25:17 2013 +0100
Committer: Daan Hoogland <dh...@schubergphilis.com>
Committed: Tue Dec 31 12:25:17 2013 +0100

----------------------------------------------------------------------
 .../configuration/ConfigurationManagerImpl.java | 21 ++++++++++----------
 utils/src/com/cloud/utils/net/NetUtils.java     |  4 ++--
 .../test/com/cloud/utils/net/NetUtilsTest.java  |  6 ++++++
 3 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2cf356e0/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 645c31a..ee7a660 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2378,7 +2378,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
         String newVlanNetmask = cmd.getNetmask();
         String vlanId = cmd.getVlan();
         // TODO decide if we should be forgiving or demand a valid and complete URI
-        if(Vlan.UNTAGGED.equalsIgnoreCase(vlanId))
+        if (NetUtils.isSameIsolationId(Vlan.UNTAGGED, vlanId))
             vlanId = null;
         if (!((vlanId == null) || ("".equals(vlanId)) || vlanId.startsWith(BroadcastDomainType.Vlan.scheme())))
             vlanId = BroadcastDomainType.Vlan.toUri(vlanId).toString();
@@ -2556,9 +2556,9 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
                     VlanVO vlan = vlans.get(0);
                     if (vlanId == null) {
                         vlanId = vlan.getVlanTag();
-                    } else if (!vlan.getVlanTag().equals(vlanId)) {
-                        throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag() + " on network :" + +network.getId() +
-                            ", only one vlan is allowed on guest network");
+                    } else if (!NetUtils.isSameIsolationId(vlan.getVlanTag(), vlanId)) {
+                        throw new InvalidParameterValueException("there is already one vlan " + vlan.getVlanTag()
+                                + " on network :" + +network.getId() + ", only one vlan is allowed on guest network");
                     }
                 }
                 sameSubnet = validateIpRange(startIP, endIP, newVlanGateway, newVlanNetmask, vlans, ipv4, ipv6, ip6Gateway, ip6Cidr, startIPv6, endIPv6, network);
@@ -2792,7 +2792,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
             if (vlanId != null) {
                 // if vlan is specified, throw an error if it's not equal to
                 // network's vlanId
-                if (networkVlanId != null && !networkVlanId.equalsIgnoreCase(vlanId)) {
+                if (networkVlanId != null && !NetUtils.isSameIsolationId(networkVlanId, vlanId)) {
                     throw new InvalidParameterValueException("Vlan doesn't match vlan of the network");
                 }
             } else {
@@ -2878,9 +2878,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
                     continue;
                 }
                 // from here, subnet overlaps
-                if (!vlanId.equals(vlan.getVlanTag())) {
-                    throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag() + " in zone " + zone.getName() +
-                        " has overlapped with the subnet. Please specify a different gateway/netmask.");
+                if (!NetUtils.isSameIsolationId(vlanId, vlan.getVlanTag())) {
+                    throw new InvalidParameterValueException("The IP range with tag: " + vlan.getVlanTag()
+                            + " in zone " + zone.getName()
+                            + " has overlapped with the subnet. Please specify a different gateway/netmask.");
                 }
                 if (vlan.getNetworkId() != networkId) {
                     throw new InvalidParameterValueException("This subnet is overlapped with subnet in other network " + vlan.getNetworkId() + " in zone " +
@@ -2918,7 +2919,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
                 if (vlan.getIp6Gateway() == null) {
                     continue;
                 }
-                if (vlanId.equals(vlan.getVlanTag())) {
+                if (NetUtils.isSameIsolationId(vlanId, vlan.getVlanTag())) {
                     if (NetUtils.isIp6RangeOverlap(ipv6Range, vlan.getIp6Range())) {
                         throw new InvalidParameterValueException("The IPv6 range with tag: " + vlan.getVlanTag() +
                             " already has IPs that overlap with the new range. Please specify a different start IP/end IP.");
@@ -3304,7 +3305,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
         List<PortableIpRangeVO> existingPortableIPRanges = _portableIpRangeDao.listByRegionId(_regionDao.getRegionId());
         if (existingPortableIPRanges != null && !existingPortableIPRanges.isEmpty()) {
             for (PortableIpRangeVO portableIpRange : existingPortableIPRanges) {
-                if (portableIpRange.getVlanTag().equalsIgnoreCase(vlanId)) {
+                if (NetUtils.isSameIsolationId(portableIpRange.getVlanTag(), vlanId)) {
                     throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for portable ip range in this region");
                 }
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2cf356e0/utils/src/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/net/NetUtils.java b/utils/src/com/cloud/utils/net/NetUtils.java
index 5f600e5..905e518 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -1388,7 +1388,7 @@ public class NetUtils {
 
     static final String VLAN_UNTAGGED = "untagged";
 
-    public static boolean sameIsolationId(String one, String other)
+    public static boolean isSameIsolationId(String one, String other)
     {
         // check nulls
         // check empty strings
@@ -1413,7 +1413,7 @@ public class NetUtils {
             other = other.substring(VLAN_PREFIX_LENGTH);
         }
         // check valid uris or numbers
-        if (one.equals(other))
+        if (one.equalsIgnoreCase(other))
         {
             return true;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2cf356e0/utils/test/com/cloud/utils/net/NetUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/net/NetUtilsTest.java b/utils/test/com/cloud/utils/net/NetUtilsTest.java
index c7407bf..53a1f2e 100644
--- a/utils/test/com/cloud/utils/net/NetUtilsTest.java
+++ b/utils/test/com/cloud/utils/net/NetUtilsTest.java
@@ -174,4 +174,10 @@ public class NetUtilsTest extends TestCase {
     public void testGetLocalIPString() {
         assertNotNull(NetUtils.getLocalIPString());
     }
+
+    @Test
+    public void testSameIsolationId() {
+        assertTrue(NetUtils.isSameIsolationId("1", "vlan://1"));
+        assertTrue(NetUtils.isSameIsolationId("", null));
+    }
 }