github.com/sneal/packer@v0.5.2/builder/vmware/iso/step_upload_tools.go (about) 1 package iso 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 "os" 8 ) 9 10 type toolsUploadPathTemplate struct { 11 Flavor string 12 } 13 14 type stepUploadTools struct{} 15 16 func (*stepUploadTools) Run(state multistep.StateBag) multistep.StepAction { 17 config := state.Get("config").(*config) 18 if config.ToolsUploadFlavor == "" { 19 return multistep.ActionContinue 20 } 21 22 comm := state.Get("communicator").(packer.Communicator) 23 tools_source := state.Get("tools_upload_source").(string) 24 ui := state.Get("ui").(packer.Ui) 25 26 ui.Say(fmt.Sprintf("Uploading the '%s' VMware Tools", config.ToolsUploadFlavor)) 27 f, err := os.Open(tools_source) 28 if err != nil { 29 state.Put("error", fmt.Errorf("Error opening VMware Tools ISO: %s", err)) 30 return multistep.ActionHalt 31 } 32 defer f.Close() 33 34 tplData := &toolsUploadPathTemplate{Flavor: config.ToolsUploadFlavor} 35 config.ToolsUploadPath, err = config.tpl.Process(config.ToolsUploadPath, tplData) 36 if err != nil { 37 err := fmt.Errorf("Error preparing upload path: %s", err) 38 state.Put("error", err) 39 ui.Error(err.Error()) 40 return multistep.ActionHalt 41 } 42 43 if err := comm.Upload(config.ToolsUploadPath, f); err != nil { 44 err := fmt.Errorf("Error uploading VMware Tools: %s", err) 45 state.Put("error", err) 46 ui.Error(err.Error()) 47 return multistep.ActionHalt 48 } 49 50 return multistep.ActionContinue 51 } 52 53 func (*stepUploadTools) Cleanup(multistep.StateBag) {}