builder/vmware: Improve check for VMware cleanup
This commit is contained in:
parent
529f72c084
commit
4d5edcaac0
|
@ -10,6 +10,7 @@ import (
|
||||||
//
|
//
|
||||||
// Uses:
|
// Uses:
|
||||||
// driver Driver
|
// driver Driver
|
||||||
|
// full_disk_path string
|
||||||
// ui packer.Ui
|
// ui packer.Ui
|
||||||
//
|
//
|
||||||
// Produces:
|
// Produces:
|
||||||
|
@ -23,7 +24,7 @@ func (stepCompactDisk) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
|
|
||||||
ui.Say("Compacting the disk image")
|
ui.Say("Compacting the disk image")
|
||||||
if err := driver.CompactDisk(full_disk_path); err != nil {
|
if err := driver.CompactDisk(full_disk_path); err != nil {
|
||||||
state["error"] := fmt.Errorf("Error compacting disk: %s", err)
|
state["error"] = fmt.Errorf("Error compacting disk: %s", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import (
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"log"
|
"log"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,8 +74,33 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Giving VMware a few extra seconds to clean up after itself...")
|
ui.Message("Waiting for VMware to clean up after itself...")
|
||||||
time.Sleep(5 * time.Second)
|
lockPattern := filepath.Join(config.OutputDir, "*.lck")
|
||||||
|
timer := time.After(15 * time.Second)
|
||||||
|
LockWaitLoop:
|
||||||
|
for {
|
||||||
|
locks, err := filepath.Glob(lockPattern)
|
||||||
|
if err == nil {
|
||||||
|
if len(locks) == 0 {
|
||||||
|
log.Println("No more lock files found. VMware is clean.")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(locks) == 1 && strings.HasSuffix(locks[0], ".vmx.lck") {
|
||||||
|
log.Println("Only waiting on VMX lock. VMware is clean.")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Waiting on lock files: %#v", locks)
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-timer:
|
||||||
|
log.Println("Reached timeout on waiting for clean VMware. Assuming clean.")
|
||||||
|
break LockWaitLoop
|
||||||
|
case <-time.After(1 * time.Second):
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("VM shut down.")
|
log.Println("VM shut down.")
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
|
|
Loading…
Reference in New Issue