github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/builder/parallels/common/step_upload_version.go (about) 1 package common 2 3 import ( 4 "bytes" 5 "fmt" 6 "log" 7 8 "github.com/mitchellh/multistep" 9 "github.com/mitchellh/packer/packer" 10 ) 11 12 // StepUploadVersion is a step that uploads a file containing the version of 13 // Parallels Desktop, which can be useful for various provisioning reasons. 14 // 15 // Uses: 16 // communicator packer.Communicator 17 // driver Driver 18 // ui packer.Ui 19 type StepUploadVersion struct { 20 Path string 21 } 22 23 // Run uploads a file containing the version of Parallels Desktop. 24 func (s *StepUploadVersion) Run(state multistep.StateBag) multistep.StepAction { 25 comm := state.Get("communicator").(packer.Communicator) 26 driver := state.Get("driver").(Driver) 27 ui := state.Get("ui").(packer.Ui) 28 29 if s.Path == "" { 30 log.Println("ParallelsVersionFile is empty. Not uploading.") 31 return multistep.ActionContinue 32 } 33 34 version, err := driver.Version() 35 if err != nil { 36 state.Put("error", fmt.Errorf("Error reading version for metadata upload: %s", err)) 37 return multistep.ActionHalt 38 } 39 40 ui.Say(fmt.Sprintf("Uploading Parallels version info (%s)", version)) 41 var data bytes.Buffer 42 data.WriteString(version) 43 if err := comm.Upload(s.Path, &data, nil); err != nil { 44 state.Put("error", fmt.Errorf("Error uploading Parallels version: %s", err)) 45 return multistep.ActionHalt 46 } 47 48 return multistep.ActionContinue 49 } 50 51 // Cleanup does nothing. 52 func (s *StepUploadVersion) Cleanup(state multistep.StateBag) {}