@@ -154,27 +154,29 @@ func domainGetIfacesInfo(virConn *libvirt.Libvirt, domain libvirt.Domain, rd *sc
154
154
return []libvirt.DomainInterface {}, nil
155
155
}
156
156
157
+ // setup source of interface address information
158
+ var addrsrc uint32
157
159
qemuAgentEnabled := rd .Get ("qemu_agent" ).(bool )
158
160
if qemuAgentEnabled {
159
- log .Print ("[DEBUG] Not implemented" )
161
+ addrsrc = uint32 (libvirt .DomainInterfaceAddressesSrcAgent )
162
+ log .Printf ("[DEBUG] qemu-agent used to query interface info" )
160
163
} 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" )
162
166
}
163
- var interfaces []libvirt.DomainInterface
164
167
165
168
// 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 )
169
171
if err != nil {
170
172
switch virErr := err .(type ) {
171
173
default :
172
- return interfaces , fmt .Errorf ("error retrieving interface addresses: %s " , virErr )
174
+ return interfaces , fmt .Errorf ("error retrieving interface addresses: %w " , virErr )
173
175
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 )
178
180
}
179
181
}
180
182
}
0 commit comments