Skip to content

Commit

Permalink
qemu-guest-agent network interface query (re)implemented
Browse files Browse the repository at this point in the history
Uses libvirt.DomainInterfaceAddressesSrcAgent in call to

virConn.DomainInterfaceAddresses
  • Loading branch information
maseman authored and dmacvicar committed Dec 11, 2021
1 parent 1883125 commit 06d383a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions libvirt/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,29 @@ func domainGetIfacesInfo(virConn *libvirt.Libvirt, domain libvirt.Domain, rd *sc
return []libvirt.DomainInterface{}, nil
}

// setup source of interface address information
var addrsrc uint32
qemuAgentEnabled := rd.Get("qemu_agent").(bool)
if qemuAgentEnabled {
log.Print("[DEBUG] Not implemented")
addrsrc = uint32(libvirt.DomainInterfaceAddressesSrcAgent)
log.Printf("[DEBUG] qemu-agent used to query interface info")
} else {
log.Printf("[DEBUG] qemu-agent is not used")
addrsrc = uint32(libvirt.DomainInterfaceAddressesSrcLease)
log.Printf("[DEBUG] Obtain interface info from dhcp lease file")
}
var interfaces []libvirt.DomainInterface

// get all the interfaces attached to libvirt networks
log.Print("[DEBUG] no interfaces could be obtained with qemu-agent: falling back to the libvirt API")

interfaces, err = virConn.DomainInterfaceAddresses(domain, uint32(libvirt.DomainInterfaceAddressesSrcLease), 0)
var interfaces []libvirt.DomainInterface
interfaces, err = virConn.DomainInterfaceAddresses(domain, addrsrc, 0)
if err != nil {
switch virErr := err.(type) {
default:
return interfaces, fmt.Errorf("error retrieving interface addresses: %s", virErr)
return interfaces, fmt.Errorf("error retrieving interface addresses: %w", virErr)
case libvirt.Error:
// FIXME ErrorDomain.fromQemu not available in libvirt.Error
// || libvirt.ErrorvirErr.Domain != libvirt.FROM_QEMU {
if virErr.Code != uint32(libvirt.ErrOperationInvalid) {
return interfaces, fmt.Errorf("error retrieving interface addresses: %s", err)
// Agent can be unresponsive if being installed/setup
if addrsrc == uint32(libvirt.DomainInterfaceAddressesSrcLease) && virErr.Code != uint32(libvirt.ErrOperationInvalid) ||
addrsrc == uint32(libvirt.DomainInterfaceAddressesSrcAgent) && virErr.Code != uint32(libvirt.ErrAgentUnresponsive) {
return interfaces, fmt.Errorf("Error retrieving interface addresses: %w", err)
}
}
}
Expand Down

0 comments on commit 06d383a

Please sign in to comment.