Allow multiple dns setting
Resolve
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Configurable;
import org.zstack.core.cloudbus.CloudBus;
import org.zstack.core.cloudbus.CloudBusCallBack;
import org.zstack.core.db.DatabaseFacade;
+import org.zstack.core.db.Q;
import org.zstack.core.db.SimpleQuery;
import org.zstack.core.db.SimpleQuery.Op;
import org.zstack.core.errorcode.ErrorFacade;
@@ -70,23 +71,25 @@ public class VirtualRouterSyncDnsOnStartFlow extends NoRollbackFlow {
SimpleQuery<L3NetworkDnsVO> query = dbf.createQuery(L3NetworkDnsVO.class);
query.select(L3NetworkDnsVO_.dns);
query.add(L3NetworkDnsVO_.l3NetworkUuid, Op.IN, l3Uuids);
+ List<L3NetworkDnsVO> l3NetworkDnsVOS = Q.New(L3NetworkDnsVO.class).in(L3NetworkDnsVO_.l3NetworkUuid, l3Uuids).list();
+
+ final List<DnsInfo> dns = new ArrayList<DnsInfo>(l3NetworkDnsVOS.size());
+ for (L3NetworkDnsVO vo : l3NetworkDnsVOS) {
+ DnsInfo dinfo = new DnsInfo();
+ dinfo.setDnsAddress(vo.getDns());
+ dinfo.setNicMac(vr.getGuestNics()
+ .stream()
+ .filter(nic -> nic.getL3NetworkUuid().equals(vo.getL3NetworkUuid()))
+ .findFirst().get()
+ .getMac());
+ dns.add(dinfo);
+ }
List<String> lst = query.listValue();
if (lst.isEmpty()) {
chain.next();
return;
}
- Set<String> dnsAddresses = new HashSet<String>(lst.size());
- dnsAddresses.addAll(lst);
-
- final List<DnsInfo> dns = new ArrayList<DnsInfo>(dnsAddresses.size());
- for (String d : dnsAddresses) {
- DnsInfo dinfo = new DnsInfo();
- dinfo.setDnsAddress(d);
- dinfo.setNicMac(vr.getGuestNics().get(0).getMac());
- dns.add(dinfo);
- }
-
SetDnsCmd cmd = new SetDnsCmd();
cmd.setDns(dns);
