builder/vmware: unexport calculted config fields

This commit is contained in:
Mitchell Hashimoto 2013-07-14 21:23:46 +09:00
parent 033c90cfa3
commit 2ba0876d34
5 changed files with 16 additions and 16 deletions

View File

@ -41,14 +41,11 @@ type config struct {
HTTPPortMin uint `mapstructure:"http_port_min"` HTTPPortMin uint `mapstructure:"http_port_min"`
HTTPPortMax uint `mapstructure:"http_port_max"` HTTPPortMax uint `mapstructure:"http_port_max"`
BootCommand []string `mapstructure:"boot_command"` BootCommand []string `mapstructure:"boot_command"`
BootWait time.Duration ``
SkipCompaction bool `mapstructure:"skip_compaction"` SkipCompaction bool `mapstructure:"skip_compaction"`
ShutdownCommand string `mapstructure:"shutdown_command"` ShutdownCommand string `mapstructure:"shutdown_command"`
ShutdownTimeout time.Duration ``
SSHUser string `mapstructure:"ssh_username"` SSHUser string `mapstructure:"ssh_username"`
SSHPassword string `mapstructure:"ssh_password"` SSHPassword string `mapstructure:"ssh_password"`
SSHPort uint `mapstructure:"ssh_port"` SSHPort uint `mapstructure:"ssh_port"`
SSHWaitTimeout time.Duration ``
ToolsUploadFlavor string `mapstructure:"tools_upload_flavor"` ToolsUploadFlavor string `mapstructure:"tools_upload_flavor"`
ToolsUploadPath string `mapstructure:"tools_upload_path"` ToolsUploadPath string `mapstructure:"tools_upload_path"`
VMXData map[string]string `mapstructure:"vmx_data"` VMXData map[string]string `mapstructure:"vmx_data"`
@ -62,6 +59,10 @@ type config struct {
RawBootWait string `mapstructure:"boot_wait"` RawBootWait string `mapstructure:"boot_wait"`
RawShutdownTimeout string `mapstructure:"shutdown_timeout"` RawShutdownTimeout string `mapstructure:"shutdown_timeout"`
RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"` RawSSHWaitTimeout string `mapstructure:"ssh_wait_timeout"`
bootWait time.Duration ``
shutdownTimeout time.Duration ``
sshWaitTimeout time.Duration ``
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) error {
@ -222,7 +223,7 @@ func (b *Builder) Prepare(raws ...interface{}) error {
} }
if b.config.RawBootWait != "" { 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 { if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing boot_wait: %s", err)) 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.RawShutdownTimeout = "5m"
} }
b.config.ShutdownTimeout, err = time.ParseDuration(b.config.RawShutdownTimeout) b.config.shutdownTimeout, err = time.ParseDuration(b.config.RawShutdownTimeout)
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing shutdown_timeout: %s", err)) 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.RawSSHWaitTimeout = "20m"
} }
b.config.SSHWaitTimeout, err = time.ParseDuration(b.config.RawSSHWaitTimeout) b.config.sshWaitTimeout, err = time.ParseDuration(b.config.RawSSHWaitTimeout)
if err != nil { if err != nil {
errs = append(errs, fmt.Errorf("Failed parsing ssh_wait_timeout: %s", err)) 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) t.Errorf("bad output dir: %s", b.config.OutputDir)
} }
if b.config.SSHWaitTimeout != (20 * time.Minute) { if b.config.sshWaitTimeout != (20 * time.Minute) {
t.Errorf("bad wait timeout: %s", b.config.SSHWaitTimeout) t.Errorf("bad wait timeout: %s", b.config.sshWaitTimeout)
} }
if b.config.VMName != "packer-foo" { 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 // Wait the wait amount
if int64(config.BootWait) > 0 { if int64(config.bootWait) > 0 {
ui.Say(fmt.Sprintf("Waiting %s for boot...", config.BootWait.String())) ui.Say(fmt.Sprintf("Waiting %s for boot...", config.bootWait.String()))
time.Sleep(config.BootWait) time.Sleep(config.bootWait)
} }
return multistep.ActionContinue 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()) log.Printf("Shutdown stderr: %s", stderr.String())
// Wait for the machine to actually shut down // Wait for the machine to actually shut down
log.Printf("Waiting max %s for shutdown to complete", config.ShutdownTimeout) log.Printf("Waiting max %s for shutdown to complete", config.shutdownTimeout)
shutdownTimer := time.After(config.ShutdownTimeout) shutdownTimer := time.After(config.shutdownTimeout)
for { for {
running, _ := driver.IsRunning(vmxPath) running, _ := driver.IsRunning(vmxPath)
if !running { if !running {

View File

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