github.com/sneal/packer@v0.5.2/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  	ui.Say(s.Message)
    28  	path := state.Get(s.Key).(string)
    29  	log.Printf("Remote uploading: %s", path)
    30  	newPath, err := remote.UploadISO(path)
    31  	if err != nil {
    32  		err := fmt.Errorf("Error uploading file: %s", err)
    33  		state.Put("error", err)
    34  		ui.Error(err.Error())
    35  		return multistep.ActionHalt
    36  	}
    37  
    38  	state.Put(s.Key, newPath)
    39  	return multistep.ActionContinue
    40  }
    41  
    42  func (s *stepRemoteUpload) Cleanup(state multistep.StateBag) {
    43  }