Skip to content

Commit

Permalink
Merge pull request #33 from r2d4/leases
Browse files Browse the repository at this point in the history
Use last entry when parsing DHCP status file
  • Loading branch information
dhiltgen authored Mar 2, 2017
2 parents dc9207e + e5724f2 commit b14a80e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,18 @@ func (d *Driver) getIPByMacFromSettings(mac string) (string, error) {
log.Warnf("Failed to decode dnsmasq lease status: %s", err)
return "", err
}
ipAddr := ""
for _, value := range s {
if strings.ToLower(value.Mac_address) == strings.ToLower(mac) {
log.Debugf("IP address: %s", value.Ip_address)
return value.Ip_address, nil
// If there are multiple entries,
// the last one is the most current
ipAddr = value.Ip_address
}
}
return "", nil
if ipAddr != "" {
log.Debugf("IP address: %s", ipAddr)
}
return ipAddr, nil
}

func (d *Driver) GetIP() (string, error) {
Expand Down

0 comments on commit b14a80e

Please sign in to comment.