From 92fec52c141a531b4e2d31c6a47dbdc93f52ff9a Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Fri, 22 Mar 2024 09:51:40 -0500 Subject: [PATCH] Refresh VM state before attempting to rm when a vm was running and then forceably stopped, the vm state still appearing as running and would error when trying to remove. a simple refresh of the vm status fixes this. Signed-off-by: Brent Baude --- pkg/hypervctl/vm.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/hypervctl/vm.go b/pkg/hypervctl/vm.go index daab766..7fcae23 100644 --- a/pkg/hypervctl/vm.go +++ b/pkg/hypervctl/vm.go @@ -568,8 +568,12 @@ func (vm *VirtualMachine) remove() (int32, error) { srv *wmiext.Service ) + refreshVM, err := vm.vmm.GetMachine(vm.ElementName) + if err != nil { + return 0, err + } // Check for disabled/stopped state - if !Disabled.equal(vm.EnabledState) { + if !Disabled.equal(refreshVM.EnabledState) { return -1, ErrMachineStateInvalid } if srv, err = NewLocalHyperVService(); err != nil {