Skip to content

Commit 742e1b1

Browse files
Anthony XuDaanHoogland
authored andcommitted
if networkID is not specified, get one network with free ips.
(cherry picked from commit 8c5a9ec)
1 parent b91727b commit 742e1b1

5 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎api/src/com/cloud/network/NetworkModel.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public interface NetworkModel {
9090

9191
boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services);
9292

93+
Network getNetworkWithSGWithFreeIPs(Long zoneId);
94+
9395
Network getNetworkWithSecurityGroupEnabled(Long zoneId);
9496

9597
String getIpOfNetworkElementInVirtualNetwork(long accountId, long dataCenterId);
@@ -273,4 +275,4 @@ public interface NetworkModel {
273275
boolean isNetworkReadyForGc(long networkId);
274276

275277
boolean getNetworkEgressDefaultPolicy(Long networkId);
276-
}
278+
}

‎server/src/com/cloud/network/NetworkModelImpl.java‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,31 @@ public NetworkVO getSystemNetworkByZoneAndTrafficType(long zoneId, TrafficType t
736736
return networks.get(0);
737737
}
738738

739+
@Override
740+
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
741+
List<NetworkVO> networks = _networksDao.listByZoneSecurityGroup(zoneId);
742+
if (networks == null || networks.isEmpty()) {
743+
return null;
744+
}
745+
NetworkVO ret_network = null;
746+
for (NetworkVO nw : networks) {
747+
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(nw.getId());
748+
for (VlanVO vlan : vlans) {
749+
if (_ipAddressDao.countFreeIpsInVlan(vlan.getId()) > 0) {
750+
ret_network = nw;
751+
break;
752+
}
753+
}
754+
if (ret_network != null) {
755+
break;
756+
}
757+
}
758+
if (ret_network == null) {
759+
s_logger.debug("Can not find network with security group enabled with free IPs");
760+
}
761+
return ret_network;
762+
}
763+
739764
@Override
740765
public NetworkVO getNetworkWithSecurityGroupEnabled(Long zoneId) {
741766
List<NetworkVO> networks = _networksDao.listByZoneSecurityGroup(zoneId);

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, Service
23582358

23592359
// If no network is specified, find system security group enabled network
23602360
if (networkIdList == null || networkIdList.isEmpty()) {
2361-
Network networkWithSecurityGroup = _networkModel.getNetworkWithSecurityGroupEnabled(zone.getId());
2361+
Network networkWithSecurityGroup = _networkModel.getNetworkWithSGWithFreeIPs(zone.getId());
23622362
if (networkWithSecurityGroup == null) {
23632363
throw new InvalidParameterValueException("No network with security enabled is found in zone id=" + zone.getId());
23642364
}

‎server/test/com/cloud/network/MockNetworkModelImpl.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Ser
227227
return false;
228228
}
229229

230+
/* (non-Javadoc)
231+
* @see com.cloud.network.NetworkModel#getNetworkWithSGWithFreeIPs(java.lang.Long)
232+
*/
233+
@Override
234+
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
235+
// TODO Auto-generated method stub
236+
return null;
237+
}
238+
230239
/* (non-Javadoc)
231240
* @see com.cloud.network.NetworkModel#getNetworkWithSecurityGroupEnabled(java.lang.Long)
232241
*/

‎server/test/com/cloud/vpc/MockNetworkModelImpl.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,15 @@ public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Ser
238238
return (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(networkOfferingId, services));
239239
}
240240

241+
/* (non-Javadoc)
242+
* @see com.cloud.network.NetworkModel#getNetworkWithSGWithFreeIPs(java.lang.Long)
243+
*/
244+
@Override
245+
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
246+
// TODO Auto-generated method stub
247+
return null;
248+
}
249+
241250
/* (non-Javadoc)
242251
* @see com.cloud.network.NetworkModel#getNetworkWithSecurityGroupEnabled(java.lang.Long)
243252
*/

0 commit comments

Comments
 (0)