Skip to content

Commit

Permalink
fix(domain): update domain running state when refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Naewis committed Nov 21, 2019
1 parent c611c1d commit d55a3ae
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libvirt/resource_libvirt_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,16 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
}
}

// We save runnig state to not mix what we have and what we want
requiredStatus := d.Get("running")

err = resourceLibvirtDomainRead(d, meta)
if err != nil {
return err
}

d.Set("running", requiredStatus)

// we must read devices again in order to set some missing ip/MAC/host mappings
for i := 0; i < d.Get("network_interface.#").(int); i++ {
prefix := fmt.Sprintf("network_interface.%d", i)
Expand Down Expand Up @@ -731,6 +736,11 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error reading domain autostart setting: %s", err)
}

domainRunningNow, err := domainIsRunning(*domain)
if err != nil {
return fmt.Errorf("Error reading domain running state : %s", err)
}

d.Set("name", domainDef.Name)
d.Set("vcpu", domainDef.VCPU)
d.Set("memory", domainDef.Memory)
Expand All @@ -739,6 +749,7 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error {
d.Set("cpu", domainDef.CPU)
d.Set("arch", domainDef.OS.Type.Arch)
d.Set("autostart", autostart)
d.Set("running", domainRunningNow)

cmdLines, err := splitKernelCmdLine(domainDef.OS.Cmdline)
if err != nil {
Expand Down

0 comments on commit d55a3ae

Please sign in to comment.