You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2013/12/31 12:26:37 UTC
[1/2] git commit: updated refs/heads/master to 2cf356e
Updated Branches:
refs/heads/master d50517e93 -> 2cf356e04
check vlans and other isolation types
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/04570eef
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/04570eef
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/04570eef
Branch: refs/heads/master
Commit: 04570eefed9a0ee1eca1fd700ed5732ba67150ce
Parents: d50517e
Author: Daan Hoogland <da...@onecht.net>
Authored: Fri Dec 20 16:47:58 2013 +0100
Committer: Daan Hoogland <dh...@schubergphilis.com>
Committed: Tue Dec 31 12:21:08 2013 +0100
----------------------------------------------------------------------
utils/src/com/cloud/utils/net/NetUtils.java | 44 +++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/04570eef/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 f6f6285..5f600e5 100755
--- a/utils/src/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/com/cloud/utils/net/NetUtils.java
@@ -1367,10 +1367,17 @@ public class NetUtils {
return resultIp;
}
+ static final String VLAN_PREFIX = "vlan://";
+ static final int VLAN_PREFIX_LENGTH = VLAN_PREFIX.length();
+
public static boolean isValidVlan(String vlan) {
+ if (null == vlan || "".equals(vlan))
+ return false;
+ if (vlan.startsWith(VLAN_PREFIX))
+ vlan = vlan.substring(VLAN_PREFIX_LENGTH);
try {
int vnet = Integer.parseInt(vlan);
- if (vnet < 0 || vnet > 4096) {
+ if (vnet <= 0 || vnet >= 4095) { // the valid range is 1- 4094
return false;
}
return true;
@@ -1379,6 +1386,41 @@ public class NetUtils {
}
}
+ static final String VLAN_UNTAGGED = "untagged";
+
+ public static boolean sameIsolationId(String one, String other)
+ {
+ // check nulls
+ // check empty strings
+ if ((one == null || one.equals(""))
+ &&
+ (other == null || other.equals("")))
+ {
+ return true;
+ }
+ // check 'untagged'
+ if (VLAN_UNTAGGED.equalsIgnoreCase(one) && VLAN_UNTAGGED.equalsIgnoreCase(other))
+ {
+ return true;
+ }
+ // if one is a number check the other as number and as 'vlan://' + number
+ if (one.startsWith(VLAN_PREFIX))
+ {
+ one = one.substring(VLAN_PREFIX_LENGTH);
+ }
+ if (other.startsWith(VLAN_PREFIX))
+ {
+ other = other.substring(VLAN_PREFIX_LENGTH);
+ }
+ // check valid uris or numbers
+ if (one.equals(other))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
// Attention maintainers: these pvlan functions should take into account code
// in Networks.BroadcastDomainType, where URI construction is done for other
// types of BroadcastDomainTypes
[2/2] git commit: updated refs/heads/master to 2cf356e
Posted by da...@apache.org.
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/master
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));
+ }
}