You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/01/16 00:55:10 UTC
[40/43] git commit: Do not allow add multiple VLANs or subnets into
shared network
Do not allow add multiple VLANs or subnets into shared network
CS allows to add multiple VLANs and subnets to a shared network, but it doesn't really work, for example , vm on second VLAN or subnet cannot get IP through DHCP
This patch will not allow to add mulitple VLANS or subnets into shared network
CLOUDSTACK-982:Do not allow add multiple VLANs or subnets into shared network
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/101f6441
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/101f6441
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/101f6441
Branch: refs/heads/api_limit
Commit: 101f64410adc944ea2f2b2ad9734c990c4fe0336
Parents: 8d0091d
Author: anthony <an...@cloud.com>
Authored: Tue Jan 15 09:17:12 2013 -0800
Committer: anthony <an...@cloud.com>
Committed: Tue Jan 15 09:17:12 2013 -0800
----------------------------------------------------------------------
.../configuration/ConfigurationManagerImpl.java | 54 ++++++++-------
1 files changed, 30 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/101f6441/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 2e20c13..b21c5a3 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2071,7 +2071,12 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
Long projectId = cmd.getProjectId();
Long domainId = cmd.getDomainId();
Account vlanOwner = null;
-
+
+ // if end ip is not specified, default it to startIp
+ if (endIP == null && startIP != null) {
+ endIP = startIP;
+ }
+
if (projectId != null) {
if (accountName != null) {
throw new InvalidParameterValueException("Account and projectId are mutually exclusive");
@@ -2176,6 +2181,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException("Nework id is required for Direct vlan creation ");
}
networkId = network.getId();
+ zoneId = network.getDataCenterId();
}
} else if (network.getGuestType() == null || network.getGuestType() == Network.GuestType.Isolated) {
throw new InvalidParameterValueException("Can't create direct vlan for network id=" + networkId + " with type: " + network.getGuestType());
@@ -2192,34 +2198,34 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
endIP = startIP;
}
- if (forVirtualNetwork || zone.getNetworkType() == DataCenter.NetworkType.Basic || zone.isSecurityGroupEnabled()) {
- if (vlanGateway == null || vlanNetmask == null || zoneId == null) {
- throw new InvalidParameterValueException("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks");
- }
- } else {
- // check if startIp and endIp belong to network Cidr
- String networkCidr = network.getCidr();
- String networkGateway = network.getGateway();
- Long networkZoneId = network.getDataCenterId();
- String networkNetmask = NetUtils.getCidrNetmask(networkCidr);
-
- // Check if ip addresses are in network range
- if (!NetUtils.sameSubnet(startIP, networkGateway, networkNetmask)) {
- throw new InvalidParameterValueException("Start ip is not in network cidr: " + networkCidr);
- }
-
- if (endIP != null) {
- if (!NetUtils.sameSubnet(endIP, networkGateway, networkNetmask)) {
- throw new InvalidParameterValueException("End ip is not in network cidr: " + networkCidr);
+ if ( zone.getNetworkType() == DataCenter.NetworkType.Advanced ) {
+ if (network.getTrafficType() == TrafficType.Guest) {
+ if (network.getGuestType() != GuestType.Shared) {
+ throw new InvalidParameterValueException("Can execute createVLANIpRanges on shared guest network, but type of this guest network "
+ + network.getId() + " is " + network.getGuestType());
+ }
+ List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
+ if ( vlans != null && vlans.size() > 0 ) {
+ VlanVO vlan = vlans.get(0);
+ if ( vlanId == null ) {
+ vlanId = vlan.getVlanTag();
+ } else if ( 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");
+ }
+ vlanGateway = vlan.getVlanGateway();
+ vlanNetmask = vlan.getVlanNetmask();
}
+ } else if (network.getTrafficType() == TrafficType.Management) {
+ throw new InvalidParameterValueException("Cannot execute createVLANIpRanges on management network");
}
+ }
- // set gateway, netmask, zone from network object
- vlanGateway = networkGateway;
- vlanNetmask = networkNetmask;
- zoneId = networkZoneId;
+ if (vlanGateway == null || vlanNetmask == null || zoneId == null) {
+ throw new InvalidParameterValueException("Gateway, netmask and zoneId have to be passed in for virtual and direct untagged networks");
}
+
// if it's an account specific range, associate ip address list to the account
boolean associateIpRangeToAccount = false;