github.com/alouche/packer@v0.3.7/builder/vmware/step_upload_tools.go (about) 1 package vmware 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 state.Put("error", fmt.Errorf("Error uploading VMware Tools: %s", err)) 45 return multistep.ActionHalt 46 } 47 48 return multistep.ActionContinue 49 } 50 51 func (*stepUploadTools) Cleanup(multistep.StateBag) {}