github.com/rothwerx/packer@v0.9.0/builder/vmware/iso/step_remote_upload.go (about) 1 package iso 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 vmwcommon "github.com/mitchellh/packer/builder/vmware/common" 7 "github.com/mitchellh/packer/packer" 8 "log" 9 ) 10 11 // stepRemoteUpload uploads some thing from the state bag to a remote driver 12 // (if it can) and stores that new remote path into the state bag. 13 type stepRemoteUpload struct { 14 Key string 15 Message string 16 } 17 18 func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction { 19 driver := state.Get("driver").(vmwcommon.Driver) 20 ui := state.Get("ui").(packer.Ui) 21 22 remote, ok := driver.(RemoteDriver) 23 if !ok { 24 return multistep.ActionContinue 25 } 26 27 path, ok := state.Get(s.Key).(string) 28 if !ok { 29 return multistep.ActionContinue 30 } 31 32 config := state.Get("config").(*Config) 33 checksum := config.ISOChecksum 34 checksumType := config.ISOChecksumType 35 36 ui.Say(s.Message) 37 log.Printf("Remote uploading: %s", path) 38 newPath, err := remote.UploadISO(path, checksum, checksumType) 39 if err != nil { 40 err := fmt.Errorf("Error uploading file: %s", err) 41 state.Put("error", err) 42 ui.Error(err.Error()) 43 return multistep.ActionHalt 44 } 45 46 state.Put(s.Key, newPath) 47 return multistep.ActionContinue 48 } 49 50 func (s *stepRemoteUpload) Cleanup(state multistep.StateBag) { 51 }