Skip to content

Commit 7e50f4a

Browse files
authored
server: Fix delete network with no services (#4132)
Fix delete shared network with no services on network offering Fixes: #4096
1 parent 06f3ff0 commit 7e50f4a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import javax.annotation.PostConstruct;
3030
import javax.inject.Inject;
3131

32+
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
33+
import org.apache.commons.collections.CollectionUtils;
3234
import org.apache.log4j.Logger;
3335

3436
import com.cloud.network.Network;
@@ -82,6 +84,8 @@ public class UserVmDaoImpl extends GenericDaoBase<UserVmVO, Long> implements Use
8284
ResourceTagDao _tagsDao;
8385
@Inject
8486
NetworkDao networkDao;
87+
@Inject
88+
NetworkOfferingServiceMapDao networkOfferingServiceMapDao;
8589

8690
private static final String LIST_PODS_HAVING_VMS_FOR_ACCOUNT =
8791
"SELECT pod_id FROM cloud.vm_instance WHERE data_center_id = ? AND account_id = ? AND pod_id IS NOT NULL AND (state = 'Running' OR state = 'Stopped') "
@@ -313,7 +317,10 @@ private void recreateUserVmSeach(NetworkVO network) {
313317
SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder();
314318
nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
315319
nicSearch.and("removed", nicSearch.entity().getRemoved(), SearchCriteria.Op.NULL);
316-
if (!Network.GuestType.L2.equals(network.getGuestType())) {
320+
321+
List<String> networkServices = networkOfferingServiceMapDao.listServicesForNetworkOffering(network.getNetworkOfferingId());
322+
323+
if (!Network.GuestType.L2.equals(network.getGuestType()) && CollectionUtils.isNotEmpty(networkServices)) {
317324
nicSearch.and().op("ip4Address", nicSearch.entity().getIPv4Address(), SearchCriteria.Op.NNULL);
318325
nicSearch.or("ip6Address", nicSearch.entity().getIPv6Address(), SearchCriteria.Op.NNULL);
319326
nicSearch.cp();

0 commit comments

Comments
 (0)