builder/vmware: unexport calculted config fields

This commit is contained in:
Mitchell Hashimoto 2013-07-14 21:23:46 +09:00
parent 16960a52f2
commit 6b6beae3b8
5 changed files with 16 additions and 16 deletions

View File

@ -41,14 +41,11 @@ type config struct {
HTTPPortMin uint `mapstructure:"http_port_min"`
HTTPPortMax uint `mapstructure:"http_port_max"`
BootCommand []string `mapstructure:"boot_command"`
BootWait time.Duration ``
SkipCompaction bool `mapstructure:"skip_compaction"`
ShutdownCommand string `mapstructure:"shutdown_command"`
ShutdownTimeout time.Duration ``
SSHUser string `mapstructure:"ssh_username"`
SSHPassword string `mapstructure:"ssh_password"`
SSHPort uint `mapstructure:"ssh_port"`
SSHWaitTimeout time.Duration ``
ToolsUploadFlavor string `mapstructure:"tools_upload_flavor"`
ToolsUploadPath string `mapstructure:"tools_upload_path"`
VMXData map[string]string `mapstructure:"vmx_data"`
@ -62,6 +59,10 @@ type config struct {
RawBootWait string `mapstructure:"boot_wait"`
RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"`
bootWait time.Duration ``
shutdownTimeout time.Duration ``
sshWaitTimeout time.Duration ``
}
func (b *Builder) Prepare(raws ...interface{}) error {
@ -222,7 +223,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
}
if b.config.RawBootWait != "" {
b.config.BootWait, err = time.ParseDuration(b.config.RawBootWait)
b.config.bootWait, err = time.ParseDuration(b.config.RawBootWait)
if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err))
}
@ -232,7 +233,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b.config.RawShutdownTimeout = "5m"
}
b.config.ShutdownTimeout, err = time.ParseDuration(b.config.RawShutdownTimeout)
b.config.shutdownTimeout, err = time.ParseDuration(b.config.RawShutdownTimeout)
if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err))
}
@ -241,7 +242,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b.config.RawSSHWaitTimeout = "20m"
}
b.config.SSHWaitTimeout, err = time.ParseDuration(b.config.RawSSHWaitTimeout)
b.config.sshWaitTimeout, err = time.ParseDuration(b.config.RawSSHWaitTimeout)
if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing ssh_wait_timeout: %s", err))
}

View File

@ -126,8 +126,8 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
t.Errorf("bad output dir: %s", b.config.OutputDir)
}
if b.config.SSHWaitTimeout != (20 * time.Minute) {
t.Errorf("bad wait timeout: %s", b.config.SSHWaitTimeout)
if b.config.sshWaitTimeout != (20 * time.Minute) {
t.Errorf("bad wait timeout: %s", b.config.sshWaitTimeout)
}
if b.config.VMName != "packer-foo" {

View File

@ -49,9 +49,9 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction {
}
// Wait the wait amount
if int64(config.BootWait) > 0 {
ui.Say(fmt.Sprintf("Waiting %s for boot...", config.BootWait.String()))
time.Sleep(config.BootWait)
if int64(config.bootWait) > 0 {
ui.Say(fmt.Sprintf("Waiting %s for boot...", config.bootWait.String()))
time.Sleep(config.bootWait)
}
return multistep.ActionContinue

View File

@ -65,8 +65,8 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction {
log.Printf("Shutdown stderr: %s", stderr.String())
// Wait for the machine to actually shut down
log.Printf("Waiting max %s for shutdown to complete", config.ShutdownTimeout)
shutdownTimer := time.After(config.ShutdownTimeout)
log.Printf("Waiting max %s for shutdown to complete", config.shutdownTimeout)
shutdownTimer := time.After(config.shutdownTimeout)
for {
running, _ := driver.IsRunning(vmxPath)
if !running {

View File

@ -41,9 +41,8 @@ func (s *stepWaitForSSH) Run(state map[string]interface{}) multistep.StepAction
waitDone <- true
}()
log.Printf("Waiting for SSH, up to timeout: %s", config.SSHWaitTimeout.String())
timeout := time.After(config.SSHWaitTimeout)
log.Printf("Waiting for SSH, up to timeout: %s", config.sshWaitTimeout.String())
timeout := time.After(config.sshWaitTimeout)
WaitLoop:
for {
// Wait for either SSH to become available, a timeout to occur,