builder/vmware: Add a boot wait in seconds

This commit is contained in:
Mitchell Hashimoto 2013-06-05 15:48:13 -07:00
parent 009b509138
commit 429ff62128
3 changed files with 17 additions and 7 deletions

View File

@ -14,12 +14,13 @@ type Builder struct {
} }
type config struct { type config struct {
DiskName string `mapstructure:"vmdk_name"` DiskName string `mapstructure:"vmdk_name"`
ISOUrl string `mapstructure:"iso_url"` ISOUrl string `mapstructure:"iso_url"`
VMName string `mapstructure:"vm_name"` VMName string `mapstructure:"vm_name"`
OutputDir string `mapstructure:"output_directory"` OutputDir string `mapstructure:"output_directory"`
HTTPDir string `mapstructure:"http_directory"` HTTPDir string `mapstructure:"http_directory"`
BootCommand []string `mapstructure:"boot_command"` BootCommand []string `mapstructure:"boot_command"`
BootWait uint `mapstructure:"boot_wait"`
} }
func (b *Builder) Prepare(raw interface{}) (err error) { func (b *Builder) Prepare(raw interface{}) (err error) {

View File

@ -17,7 +17,7 @@ import (
// //
// Produces: // Produces:
// http_port int - The port the HTTP server started on. // http_port int - The port the HTTP server started on.
type stepHTTPServer struct{ type stepHTTPServer struct {
l net.Listener l net.Listener
} }

View File

@ -5,21 +5,24 @@ import (
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"os/exec" "os/exec"
"time"
) )
// This step runs the created virtual machine. // This step runs the created virtual machine.
// //
// Uses: // Uses:
// config *config
// ui packer.Ui // ui packer.Ui
// vmx_path string // vmx_path string
// //
// Produces: // Produces:
// <nothing> // <nothing>
type stepRun struct{ type stepRun struct {
vmxPath string vmxPath string
} }
func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction { func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
config := state["config"].(*config)
ui := state["ui"].(packer.Ui) ui := state["ui"].(packer.Ui)
vmxPath := state["vmx_path"].(string) vmxPath := state["vmx_path"].(string)
@ -35,6 +38,12 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
// Set the VMX path so that we know we started the machine // Set the VMX path so that we know we started the machine
s.vmxPath = vmxPath s.vmxPath = vmxPath
// Wait the wait amount
if config.BootWait > 0 {
ui.Say(fmt.Sprintf("Waiting %d seconds for boot...", config.BootWait))
time.Sleep(config.BootWait * time.Second)
}
return multistep.ActionContinue return multistep.ActionContinue
} }