Skip to content

Commit

Permalink
Adapt wait_for_lease behaviour with new mac
Browse files Browse the repository at this point in the history
  • Loading branch information
MalloZup committed Sep 20, 2018
1 parent 6629478 commit a13c304
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions libvirt/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func domainWaitForLeases(domain *libvirt.Domain, waitForLeases []*libvirtxml.Dom
continue
}
if !found {
log.Printf("[DEBUG] IP address not found for iface=%+v: will try in a while", strings.ToUpper(iface.MAC.Address))
log.Printf("[DEBUG] IP address not found for interface %+v will try in a while", iface)
return false, domWaitLeaseStillWaiting, nil
}
}
Expand All @@ -81,28 +81,22 @@ func domainWaitForLeases(domain *libvirt.Domain, waitForLeases []*libvirtxml.Dom
func domainIfaceHasAddress(domain libvirt.Domain, iface libvirtxml.DomainInterface,
domainDef libvirtxml.Domain, virConn *libvirt.Connect, rd *schema.ResourceData) (found bool, ignore bool, err error) {

// skip if we don't have mac
if iface.MAC == nil {
log.Printf("[DEBUG] Can't wait without a MAC address: ignoring interface %+v.\n", iface)
// we can't get the ip without a mac address
return false, true, nil
}
mac := strings.ToUpper(iface.MAC.Address)
log.Printf("[DEBUG] waiting for network address for iface=%s\n", mac)
// domainGetIfacesInfo retrieve network info from qemu-agent(disabled by default)
// and from libvirt-api, which will give the NetIfaces with adress and mac
ifacesWithAddr, err := domainGetIfacesInfo(domain, domainDef, virConn, rd)
if err != nil {
return false, false, fmt.Errorf("Error retrieving interface addresses: %s", err)
}
log.Printf("[DEBUG] ifaces with addresses: %+v\n", ifacesWithAddr)

for _, ifaceWithAddr := range ifacesWithAddr {
if mac == strings.ToUpper(ifaceWithAddr.Hwaddr) {
log.Printf("[DEBUG] found IPs for MAC=%+v: %+v\n", mac, ifaceWithAddr.Addrs)
if ifaceWithAddr.Hwaddr != "" {
log.Printf("[DEBUG] found IPs for: %+v\n", ifaceWithAddr.Name)
return true, false, nil
}
}

log.Printf("[DEBUG] %+v doesn't have IP address(es) yet...\n", mac)
log.Printf("[DEBUG] doesn't have IP address(es) yet...")
return false, false, nil
}

Expand Down

0 comments on commit a13c304

Please sign in to comment.