@@ -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