@@ -1009,26 +1009,31 @@ void handleVmHostnameChanged(long instanceId, String newHostName) {
10091009 List <DnsNicJoinVO > nicsForThisFqdn = newUrlEntry .getValue ();
10101010
10111011 try {
1012+ Set <String > oldDnsRecordUrls = new HashSet <>();
10121013 Transaction .execute (new TransactionCallbackWithExceptionNoReturn <DnsProviderException >() {
10131014 @ Override
10141015 public void doInTransactionWithoutResult (TransactionStatus status ) throws DnsProviderException {
1015- if (isDnsCollision (newDnsRecordUrl , targetZoneId , instanceId )) {
1016- return ;
1017- }
1018-
1019- Set <String > oldDnsRecordUrls = new HashSet <>();
10201016 for (DnsNicJoinVO nic : nicsForThisFqdn ) {
10211017 if (nic .getNicDnsUrl () != null ) {
10221018 oldDnsRecordUrls .add (nic .getNicDnsUrl ());
1019+ nicDetailsDao .removeDetail (nic .getId (), ApiConstants .NIC_DNS_RECORD );
10231020 }
1024- nicDetailsDao .addDetail (nic .getId (), ApiConstants .NIC_DNS_RECORD , newDnsRecordUrl , true );
10251021 }
1026-
1027- // NICs for the old URL and cleanly send a DELETE API call to PowerDNS!
10281022 for (String oldUrl : oldDnsRecordUrls ) {
10291023 syncDnsRecordsState (instanceId , oldUrl , targetZoneId );
10301024 }
1025+ }
1026+ });
10311027
1028+ Transaction .execute (new TransactionCallbackWithExceptionNoReturn <DnsProviderException >() {
1029+ @ Override
1030+ public void doInTransactionWithoutResult (TransactionStatus status ) throws DnsProviderException {
1031+ if (isDnsCollision (newDnsRecordUrl , targetZoneId , instanceId )) {
1032+ return ;
1033+ }
1034+ for (DnsNicJoinVO nic : nicsForThisFqdn ) {
1035+ nicDetailsDao .addDetail (nic .getId (), ApiConstants .NIC_DNS_RECORD , newDnsRecordUrl , true );
1036+ }
10321037 // This sync call finds the newly written intent and sends an ADD/REPLACE call.
10331038 syncDnsRecordsState (instanceId , newDnsRecordUrl , targetZoneId );
10341039 }
0 commit comments