packer-cn/builder/vmware/step_remote_upload.go

43 lines
983 B
Go

package vmware
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
// stepRemoteUpload uploads some thing from the state bag to a remote driver
// (if it can) and stores that new remote path into the state bag.
type stepRemoteUpload struct {
Key string
Message string
}
func (s *stepRemoteUpload) Run(state multistep.StateBag) multistep.StepAction {
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
remote, ok := driver.(RemoteDriver)
if !ok {
return multistep.ActionContinue
}
ui.Say(s.Message)
path := state.Get(s.Key).(string)
log.Printf("Remote uploading: %s", path)
newPath, err := remote.UploadISO(path)
if err != nil {
err := fmt.Errorf("Error uploading file: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put(s.Key, newPath)
return multistep.ActionContinue
}
func (s *stepRemoteUpload) Cleanup(state multistep.StateBag) {
}