From 858578993f65bcc6972a8c163b91a71c27f07d27 Mon Sep 17 00:00:00 2001 From: alena Date: Tue, 1 Mar 2011 10:00:36 -0800 Subject: [PATCH] Set specify_vlan=1 for Direct Network offering. --- .../ConfigurationManagerImpl.java | 18 ++++++++++++++---- .../com/cloud/network/NetworkManagerImpl.java | 10 +++++----- .../cloud/server/ConfigurationServerImpl.java | 3 +-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 4325c5736ae..c6f7415443a 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -1555,6 +1555,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura String vlanId = cmd.getVlan(); Boolean forVirtualNetwork = cmd.isForVirtualNetwork(); Long networkId = cmd.getNetworkID(); + String networkVlanId = null; // If an account name and domain ID are specified, look up the account String accountName = cmd.getAccountName(); @@ -1616,6 +1617,17 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura if (endIP == null && startIP != null) { endIP = startIP; } + + //if vlan is specified, throw an error if it's not equal to network's vlanId + URI uri = network.getBroadcastUri(); + if (uri != null) { + String[] vlan = uri.toString().split("vlan:\\/\\/"); + networkVlanId = vlan[1]; + } + + if (vlanId != null && !networkVlanId.equalsIgnoreCase(vlanId)) { + throw new InvalidParameterValueException("Vlan doesn't match vlan of the network"); + } if (forVirtualNetwork || zone.getNetworkType() == DataCenter.NetworkType.Basic || network.isSecurityGroupEnabled()) { if (vlanGateway == null || vlanNetmask == null || zoneId == null) { @@ -1645,10 +1657,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura zoneId = networkZoneId; //set vlanId if it's not null for the network - URI uri = network.getBroadcastUri(); - if (uri != null) { - String[] vlan = uri.toString().split("vlan:\\/\\/"); - vlanId = vlan[1]; + if (networkVlanId != null) { + vlanId = networkVlanId; } } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 4ff1f00ee7a..a679d94f214 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -716,7 +716,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag "Direct", TrafficType.Guest, false, - false, + true, null, null, null, @@ -1565,8 +1565,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } //Don't allow to specify cidr if the caller is a regular user - if (ctxAccount.getType() == Account.ACCOUNT_TYPE_NORMAL && cidr != null) { - throw new InvalidParameterValueException("Regular user is not allowed to specify gateway/netmask/ipRange"); + if (ctxAccount.getType() == Account.ACCOUNT_TYPE_NORMAL && (cidr != null || vlanId != null)) { + throw new InvalidParameterValueException("Regular user is not allowed to specify gateway/netmask/ipRange/vlanId"); } //For non-root admins check cidr limit - if it's allowed by global config value @@ -1580,8 +1580,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } - // VlanId can be specified by regular user only when network offering supports it - if (ctxAccount.getType() == Account.ACCOUNT_TYPE_NORMAL && vlanId != null && !networkOffering.getSpecifyVlan()) { + // VlanId can be specified only when network offering supports it + if (vlanId != null && !networkOffering.getSpecifyVlan()) { throw new InvalidParameterValueException("Can't specify vlan because network offering doesn't support it"); } diff --git a/server/src/com/cloud/server/ConfigurationServerImpl.java b/server/src/com/cloud/server/ConfigurationServerImpl.java index 9a86f19d47b..c02c1bd0315 100644 --- a/server/src/com/cloud/server/ConfigurationServerImpl.java +++ b/server/src/com/cloud/server/ConfigurationServerImpl.java @@ -76,7 +76,6 @@ import com.cloud.offerings.dao.NetworkOfferingDao; import com.cloud.service.ServiceOfferingVO; import com.cloud.service.dao.ServiceOfferingDao; import com.cloud.storage.DiskOfferingVO; -import com.cloud.storage.SnapshotPolicyVO; import com.cloud.storage.dao.DiskOfferingDao; import com.cloud.storage.dao.SnapshotPolicyDao; import com.cloud.test.IPRangeConfig; @@ -749,7 +748,7 @@ public class ConfigurationServerImpl implements ConfigurationServer { NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, - false, false, null, null, null, true, + false, true, null, null, null, true, Availability.Required, true, true, true, //services - all true except for firewall/lb/vpn and gateway false, false, false, false, GuestIpType.Direct);