cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: Fixing CLOUDSTACK-226: don't allow physical networks with overlaping vnet ranges, belong to the same zone. Fixed create and update physical network code
Date Fri, 28 Sep 2012 20:13:32 GMT
Updated Branches:
  refs/heads/master e1ae302c1 -> 11fe086ad


Fixing CLOUDSTACK-226: don't allow physical networks with overlaping vnet ranges, belong to
the same zone. Fixed create and update physical network code


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

Branch: refs/heads/master
Commit: 11fe086adab8e790018343252ed08aac9a27b1c6
Parents: e1ae302
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Fri Sep 28 13:10:09 2012 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Fri Sep 28 13:11:20 2012 -0700

----------------------------------------------------------------------
 .../api/commands/UpdatePhysicalNetworkCmd.java     |   12 ++-----
 .../src/com/cloud/network/NetworkManagerImpl.java  |   27 +++++++++++++-
 2 files changed, 28 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/11fe086a/api/src/com/cloud/api/commands/UpdatePhysicalNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UpdatePhysicalNetworkCmd.java b/api/src/com/cloud/api/commands/UpdatePhysicalNetworkCmd.java
index 30fa532..a6abc03 100644
--- a/api/src/com/cloud/api/commands/UpdatePhysicalNetworkCmd.java
+++ b/api/src/com/cloud/api/commands/UpdatePhysicalNetworkCmd.java
@@ -22,11 +22,9 @@ import org.apache.log4j.Logger;
 
 import com.cloud.api.ApiConstants;
 import com.cloud.api.BaseAsyncCmd;
-import com.cloud.api.BaseCmd;
 import com.cloud.api.IdentityMapper;
 import com.cloud.api.Implementation;
 import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
 import com.cloud.api.response.PhysicalNetworkResponse;
 import com.cloud.async.AsyncJob;
 import com.cloud.event.EventTypes;
@@ -99,13 +97,9 @@ public class UpdatePhysicalNetworkCmd extends BaseAsyncCmd {
     @Override
     public void execute(){
         PhysicalNetwork result = _networkService.updatePhysicalNetwork(getId(),getNetworkSpeed(),
getTags(), getVlan(), getState());
-        if (result != null) {
-            PhysicalNetworkResponse response = _responseGenerator.createPhysicalNetworkResponse(result);
-            response.setResponseName(getCommandName());
-            this.setResponseObject(response);
-        }else {
-            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update physical
network");
-        }
+        PhysicalNetworkResponse response = _responseGenerator.createPhysicalNetworkResponse(result);
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/11fe086a/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index 7a11525..0cb61d5 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -130,6 +130,7 @@ import com.cloud.network.dao.PhysicalNetworkTrafficTypeVO;
 import com.cloud.network.element.ConnectivityProvider;
 import com.cloud.network.element.DhcpServiceProvider;
 import com.cloud.network.element.FirewallServiceProvider;
+import com.cloud.network.element.SourceNatServiceProvider;
 import com.cloud.network.element.IpDeployer;
 import com.cloud.network.element.LoadBalancingServiceProvider;
 import com.cloud.network.element.NetworkACLServiceProvider;
@@ -137,7 +138,6 @@ import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.PortForwardingServiceProvider;
 import com.cloud.network.element.RemoteAccessVPNServiceProvider;
 import com.cloud.network.element.Site2SiteVpnServiceProvider;
-import com.cloud.network.element.SourceNatServiceProvider;
 import com.cloud.network.element.StaticNatServiceProvider;
 import com.cloud.network.element.UserDataServiceProvider;
 import com.cloud.network.element.VirtualRouterElement;
@@ -218,7 +218,6 @@ import com.cloud.vm.dao.DomainRouterDao;
 import com.cloud.vm.dao.NicDao;
 import com.cloud.vm.dao.UserVmDao;
 import com.cloud.vm.dao.VMInstanceDao;
-
 import edu.emory.mathcs.backport.java.util.Collections;
 
 /**
@@ -5192,6 +5191,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService,
Manag
             } catch (NumberFormatException e) {
                 throw new InvalidParameterValueException("Please specify valid integers for
the vlan range.");
             }
+            
+            //check for vnet conflicts with other physical network(s) in the zone
+            checkGuestVnetsConflicts(zoneId, vnetStart, vnetEnd, null);
 
             if ((vnetStart > vnetEnd) || (vnetStart < 0) || (vnetEnd > 4096)) {
                 s_logger.warn("Invalid vnet range: start range:" + vnetStart + " end range:"
+ vnetEnd);
@@ -5370,6 +5372,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService,
Manag
                 throw new InvalidParameterValueException("Vnet range has to be" + rangeMessage
+ " and start range should be lesser than or equal to stop range");
             }
             
+            //check if new vnet conflicts with vnet ranges of other physical networks
+            checkGuestVnetsConflicts(network.getDataCenterId(), newStartVnet, newEndVnet,
network.getId());
+
             if (physicalNetworkHasAllocatedVnets(network.getDataCenterId(), network.getId()))
{
                 String[] existingRange = network.getVnet().split("-");
                 int existingStartVnet = Integer.parseInt(existingRange[0]);
@@ -5414,6 +5419,24 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService,
Manag
         return network;
     }
 
+    protected void checkGuestVnetsConflicts(long zoneId, int newStartVnet, int newEndVnet,
Long pNtwkIdToSkip) {
+        List<? extends PhysicalNetwork> pNtwks = _physicalNetworkDao.listByZone(zoneId);
+        for (PhysicalNetwork pNtwk : pNtwks) {
+            // skip my own network
+            if (pNtwkIdToSkip != null && pNtwkIdToSkip == pNtwk.getId()) {
+                continue;
+            }
+            String[] existingRange = pNtwk.getVnet().split("-");
+            int startVnet = Integer.parseInt(existingRange[0]);
+            int endVnet = Integer.parseInt(existingRange[1]);
+            if ((newStartVnet >= startVnet && newStartVnet <= endVnet)
+                    || (newEndVnet <= endVnet && newEndVnet >= startVnet))
{
+                throw new InvalidParameterValueException("Vnet range for physical network
conflicts with another " +
+                		"physical network's vnet in the zone");
+            } 
+        }
+    }
+
     private boolean physicalNetworkHasAllocatedVnets(long zoneId, long physicalNetworkId)
{
         return !_dcDao.listAllocatedVnets(physicalNetworkId).isEmpty();
     }


Mime
View raw message