cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaya...@apache.org
Subject [1/3] git commit: updated refs/heads/master to c53778c
Date Thu, 23 Jan 2014 13:00:54 GMT
Updated Branches:
  refs/heads/master f999a0183 -> c53778c33


CLOUDSTACK-2031:support for number of ips per nic limit needs to be added for the multiple
ip address per nic


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

Branch: refs/heads/master
Commit: 4925b9f6a126454215531998c461bf376ac6ab67
Parents: 4b3784a
Author: Damodar Reddy <damoder.reddy@citrix.com>
Authored: Thu Jan 23 17:35:37 2014 +0530
Committer: Jayapal <jayapal@apache.org>
Committed: Thu Jan 23 18:14:12 2014 +0530

----------------------------------------------------------------------
 .../api/command/user/vm/AddIpToVmNicCmd.java           |  2 +-
 .../schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java |  2 ++
 .../src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java    | 13 +++++++++++++
 server/src/com/cloud/configuration/Config.java         |  4 ++++
 server/src/com/cloud/network/NetworkServiceImpl.java   |  8 ++++++++
 setup/db/db/schema-430to440.sql                        |  2 +-
 6 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4925b9f6/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java
index c0e8d3e..439879a 100644
--- a/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/AddIpToVmNicCmd.java
@@ -130,7 +130,7 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd {
         try {
             result = _networkService.allocateSecondaryGuestIP(getNicId(), getIpaddress());
         } catch (InsufficientAddressCapacityException e) {
-            throw new InvalidParameterValueException("Allocating guest ip for nic failed");
+            throw new InvalidParameterValueException("Allocating guest ip for nic failed
: " + e.getMessage());
         }
 
         if (result != null) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4925b9f6/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java
index 9fbfa27..39b8470 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDao.java
@@ -51,4 +51,6 @@ public interface NicSecondaryIpDao extends GenericDao<NicSecondaryIpVO,
Long> {
     NicSecondaryIpVO findByIp4AddressAndNetworkIdAndInstanceId(long networkId, Long vmId,
String vmIp);
 
     List<String> getSecondaryIpAddressesForNic(long nicId);
+
+    Long countByNicId(long nicId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4925b9f6/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java
index 2f3cc29..29af019 100644
--- a/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/NicSecondaryIpDaoImpl.java
@@ -35,6 +35,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
 public class NicSecondaryIpDaoImpl extends GenericDaoBase<NicSecondaryIpVO, Long> implements
NicSecondaryIpDao {
     private final SearchBuilder<NicSecondaryIpVO> AllFieldsSearch;
     private final GenericSearchBuilder<NicSecondaryIpVO, String> IpSearch;
+    protected GenericSearchBuilder<NicSecondaryIpVO, Long> CountByNicId;
 
     protected NicSecondaryIpDaoImpl() {
         super();
@@ -50,6 +51,11 @@ public class NicSecondaryIpDaoImpl extends GenericDaoBase<NicSecondaryIpVO,
Long
         IpSearch.and("network", IpSearch.entity().getNetworkId(), Op.EQ);
         IpSearch.and("address", IpSearch.entity().getIp4Address(), Op.NNULL);
         IpSearch.done();
+
+        CountByNicId = createSearchBuilder(Long.class);
+        CountByNicId.select(null, Func.COUNT, null);
+        CountByNicId.and("nic", CountByNicId.entity().getNicId(), SearchCriteria.Op.EQ);
+        CountByNicId.done();
     }
 
     @Override
@@ -135,4 +141,11 @@ public class NicSecondaryIpDaoImpl extends GenericDaoBase<NicSecondaryIpVO,
Long
         sc.setParameters("address", vmIp);
         return findOneBy(sc);
     }
+
+    @Override
+    public Long countByNicId(long nicId) {
+        SearchCriteria<Long> sc = CountByNicId.create();
+        sc.setParameters("nic", nicId);
+        return customSearch(sc, null).get(0);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4925b9f6/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index 9117bc4..6ba6774 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -402,6 +402,10 @@ public enum Config {
             "10",
             "The maximum number of subnets per customer gateway",
             null),
+    MaxNumberOfSecondaryIPsPerNIC(
+            "Network", ManagementServer.class, Integer.class,
+            "vm.network.nic.max.secondary.ipaddresses", "256",
+            "Specify the number of secondary ip addresses per nic per vm", null),
 
     // Console Proxy
     ConsoleProxyCapacityStandby(

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4925b9f6/server/src/com/cloud/network/NetworkServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkServiceImpl.java b/server/src/com/cloud/network/NetworkServiceImpl.java
index 056190f..399f086 100755
--- a/server/src/com/cloud/network/NetworkServiceImpl.java
+++ b/server/src/com/cloud/network/NetworkServiceImpl.java
@@ -669,6 +669,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService
{
             throw new InvalidParameterValueException("Invalid network id is given");
         }
 
+        int maxAllowedIpsPerNic = NumbersUtil.parseInt(_configDao.getValue(Config.MaxNumberOfSecondaryIPsPerNIC.key()),
10);
+        Long nicWiseIpCount = _nicSecondaryIpDao.countByNicId(nicId);
+        if(nicWiseIpCount.intValue() >= maxAllowedIpsPerNic) {
+            s_logger.error("Maximum Number of Ips \"vm.network.nic.max.secondary.ipaddresses
= \"" + maxAllowedIpsPerNic + " per Nic has been crossed for the nic " +  nicId + ".");
+            throw new InsufficientAddressCapacityException("Maximum Number of Ips per Nic
has been crossed.", Nic.class, nicId);
+        }
+
+
         s_logger.debug("Calling the ip allocation ...");
         String ipaddr = null;
         //Isolated network can exist in Basic zone only, so no need to verify the zone type

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4925b9f6/setup/db/db/schema-430to440.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-430to440.sql b/setup/db/db/schema-430to440.sql
index 1b6a9ab..0ce9202 100644
--- a/setup/db/db/schema-430to440.sql
+++ b/setup/db/db/schema-430to440.sql
@@ -443,4 +443,4 @@ CREATE VIEW `cloud`.`user_vm_view` AS
            left join
         `cloud`.`user_vm_details` `custom_ram_size`  ON (((`custom_ram_size`.`vm_id` = `cloud`.`vm_instance`.`id`)
and (`custom_ram_size`.`name` = 'memory')));
 
-
+INSERT INTO `cloud`.`configuration`(category, instance, component, name, value, description,
default_value) VALUES ('NetworkManager', 'DEFAULT', 'management-server', 'vm.network.nic.max.secondary.ipaddresses',
NULL, 'Specify the number of secondary ip addresses per nic per vm', '256') ON DUPLICATE KEY
UPDATE category='NetworkManager';
\ No newline at end of file


Mime
View raw message