Skip to content

Commit

Permalink
Only try to shutdown VM if running
Browse files Browse the repository at this point in the history
As discussed in #212

Trying to stop a VM that is not running results in an error, so we only
do shutdowns for running VMs now

Possible power-states are "Running, Halted, Paused, Suspended"
  • Loading branch information
4censord authored and ddelnano committed Dec 14, 2022
1 parent c15010d commit b1cfb73
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion xoa/resource_xenorchestra_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,19 @@ func resourceVmDelete(d *schema.ResourceData, m interface{}) error {
vmReq := client.Vm{
Id: d.Id(),
}
err := c.HaltVm(vmReq)

vm, err := c.GetVm(vmReq)
if err != nil {
return err
}

if vm.PowerState == "Running" {
err = c.HaltVm(vmReq)
if err != nil {
return err
}
}

err = c.DeleteVm(d.Id())
if err != nil {
return err
Expand Down

0 comments on commit b1cfb73

Please sign in to comment.