2013-12-24 00:58:41 -05:00
|
|
|
package iso
|
2013-11-07 15:28:41 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
2013-12-24 13:31:57 -05:00
|
|
|
vmwcommon "github.com/mitchellh/packer/builder/vmware/common"
|
2013-11-07 15:28:41 -05:00
|
|
|
"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 {
|
2013-12-24 13:31:57 -05:00
|
|
|
driver := state.Get("driver").(vmwcommon.Driver)
|
2013-11-07 15:28:41 -05:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
remote, ok := driver.(RemoteDriver)
|
|
|
|
if !ok {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2014-05-03 05:23:20 -04:00
|
|
|
path, ok := state.Get(s.Key).(string)
|
|
|
|
if !ok {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2013-11-07 15:28:41 -05:00
|
|
|
ui.Say(s.Message)
|
|
|
|
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) {
|
|
|
|
}
|