Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up terraform apply when domains are shutdown #474

Merged
merged 1 commit into from
Nov 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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