From 63cff8de26bf2ea293ec2df81fa7cc02f284a1d9 Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 23 Feb 2011 11:31:11 -0800 Subject: [PATCH] Regular user is allowed to create Guest networks only; throw an error when he tries to use networkOffering with trafficType Public --- server/src/com/cloud/configuration/Config.java | 1 - .../com/cloud/network/NetworkManagerImpl.java | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 3512e32db1d..3bc90075615 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -196,7 +196,6 @@ public enum Config { KvmPrivateNetwork("Advanced", ManagementServer.class, String.class, "kvm.private.network.device", null, "Specify the private bridge on host for private network", null), // Premium - UsageExecutionTimezone("Premium", ManagementServer.class, String.class, "usage.execution.timezone", null, "The timezone to use for usage job execution time", null), UsageStatsJobAggregationRange("Premium", ManagementServer.class, Integer.class, "usage.stats.job.aggregation.range", "1440", "The range of time for aggregating the user statistics specified in minutes (e.g. 1440 for daily, 60 for hourly.", null), UsageStatsJobExecTime("Premium", ManagementServer.class, String.class, "usage.stats.job.exec.time", "00:15", "The time at which the usage statistics aggregation job will run as an HH24:MM time, e.g. 00:30 to run at 12:30am.", null), diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index a860dbaea19..c18236b5341 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1491,17 +1491,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag networkConfigs.add(endIP); networkConfigs.add(netmask); boolean defineNetworkConfig = false; - short nullElementsCount = 0; + short configElementsCount = 0; for (String networkConfig : networkConfigs) { - if (networkConfig == null) { - nullElementsCount++; + if (networkConfig != null) { + configElementsCount++; } } - if (nullElementsCount > 0 && nullElementsCount != networkConfigs.size()) { + if (configElementsCount > 0 && configElementsCount != networkConfigs.size()) { throw new InvalidParameterValueException("startIP/endIP/netmask/gateway must be specified together"); - } else if (nullElementsCount == networkConfigs.size()) { + } else if (configElementsCount == networkConfigs.size()) { defineNetworkConfig = true; } @@ -1519,13 +1519,19 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag } } + //Regular user can create guest network only + if (ctxAccount.getType() == Account.ACCOUNT_TYPE_NORMAL && networkOffering.getTrafficType() != TrafficType.Guest) { + throw new InvalidParameterValueException("Regular user can create a network only from the network offering having traffic type " + TrafficType.Guest); + } + //Don't allow to specify cidr/gateway/vlan 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"); } + //For non-root admins check cidr limit - if it's allowed by global config value if (ctxAccount.getType() != Account.ACCOUNT_TYPE_ADMIN && cidr != null) { - //Check cidr limit - if it's allowed by global config value + String[] cidrPair = cidr.split("\\/"); int cidrSize = Integer.valueOf(cidrPair[1]);