Filter out networks without access while getting networks with SG with free IPs (#9596)

This commit is contained in:
Vishesh 2024-09-20 20:13:54 +05:30 committed by GitHub
parent 0a93dcec74
commit 9df783ca4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 6 deletions

View File

@ -149,7 +149,7 @@ public interface NetworkModel {
boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services);
Network getNetworkWithSGWithFreeIPs(Long zoneId);
Network getNetworkWithSGWithFreeIPs(Account account, Long zoneId);
Network getNetworkWithSecurityGroupEnabled(Long zoneId);

View File

@ -789,13 +789,19 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel, Confi
}
@Override
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
public NetworkVO getNetworkWithSGWithFreeIPs(Account account, Long zoneId) {
List<NetworkVO> networks = _networksDao.listByZoneSecurityGroup(zoneId);
if (networks == null || networks.isEmpty()) {
return null;
}
NetworkVO ret_network = null;
for (NetworkVO nw : networks) {
try {
checkAccountNetworkPermissions(account, nw);
} catch (PermissionDeniedException e) {
continue;
}
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(nw.getId());
for (VlanVO vlan : vlans) {
if (_ipAddressDao.countFreeIpsInVlan(vlan.getId()) > 0) {

View File

@ -3653,7 +3653,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.getNetworkWithSGWithFreeIPs(zone.getId());
Network networkWithSecurityGroup = _networkModel.getNetworkWithSGWithFreeIPs(owner, zone.getId());
if (networkWithSecurityGroup == null) {
throw new InvalidParameterValueException("No network with security enabled is found in zone id=" + zone.getUuid());
}
@ -8536,7 +8536,7 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
private Network getNetworkForOvfNetworkMapping(DataCenter zone, Account owner) throws InsufficientCapacityException, ResourceAllocationException {
Network network = null;
if (zone.isSecurityGroupEnabled()) {
network = _networkModel.getNetworkWithSGWithFreeIPs(zone.getId());
network = _networkModel.getNetworkWithSGWithFreeIPs(owner, zone.getId());
if (network == null) {
throw new InvalidParameterValueException("No network with security enabled is found in zone ID: " + zone.getUuid());
}

View File

@ -237,7 +237,7 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
* @see com.cloud.network.NetworkModel#getNetworkWithSGWithFreeIPs(java.lang.Long)
*/
@Override
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
public NetworkVO getNetworkWithSGWithFreeIPs(Account account, Long zoneId) {
// TODO Auto-generated method stub
return null;
}

View File

@ -248,7 +248,7 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
* @see com.cloud.network.NetworkModel#getNetworkWithSGWithFreeIPs(java.lang.Long)
*/
@Override
public NetworkVO getNetworkWithSGWithFreeIPs(Long zoneId) {
public NetworkVO getNetworkWithSGWithFreeIPs(Account account, Long zoneId) {
// TODO Auto-generated method stub
return null;
}