From 239aabb554ed8a2a2886066725a6e3a2b111da42 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 1 Mar 2014 16:20:02 +0100 Subject: [PATCH] builder/virtualbox: retry unregister a few times [GH-915] --- builder/virtualbox/iso/step_create_vm.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/builder/virtualbox/iso/step_create_vm.go b/builder/virtualbox/iso/step_create_vm.go index 942d33363..a1f42a748 100644 --- a/builder/virtualbox/iso/step_create_vm.go +++ b/builder/virtualbox/iso/step_create_vm.go @@ -5,6 +5,7 @@ import ( "github.com/mitchellh/multistep" vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common" "github.com/mitchellh/packer/packer" + "time" ) // This step creates the actual virtual machine. @@ -65,7 +66,17 @@ func (s *stepCreateVM) Cleanup(state multistep.StateBag) { ui := state.Get("ui").(packer.Ui) ui.Say("Unregistering and deleting virtual machine...") - if err := driver.VBoxManage("unregistervm", s.vmName, "--delete"); err != nil { + var err error = nil + for i := 0; i < 5; i++ { + err = driver.VBoxManage("unregistervm", s.vmName, "--delete") + if err == nil { + break + } + + time.Sleep(1 * time.Second * time.Duration(i)) + } + + if err != nil { ui.Error(fmt.Sprintf("Error deleting virtual machine: %s", err)) } }