Skip to content

Commit

Permalink
Do not try contacting qemu-agent if domain is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
moio committed Nov 9, 2018
1 parent afd5c1a commit b730c9e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions libvirt/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ func domainIsRunning(domain libvirt.Domain) (bool, error) {
}

func domainGetIfacesInfo(domain libvirt.Domain, rd *schema.ResourceData) ([]libvirt.DomainInterface, error) {
domainRunningNow, err := domainIsRunning(domain)
if err != nil {
return []libvirt.DomainInterface{}, err
}
if !domainRunningNow {
log.Print("[DEBUG] no interfaces could be obtained: domain not running")
return []libvirt.DomainInterface{}, nil
}

qemuAgentEnabled := rd.Get("qemu_agent").(bool)
if qemuAgentEnabled {
// get all the interfaces using the qemu-agent, this includes also
Expand All @@ -168,15 +177,6 @@ func domainGetIfacesInfo(domain libvirt.Domain, rd *schema.ResourceData) ([]libv
// 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")

domainRunningNow, err := domainIsRunning(domain)
if err != nil {
return interfaces, err
}
if !domainRunningNow {
log.Print("[DEBUG] no interfaces could be obtained with libvirt API: domain not running")
return interfaces, nil
}

interfaces, err = domain.ListAllInterfaceAddresses(libvirt.DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE)
if err != nil {
switch err.(type) {
Expand Down

0 comments on commit b730c9e

Please sign in to comment.