2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// This step uploads a file containing the Parallels version, which
|
|
|
|
// can be useful for various provisioning reasons.
|
|
|
|
type StepUploadVersion struct {
|
|
|
|
Path string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepUploadVersion) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepUploadVersion) Cleanup(state multistep.StateBag) {}
|