2013-12-24 00:58:41 -05:00
|
|
|
package iso
|
2013-11-07 15:28:41 -05:00
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2013-11-07 15:28:41 -05:00
|
|
|
"fmt"
|
2018-01-22 20:21:10 -05:00
|
|
|
"log"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-11-07 15:28:41 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2018-01-22 18:31:41 -05:00
|
|
|
func (s *stepRemoteUpload) Run(_ context.Context, 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
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:16:28 -04:00
|
|
|
config := state.Get("config").(*Config)
|
2014-06-12 01:33:34 -04:00
|
|
|
checksum := config.ISOChecksum
|
|
|
|
checksumType := config.ISOChecksumType
|
|
|
|
|
2013-11-07 15:28:41 -05:00
|
|
|
ui.Say(s.Message)
|
|
|
|
log.Printf("Remote uploading: %s", path)
|
2014-06-12 01:33:34 -04:00
|
|
|
newPath, err := remote.UploadISO(path, checksum, checksumType)
|
2013-11-07 15:28:41 -05:00
|
|
|
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) {
|
|
|
|
}
|