2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2014-04-06 13:21:22 -04:00
|
|
|
"fmt"
|
2016-12-11 14:13:37 -05:00
|
|
|
"log"
|
|
|
|
|
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"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
2016-12-11 17:37:41 -05:00
|
|
|
// StepUploadVersion is a step that uploads a file containing the version of
|
|
|
|
// Parallels Desktop, which can be useful for various provisioning reasons.
|
|
|
|
//
|
|
|
|
// Uses:
|
|
|
|
// communicator packer.Communicator
|
|
|
|
// driver Driver
|
|
|
|
// ui packer.Ui
|
2014-04-06 13:21:22 -04:00
|
|
|
type StepUploadVersion struct {
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
|
2016-12-16 14:51:55 -05:00
|
|
|
// Run uploads a file containing the version of Parallels Desktop.
|
2018-01-22 18:31:41 -05:00
|
|
|
func (s *StepUploadVersion) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2014-04-06 13:21:22 -04:00
|
|
|
comm := state.Get("communicator").(packer.Communicator)
|
|
|
|
driver := state.Get("driver").(Driver)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
if s.Path == "" {
|
|
|
|
log.Println("ParallelsVersionFile is empty. Not uploading.")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
version, err := driver.Version()
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Error reading version for metadata upload: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Uploading Parallels version info (%s)", version))
|
|
|
|
var data bytes.Buffer
|
|
|
|
data.WriteString(version)
|
2014-05-10 00:03:35 -04:00
|
|
|
if err := comm.Upload(s.Path, &data, nil); err != nil {
|
2014-04-06 13:21:22 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error uploading Parallels version: %s", err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2016-12-16 14:51:55 -05:00
|
|
|
// Cleanup does nothing.
|
2014-04-06 13:21:22 -04:00
|
|
|
func (s *StepUploadVersion) Cleanup(state multistep.StateBag) {}
|