Skip to content

Commit 9df783c

Browse files
authored
Filter out networks without access while getting networks with SG with free IPs (#9596)
1 parent 0a93dce commit 9df783c

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public interface NetworkModel {
149149

150150
boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services);
151151

152-
Network getNetworkWithSGWithFreeIPs(Long zoneId);
152+
Network getNetworkWithSGWithFreeIPs(Account account, Long zoneId);
153153

154154
Network getNetworkWithSecurityGroupEnabled(Long zoneId);
155155

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,13 +789,19 @@ public NetworkVO getSystemNetworkByZoneAndTrafficType(long zoneId, TrafficType t
789789
}
790790

791791
@Override
792-
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
792+
public NetworkVO getNetworkWithSGWithFreeIPs(Account account, Long zoneId) {
793793
List<NetworkVO> networks = _networksDao.listByZoneSecurityGroup(zoneId);
794794
if (networks == null || networks.isEmpty()) {
795795
return null;
796796
}
797797
NetworkVO ret_network = null;
798798
for (NetworkVO nw : networks) {
799+
try {
800+
checkAccountNetworkPermissions(account, nw);
801+
} catch (PermissionDeniedException e) {
802+
continue;
803+
}
804+
799805
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(nw.getId());
800806
for (VlanVO vlan : vlans) {
801807
if (_ipAddressDao.countFreeIpsInVlan(vlan.getId()) > 0) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3653,7 +3653,7 @@ public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, Service
36533653

36543654
// If no network is specified, find system security group enabled network
36553655
if (networkIdList == null || networkIdList.isEmpty()) {
3656-
Network networkWithSecurityGroup = _networkModel.getNetworkWithSGWithFreeIPs(zone.getId());
3656+
Network networkWithSecurityGroup = _networkModel.getNetworkWithSGWithFreeIPs(owner, zone.getId());
36573657
if (networkWithSecurityGroup == null) {
36583658
throw new InvalidParameterValueException("No network with security enabled is found in zone id=" + zone.getUuid());
36593659
}
@@ -8536,7 +8536,7 @@ private LinkedHashMap<Integer, Long> getVmOvfNetworkMapping(DataCenter zone, Acc
85368536
private Network getNetworkForOvfNetworkMapping(DataCenter zone, Account owner) throws InsufficientCapacityException, ResourceAllocationException {
85378537
Network network = null;
85388538
if (zone.isSecurityGroupEnabled()) {
8539-
network = _networkModel.getNetworkWithSGWithFreeIPs(zone.getId());
8539+
network = _networkModel.getNetworkWithSGWithFreeIPs(owner, zone.getId());
85408540
if (network == null) {
85418541
throw new InvalidParameterValueException("No network with security enabled is found in zone ID: " + zone.getUuid());
85428542
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Ser
237237
* @see com.cloud.network.NetworkModel#getNetworkWithSGWithFreeIPs(java.lang.Long)
238238
*/
239239
@Override
240-
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
240+
public NetworkVO getNetworkWithSGWithFreeIPs(Account account, Long zoneId) {
241241
// TODO Auto-generated method stub
242242
return null;
243243
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Ser
248248
* @see com.cloud.network.NetworkModel#getNetworkWithSGWithFreeIPs(java.lang.Long)
249249
*/
250250
@Override
251-
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
251+
public NetworkVO getNetworkWithSGWithFreeIPs(Account account, Long zoneId) {
252252
// TODO Auto-generated method stub
253253
return null;
254254
}

0 commit comments

Comments
 (0)