builder/virtualbox: retry unregister a few times [GH-915]

This commit is contained in:
Mitchell Hashimoto 2014-03-01 16:20:02 +01:00
parent 5adcce912b
commit 239aabb554
1 changed files with 12 additions and 1 deletions

View File

@ -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))
}
}