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

This commit is contained in:
Damodar Reddy 2014-01-23 17:35:37 +05:30 committed by Jayapal
parent 4b3784a98e
commit 4925b9f6a1
6 changed files with 29 additions and 2 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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(

View File

@ -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

View File

@ -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';