if networkID is not specified, get one network with free ips.

(cherry picked from commit 8c5a9ec4de)
This commit is contained in:
Anthony Xu 2014-05-21 14:33:52 -07:00 committed by Daan Hoogland
parent b91727ba89
commit 742e1b1954
5 changed files with 47 additions and 2 deletions

View File

@ -90,6 +90,8 @@ public interface NetworkModel {
boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services);
Network getNetworkWithSGWithFreeIPs(Long zoneId);
Network getNetworkWithSecurityGroupEnabled(Long zoneId);
String getIpOfNetworkElementInVirtualNetwork(long accountId, long dataCenterId);
@ -273,4 +275,4 @@ public interface NetworkModel {
boolean isNetworkReadyForGc(long networkId);
boolean getNetworkEgressDefaultPolicy(Long networkId);
}
}

View File

@ -736,6 +736,31 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
return networks.get(0);
}
@Override
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
List<NetworkVO> networks = _networksDao.listByZoneSecurityGroup(zoneId);
if (networks == null || networks.isEmpty()) {
return null;
}
NetworkVO ret_network = null;
for (NetworkVO nw : networks) {
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(nw.getId());
for (VlanVO vlan : vlans) {
if (_ipAddressDao.countFreeIpsInVlan(vlan.getId()) > 0) {
ret_network = nw;
break;
}
}
if (ret_network != null) {
break;
}
}
if (ret_network == null) {
s_logger.debug("Can not find network with security group enabled with free IPs");
}
return ret_network;
}
@Override
public NetworkVO getNetworkWithSecurityGroupEnabled(Long zoneId) {
List<NetworkVO> networks = _networksDao.listByZoneSecurityGroup(zoneId);

View File

@ -2358,7 +2358,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
// If no network is specified, find system security group enabled network
if (networkIdList == null || networkIdList.isEmpty()) {
Network networkWithSecurityGroup = _networkModel.getNetworkWithSecurityGroupEnabled(zone.getId());
Network networkWithSecurityGroup = _networkModel.getNetworkWithSGWithFreeIPs(zone.getId());
if (networkWithSecurityGroup == null) {
throw new InvalidParameterValueException("No network with security enabled is found in zone id=" + zone.getId());
}

View File

@ -227,6 +227,15 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
return false;
}
/* (non-Javadoc)
* @see com.cloud.network.NetworkModel#getNetworkWithSGWithFreeIPs(java.lang.Long)
*/
@Override
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.NetworkModel#getNetworkWithSecurityGroupEnabled(java.lang.Long)
*/

View File

@ -238,6 +238,15 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
return (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(networkOfferingId, services));
}
/* (non-Javadoc)
* @see com.cloud.network.NetworkModel#getNetworkWithSGWithFreeIPs(java.lang.Long)
*/
@Override
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.NetworkModel#getNetworkWithSecurityGroupEnabled(java.lang.Long)
*/