diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index 501e942e7..80627df56 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -376,12 +376,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe } // Setup the state bag - state := make(map[string]interface{}) - state["cache"] = cache - state["config"] = &b.config - state["driver"] = driver - state["hook"] = hook - state["ui"] = ui + state := new(multistep.BasicStateBag) + state.Put("cache", cache) + state.Put("config", &b.config) + state.Put("driver", driver) + state.Put("hook", hook) + state.Put("ui", ui) // Run! if b.config.PackerDebug { @@ -396,16 +396,16 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe b.runner.Run(state) // If there was an error, return that - if rawErr, ok := state["error"]; ok { + if rawErr, ok := state.GetOk("error"); ok { return nil, rawErr.(error) } // If we were interrupted or cancelled, then just exit. - if _, ok := state[multistep.StateCancelled]; ok { + if _, ok := state.GetOk(multistep.StateCancelled); ok { return nil, errors.New("Build was cancelled.") } - if _, ok := state[multistep.StateHalted]; ok { + if _, ok := state.GetOk(multistep.StateHalted); ok { return nil, errors.New("Build was halted.") } diff --git a/builder/vmware/ssh.go b/builder/vmware/ssh.go index 2f1232fd6..121d79709 100644 --- a/builder/vmware/ssh.go +++ b/builder/vmware/ssh.go @@ -4,16 +4,17 @@ import ( gossh "code.google.com/p/go.crypto/ssh" "errors" "fmt" + "github.com/mitchellh/multistep" "github.com/mitchellh/packer/communicator/ssh" "io/ioutil" "log" "os" ) -func sshAddress(state map[string]interface{}) (string, error) { - config := state["config"].(*config) - driver := state["driver"].(Driver) - vmxPath := state["vmx_path"].(string) +func sshAddress(state multistep.StateBag) (string, error) { + config := state.Get("config").(*config) + driver := state.Get("driver").(Driver) + vmxPath := state.Get("vmx_path").(string) log.Println("Lookup up IP information...") f, err := os.Open(vmxPath) @@ -58,8 +59,8 @@ func sshAddress(state map[string]interface{}) (string, error) { return fmt.Sprintf("%s:%d", ipAddress, config.SSHPort), nil } -func sshConfig(state map[string]interface{}) (*gossh.ClientConfig, error) { - config := state["config"].(*config) +func sshConfig(state multistep.StateBag) (*gossh.ClientConfig, error) { + config := state.Get("config").(*config) auth := []gossh.ClientAuth{ gossh.ClientAuthPassword(ssh.Password(config.SSHPassword)), diff --git a/builder/vmware/step_clean_files.go b/builder/vmware/step_clean_files.go index ba6f4b04e..f429b4464 100644 --- a/builder/vmware/step_clean_files.go +++ b/builder/vmware/step_clean_files.go @@ -23,9 +23,9 @@ var KeepFileExtensions = []string{".nvram", ".vmdk", ".vmsd", ".vmx", ".vmxf"} // type stepCleanFiles struct{} -func (stepCleanFiles) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - ui := state["ui"].(packer.Ui) +func (stepCleanFiles) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + ui := state.Get("ui").(packer.Ui) ui.Say("Deleting unnecessary VMware files...") visit := func(path string, info os.FileInfo, err error) error { @@ -55,11 +55,11 @@ func (stepCleanFiles) Run(state map[string]interface{}) multistep.StepAction { } if err := filepath.Walk(config.OutputDir, visit); err != nil { - state["error"] = err + state.Put("error", err) return multistep.ActionHalt } return multistep.ActionContinue } -func (stepCleanFiles) Cleanup(map[string]interface{}) {} +func (stepCleanFiles) Cleanup(multistep.StateBag) {} diff --git a/builder/vmware/step_clean_vmx.go b/builder/vmware/step_clean_vmx.go index b6519858b..21273ffa2 100644 --- a/builder/vmware/step_clean_vmx.go +++ b/builder/vmware/step_clean_vmx.go @@ -22,20 +22,20 @@ import ( // type stepCleanVMX struct{} -func (s stepCleanVMX) Run(state map[string]interface{}) multistep.StepAction { - isoPath := state["iso_path"].(string) - ui := state["ui"].(packer.Ui) - vmxPath := state["vmx_path"].(string) +func (s stepCleanVMX) Run(state multistep.StateBag) multistep.StepAction { + isoPath := state.Get("iso_path").(string) + ui := state.Get("ui").(packer.Ui) + vmxPath := state.Get("vmx_path").(string) ui.Say("Cleaning VMX prior to finishing up...") vmxData, err := s.readVMX(vmxPath) if err != nil { - state["error"] = fmt.Errorf("Error reading VMX: %s", err) + state.Put("error", fmt.Errorf("Error reading VMX: %s", err)) return multistep.ActionHalt } - if _, ok := state["floppy_path"]; ok { + if _, ok := state.GetOk("floppy_path"); ok { // Delete the floppy0 entries so the floppy is no longer mounted ui.Message("Unmounting floppy from VMX...") for k, _ := range vmxData { @@ -67,14 +67,14 @@ func (s stepCleanVMX) Run(state map[string]interface{}) multistep.StepAction { // Rewrite the VMX if err := WriteVMX(vmxPath, vmxData); err != nil { - state["error"] = fmt.Errorf("Error writing VMX: %s", err) + state.Put("error", fmt.Errorf("Error writing VMX: %s", err)) return multistep.ActionHalt } return multistep.ActionContinue } -func (stepCleanVMX) Cleanup(map[string]interface{}) {} +func (stepCleanVMX) Cleanup(multistep.StateBag) {} func (stepCleanVMX) readVMX(vmxPath string) (map[string]string, error) { vmxF, err := os.Open(vmxPath) diff --git a/builder/vmware/step_compact_disk.go b/builder/vmware/step_compact_disk.go index 05bbc62da..4a87b4a1a 100644 --- a/builder/vmware/step_compact_disk.go +++ b/builder/vmware/step_compact_disk.go @@ -20,11 +20,11 @@ import ( // type stepCompactDisk struct{} -func (stepCompactDisk) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - driver := state["driver"].(Driver) - ui := state["ui"].(packer.Ui) - full_disk_path := state["full_disk_path"].(string) +func (stepCompactDisk) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + driver := state.Get("driver").(Driver) + ui := state.Get("ui").(packer.Ui) + full_disk_path := state.Get("full_disk_path").(string) if config.SkipCompaction == true { log.Println("Skipping disk compaction step...") @@ -33,11 +33,11 @@ func (stepCompactDisk) Run(state map[string]interface{}) multistep.StepAction { ui.Say("Compacting the disk image") if err := driver.CompactDisk(full_disk_path); err != nil { - state["error"] = fmt.Errorf("Error compacting disk: %s", err) + state.Put("error", fmt.Errorf("Error compacting disk: %s", err)) return multistep.ActionHalt } return multistep.ActionContinue } -func (stepCompactDisk) Cleanup(map[string]interface{}) {} +func (stepCompactDisk) Cleanup(multistep.StateBag) {} diff --git a/builder/vmware/step_configure_vnc.go b/builder/vmware/step_configure_vnc.go index 341097949..bee28c8d4 100644 --- a/builder/vmware/step_configure_vnc.go +++ b/builder/vmware/step_configure_vnc.go @@ -22,15 +22,15 @@ import ( // vnc_port uint - The port that VNC is configured to listen on. type stepConfigureVNC struct{} -func (stepConfigureVNC) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - ui := state["ui"].(packer.Ui) - vmxPath := state["vmx_path"].(string) +func (stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + ui := state.Get("ui").(packer.Ui) + vmxPath := state.Get("vmx_path").(string) f, err := os.Open(vmxPath) if err != nil { err := fmt.Errorf("Error reading VMX data: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -38,7 +38,7 @@ func (stepConfigureVNC) Run(state map[string]interface{}) multistep.StepAction { vmxBytes, err := ioutil.ReadAll(f) if err != nil { err := fmt.Errorf("Error reading VMX data: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -67,15 +67,15 @@ func (stepConfigureVNC) Run(state map[string]interface{}) multistep.StepAction { if err := WriteVMX(vmxPath, vmxData); err != nil { err := fmt.Errorf("Error writing VMX data: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } - state["vnc_port"] = vncPort + state.Put("vnc_port", vncPort) return multistep.ActionContinue } -func (stepConfigureVNC) Cleanup(map[string]interface{}) { +func (stepConfigureVNC) Cleanup(multistep.StateBag) { } diff --git a/builder/vmware/step_create_disk.go b/builder/vmware/step_create_disk.go index 00bb0e2e2..3b526812e 100644 --- a/builder/vmware/step_create_disk.go +++ b/builder/vmware/step_create_disk.go @@ -18,23 +18,23 @@ import ( // full_disk_path (string) - The full path to the created disk. type stepCreateDisk struct{} -func (stepCreateDisk) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - driver := state["driver"].(Driver) - ui := state["ui"].(packer.Ui) +func (stepCreateDisk) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + driver := state.Get("driver").(Driver) + ui := state.Get("ui").(packer.Ui) ui.Say("Creating virtual machine disk") full_disk_path := filepath.Join(config.OutputDir, config.DiskName+".vmdk") if err := driver.CreateDisk(full_disk_path, fmt.Sprintf("%dM", config.DiskSize), config.DiskTypeId); err != nil { err := fmt.Errorf("Error creating disk: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } - state["full_disk_path"] = full_disk_path + state.Put("full_disk_path", full_disk_path) return multistep.ActionContinue } -func (stepCreateDisk) Cleanup(map[string]interface{}) {} +func (stepCreateDisk) Cleanup(multistep.StateBag) {} diff --git a/builder/vmware/step_create_vmx.go b/builder/vmware/step_create_vmx.go index 91a2b474b..311b7a9ca 100644 --- a/builder/vmware/step_create_vmx.go +++ b/builder/vmware/step_create_vmx.go @@ -28,10 +28,10 @@ type vmxTemplateData struct { // vmx_path string - The path to the VMX file. type stepCreateVMX struct{} -func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - isoPath := state["iso_path"].(string) - ui := state["ui"].(packer.Ui) +func (stepCreateVMX) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + isoPath := state.Get("iso_path").(string) + ui := state.Get("ui").(packer.Ui) ui.Say("Building and writing VMX file") @@ -47,7 +47,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction { f, err := os.Open(config.VMXTemplatePath) if err != nil { err := fmt.Errorf("Error reading VMX template: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -56,7 +56,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction { rawBytes, err := ioutil.ReadAll(f) if err != nil { err := fmt.Errorf("Error reading VMX template: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -67,7 +67,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction { vmxContents, err := config.tpl.Process(vmxTemplate, tplData) if err != nil { err := fmt.Errorf("Error procesing VMX template: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -81,7 +81,7 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction { } } - if floppyPathRaw, ok := state["floppy_path"]; ok { + if floppyPathRaw, ok := state.GetOk("floppy_path"); ok { log.Println("Floppy path present, setting in VMX") vmxData["floppy0.present"] = "TRUE" vmxData["floppy0.fileType"] = "file" @@ -91,17 +91,17 @@ func (stepCreateVMX) Run(state map[string]interface{}) multistep.StepAction { vmxPath := filepath.Join(config.OutputDir, config.VMName+".vmx") if err := WriteVMX(vmxPath, vmxData); err != nil { err := fmt.Errorf("Error creating VMX file: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } - state["vmx_path"] = vmxPath + state.Put("vmx_path", vmxPath) return multistep.ActionContinue } -func (stepCreateVMX) Cleanup(map[string]interface{}) { +func (stepCreateVMX) Cleanup(multistep.StateBag) { } // This is the default VMX template used if no other template is given. diff --git a/builder/vmware/step_http_server.go b/builder/vmware/step_http_server.go index af4a35beb..084816f63 100644 --- a/builder/vmware/step_http_server.go +++ b/builder/vmware/step_http_server.go @@ -23,13 +23,13 @@ type stepHTTPServer struct { l net.Listener } -func (s *stepHTTPServer) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - ui := state["ui"].(packer.Ui) +func (s *stepHTTPServer) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + ui := state.Get("ui").(packer.Ui) var httpPort uint = 0 if config.HTTPDir == "" { - state["http_port"] = httpPort + state.Put("http_port", httpPort) return multistep.ActionContinue } @@ -62,12 +62,12 @@ func (s *stepHTTPServer) Run(state map[string]interface{}) multistep.StepAction go server.Serve(s.l) // Save the address into the state so it can be accessed in the future - state["http_port"] = httpPort + state.Put("http_port", httpPort) return multistep.ActionContinue } -func (s *stepHTTPServer) Cleanup(map[string]interface{}) { +func (s *stepHTTPServer) Cleanup(multistep.StateBag) { if s.l != nil { // Close the listener so that the HTTP server stops s.l.Close() diff --git a/builder/vmware/step_prepare_output_dir.go b/builder/vmware/step_prepare_output_dir.go index 738bedca3..bb5149cad 100644 --- a/builder/vmware/step_prepare_output_dir.go +++ b/builder/vmware/step_prepare_output_dir.go @@ -10,9 +10,9 @@ import ( type stepPrepareOutputDir struct{} -func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - ui := state["ui"].(packer.Ui) +func (stepPrepareOutputDir) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + ui := state.Get("ui").(packer.Ui) if _, err := os.Stat(config.OutputDir); err == nil && config.PackerForce { ui.Say("Deleting previous output directory...") @@ -20,20 +20,20 @@ func (stepPrepareOutputDir) Run(state map[string]interface{}) multistep.StepActi } if err := os.MkdirAll(config.OutputDir, 0755); err != nil { - state["error"] = err + state.Put("error", err) return multistep.ActionHalt } return multistep.ActionContinue } -func (stepPrepareOutputDir) Cleanup(state map[string]interface{}) { - _, cancelled := state[multistep.StateCancelled] - _, halted := state[multistep.StateHalted] +func (stepPrepareOutputDir) Cleanup(state multistep.StateBag) { + _, cancelled := state.GetOk(multistep.StateCancelled) + _, halted := state.GetOk(multistep.StateHalted) if cancelled || halted { - config := state["config"].(*config) - ui := state["ui"].(packer.Ui) + config := state.Get("config").(*config) + ui := state.Get("ui").(packer.Ui) ui.Say("Deleting output directory...") for i := 0; i < 5; i++ { diff --git a/builder/vmware/step_prepare_tools.go b/builder/vmware/step_prepare_tools.go index 0df461321..e26bcf8ed 100644 --- a/builder/vmware/step_prepare_tools.go +++ b/builder/vmware/step_prepare_tools.go @@ -8,9 +8,9 @@ import ( type stepPrepareTools struct{} -func (*stepPrepareTools) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - driver := state["driver"].(Driver) +func (*stepPrepareTools) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + driver := state.Get("driver").(Driver) if config.ToolsUploadFlavor == "" { return multistep.ActionContinue @@ -18,16 +18,16 @@ func (*stepPrepareTools) Run(state map[string]interface{}) multistep.StepAction path := driver.ToolsIsoPath(config.ToolsUploadFlavor) if _, err := os.Stat(path); err != nil { - state["error"] = fmt.Errorf( + state.Put("error", fmt.Errorf( "Couldn't find VMware tools for '%s'! VMware often downloads these\n"+ "tools on-demand. However, to do this, you need to create a fake VM\n"+ "of the proper type then click the 'install tools' option in the\n"+ - "VMware GUI.", config.ToolsUploadFlavor) + "VMware GUI.", config.ToolsUploadFlavor)) return multistep.ActionHalt } - state["tools_upload_source"] = path + state.Put("tools_upload_source", path) return multistep.ActionContinue } -func (*stepPrepareTools) Cleanup(map[string]interface{}) {} +func (*stepPrepareTools) Cleanup(multistep.StateBag) {} diff --git a/builder/vmware/step_run.go b/builder/vmware/step_run.go index 75ce071f7..2fe56eec7 100644 --- a/builder/vmware/step_run.go +++ b/builder/vmware/step_run.go @@ -22,12 +22,12 @@ type stepRun struct { vmxPath string } -func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - driver := state["driver"].(Driver) - ui := state["ui"].(packer.Ui) - vmxPath := state["vmx_path"].(string) - vncPort := state["vnc_port"].(uint) +func (s *stepRun) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + driver := state.Get("driver").(Driver) + ui := state.Get("ui").(packer.Ui) + vmxPath := state.Get("vmx_path").(string) + vncPort := state.Get("vnc_port").(uint) // Set the VMX path so that we know we started the machine s.bootTime = time.Now() @@ -43,7 +43,7 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction { if err := driver.Start(vmxPath, config.Headless); err != nil { err := fmt.Errorf("Error starting VM: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -57,9 +57,9 @@ func (s *stepRun) Run(state map[string]interface{}) multistep.StepAction { return multistep.ActionContinue } -func (s *stepRun) Cleanup(state map[string]interface{}) { - driver := state["driver"].(Driver) - ui := state["ui"].(packer.Ui) +func (s *stepRun) Cleanup(state multistep.StateBag) { + driver := state.Get("driver").(Driver) + ui := state.Get("ui").(packer.Ui) // If we started the machine... stop it. if s.vmxPath != "" { diff --git a/builder/vmware/step_shutdown.go b/builder/vmware/step_shutdown.go index 4355a047f..dae402763 100644 --- a/builder/vmware/step_shutdown.go +++ b/builder/vmware/step_shutdown.go @@ -27,12 +27,12 @@ import ( // type stepShutdown struct{} -func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction { - comm := state["communicator"].(packer.Communicator) - config := state["config"].(*config) - driver := state["driver"].(Driver) - ui := state["ui"].(packer.Ui) - vmxPath := state["vmx_path"].(string) +func (s *stepShutdown) Run(state multistep.StateBag) multistep.StepAction { + comm := state.Get("communicator").(packer.Communicator) + config := state.Get("config").(*config) + driver := state.Get("driver").(Driver) + ui := state.Get("ui").(packer.Ui) + vmxPath := state.Get("vmx_path").(string) if config.ShutdownCommand != "" { ui.Say("Gracefully halting virtual machine...") @@ -46,7 +46,7 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction { } if err := comm.Start(cmd); err != nil { err := fmt.Errorf("Failed to send shutdown command: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -56,9 +56,9 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction { // If the command failed to run, notify the user in some way. if cmd.ExitStatus != 0 { - state["error"] = fmt.Errorf( + state.Put("error", fmt.Errorf( "Shutdown command has non-zero exit status.\n\nStdout: %s\n\nStderr: %s", - stdout.String(), stderr.String()) + stdout.String(), stderr.String())) return multistep.ActionHalt } @@ -77,7 +77,7 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction { select { case <-shutdownTimer: err := errors.New("Timeout while waiting for machine to shut down.") - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt default: @@ -87,7 +87,7 @@ func (s *stepShutdown) Run(state map[string]interface{}) multistep.StepAction { } else { if err := driver.Stop(vmxPath); err != nil { err := fmt.Errorf("Error stopping VM: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -132,4 +132,4 @@ LockWaitLoop: return multistep.ActionContinue } -func (s *stepShutdown) Cleanup(state map[string]interface{}) {} +func (s *stepShutdown) Cleanup(state multistep.StateBag) {} diff --git a/builder/vmware/step_type_boot_command.go b/builder/vmware/step_type_boot_command.go index 2bc831913..804328613 100644 --- a/builder/vmware/step_type_boot_command.go +++ b/builder/vmware/step_type_boot_command.go @@ -34,18 +34,18 @@ type bootCommandTemplateData struct { // type stepTypeBootCommand struct{} -func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) - httpPort := state["http_port"].(uint) - ui := state["ui"].(packer.Ui) - vncPort := state["vnc_port"].(uint) +func (s *stepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) + httpPort := state.Get("http_port").(uint) + ui := state.Get("ui").(packer.Ui) + vncPort := state.Get("vnc_port").(uint) // Connect to VNC ui.Say("Connecting to VM via VNC") nc, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", vncPort)) if err != nil { err := fmt.Errorf("Error connecting to VNC: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -54,7 +54,7 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc c, err := vnc.Client(nc, &vnc.ClientConfig{Exclusive: true}) if err != nil { err := fmt.Errorf("Error handshaking with VNC: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -73,7 +73,7 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc hostIp, err := ipFinder.HostIP() if err != nil { err := fmt.Errorf("Error detecting host IP: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } @@ -91,14 +91,14 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc command, err := config.tpl.Process(command, tplData) if err != nil { err := fmt.Errorf("Error preparing boot command: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } // Check for interrupts between typing things so we can cancel // since this isn't the fastest thing. - if _, ok := state[multistep.StateCancelled]; ok { + if _, ok := state.GetOk(multistep.StateCancelled); ok { return multistep.ActionHalt } @@ -108,7 +108,7 @@ func (s *stepTypeBootCommand) Run(state map[string]interface{}) multistep.StepAc return multistep.ActionContinue } -func (*stepTypeBootCommand) Cleanup(map[string]interface{}) {} +func (*stepTypeBootCommand) Cleanup(multistep.StateBag) {} func vncSendString(c *vnc.ClientConn, original string) { special := make(map[string]uint32) diff --git a/builder/vmware/step_upload_tools.go b/builder/vmware/step_upload_tools.go index 9bbc5572a..630faef8d 100644 --- a/builder/vmware/step_upload_tools.go +++ b/builder/vmware/step_upload_tools.go @@ -13,20 +13,20 @@ type toolsUploadPathTemplate struct { type stepUploadTools struct{} -func (*stepUploadTools) Run(state map[string]interface{}) multistep.StepAction { - config := state["config"].(*config) +func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction { + config := state.Get("config").(*config) if config.ToolsUploadFlavor == "" { return multistep.ActionContinue } - comm := state["communicator"].(packer.Communicator) - tools_source := state["tools_upload_source"].(string) - ui := state["ui"].(packer.Ui) + comm := state.Get("communicator").(packer.Communicator) + tools_source := state.Get("tools_upload_source").(string) + ui := state.Get("ui").(packer.Ui) ui.Say(fmt.Sprintf("Uploading the '%s' VMware Tools", config.ToolsUploadFlavor)) f, err := os.Open(tools_source) if err != nil { - state["error"] = fmt.Errorf("Error opening VMware Tools ISO: %s", err) + state.Put("error", fmt.Errorf("Error opening VMware Tools ISO: %s", err)) return multistep.ActionHalt } defer f.Close() @@ -35,17 +35,17 @@ func (*stepUploadTools) Run(state map[string]interface{}) multistep.StepAction { config.ToolsUploadPath, err = config.tpl.Process(config.ToolsUploadPath, tplData) if err != nil { err := fmt.Errorf("Error preparing upload path: %s", err) - state["error"] = err + state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } if err := comm.Upload(config.ToolsUploadPath, f); err != nil { - state["error"] = fmt.Errorf("Error uploading VMware Tools: %s", err) + state.Put("error", fmt.Errorf("Error uploading VMware Tools: %s", err)) return multistep.ActionHalt } return multistep.ActionContinue } -func (*stepUploadTools) Cleanup(map[string]interface{}) {} +func (*stepUploadTools) Cleanup(multistep.StateBag) {}