@Override
public void releaseResourceOnDetachingNic(VmInstanceSpec spec, VmNicInventory nic, NoErrorCompletion completion) {
if (spec.getVmInventory().getType().equals(VmInstanceConstant.USER_VM_TYPE)) {
completion.done();
return;
}
logger.debug(String.format("check detaching nic[uuid:%s] in peer l3 of vip", nic.getUuid()));
List<VipPeerL3NetworkRefVO> refVOS = Q.New(VipPeerL3NetworkRefVO.class).eq(VipPeerL3NetworkRefVO_.l3NetworkUuid,
nic.getL3NetworkUuid()).list();
if (refVOS == null || refVOS.isEmpty()) {
completion.done();
return;
}
Set<String> refUuids = refVOS.stream().map(r -> r.getVipUuid()).collect(Collectors.toSet());
logger.debug(String.format("release peer l3[uuid:%s] from vips[uuid:%s] for detaching nic[uuid:%s]",
nic.getL3NetworkUuid(), refUuids, nic.getUuid()));
List<VipVO> vipVOS = Q.New(VipVO.class).in(VipVO_.uuid, refUuids).list();
for (VipVO vipVO : vipVOS) {
VipBase v = new VipBase(vipVO);
v.deletePeerL3NetworkUuid(nic.getL3NetworkUuid());
}
completion.done();
}