Skip to content

Commit e5724f2

Browse files
committed
Use last entry when parsing DHCP status file
When a machine is stopped and restarted, it may get allocated a new IP. The loop that parsing the status file returns on the first match, which is the entry for the old IP so that machine fails to start up.
1 parent 37bb4cc commit e5724f2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

kvm.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,13 +636,18 @@ func (d *Driver) getIPByMacFromSettings(mac string) (string, error) {
636636
log.Warnf("Failed to decode dnsmasq lease status: %s", err)
637637
return "", err
638638
}
639+
ipAddr := ""
639640
for _, value := range s {
640641
if strings.ToLower(value.Mac_address) == strings.ToLower(mac) {
641-
log.Debugf("IP address: %s", value.Ip_address)
642-
return value.Ip_address, nil
642+
// If there are multiple entries,
643+
// the last one is the most current
644+
ipAddr = value.Ip_address
643645
}
644646
}
645-
return "", nil
647+
if ipAddr != "" {
648+
log.Debugf("IP address: %s", ipAddr)
649+
}
650+
return ipAddr, nil
646651
}
647652

648653
func (d *Driver) GetIP() (string, error) {

0 commit comments

Comments
 (0)