Skip to content

Commit 06d383a

Browse files
masemandmacvicar
authored andcommitted
qemu-guest-agent network interface query (re)implemented
Uses libvirt.DomainInterfaceAddressesSrcAgent in call to virConn.DomainInterfaceAddresses
1 parent 1883125 commit 06d383a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

libvirt/domain.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,29 @@ func domainGetIfacesInfo(virConn *libvirt.Libvirt, domain libvirt.Domain, rd *sc
154154
return []libvirt.DomainInterface{}, nil
155155
}
156156

157+
// setup source of interface address information
158+
var addrsrc uint32
157159
qemuAgentEnabled := rd.Get("qemu_agent").(bool)
158160
if qemuAgentEnabled {
159-
log.Print("[DEBUG] Not implemented")
161+
addrsrc = uint32(libvirt.DomainInterfaceAddressesSrcAgent)
162+
log.Printf("[DEBUG] qemu-agent used to query interface info")
160163
} else {
161-
log.Printf("[DEBUG] qemu-agent is not used")
164+
addrsrc = uint32(libvirt.DomainInterfaceAddressesSrcLease)
165+
log.Printf("[DEBUG] Obtain interface info from dhcp lease file")
162166
}
163-
var interfaces []libvirt.DomainInterface
164167

165168
// get all the interfaces attached to libvirt networks
166-
log.Print("[DEBUG] no interfaces could be obtained with qemu-agent: falling back to the libvirt API")
167-
168-
interfaces, err = virConn.DomainInterfaceAddresses(domain, uint32(libvirt.DomainInterfaceAddressesSrcLease), 0)
169+
var interfaces []libvirt.DomainInterface
170+
interfaces, err = virConn.DomainInterfaceAddresses(domain, addrsrc, 0)
169171
if err != nil {
170172
switch virErr := err.(type) {
171173
default:
172-
return interfaces, fmt.Errorf("error retrieving interface addresses: %s", virErr)
174+
return interfaces, fmt.Errorf("error retrieving interface addresses: %w", virErr)
173175
case libvirt.Error:
174-
// FIXME ErrorDomain.fromQemu not available in libvirt.Error
175-
// || libvirt.ErrorvirErr.Domain != libvirt.FROM_QEMU {
176-
if virErr.Code != uint32(libvirt.ErrOperationInvalid) {
177-
return interfaces, fmt.Errorf("error retrieving interface addresses: %s", err)
176+
// Agent can be unresponsive if being installed/setup
177+
if addrsrc == uint32(libvirt.DomainInterfaceAddressesSrcLease) && virErr.Code != uint32(libvirt.ErrOperationInvalid) ||
178+
addrsrc == uint32(libvirt.DomainInterfaceAddressesSrcAgent) && virErr.Code != uint32(libvirt.ErrAgentUnresponsive) {
179+
return interfaces, fmt.Errorf("Error retrieving interface addresses: %w", err)
178180
}
179181
}
180182
}

0 commit comments

Comments
 (0)