packer-cn/builder/virtualbox/common/step_upload_version.go

45 lines
1.2 KiB
Go
Raw Normal View History

2013-12-22 14:50:29 -05:00
package common
import (
"bytes"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
// This step uploads a file containing the VirtualBox version, which
// can be useful for various provisioning reasons.
2013-12-22 14:50:29 -05:00
type StepUploadVersion struct {
Path string
}
2013-12-22 14:50:29 -05:00
func (s *StepUploadVersion) Run(state multistep.StateBag) multistep.StepAction {
2013-08-31 15:44:58 -04:00
comm := state.Get("communicator").(packer.Communicator)
2013-12-22 14:50:29 -05:00
driver := state.Get("driver").(Driver)
2013-08-31 15:44:58 -04:00
ui := state.Get("ui").(packer.Ui)
2013-12-22 14:50:29 -05:00
if s.Path == "" {
log.Println("VBoxVersionFile is empty. Not uploading.")
return multistep.ActionContinue
}
version, err := driver.Version()
if err != nil {
2013-08-31 15:44:58 -04:00
state.Put("error", fmt.Errorf("Error reading version for metadata upload: %s", err))
return multistep.ActionHalt
}
ui.Say(fmt.Sprintf("Uploading VirtualBox version info (%s)", version))
var data bytes.Buffer
data.WriteString(version)
2013-12-22 14:50:29 -05:00
if err := comm.Upload(s.Path, &data); err != nil {
2013-08-31 15:44:58 -04:00
state.Put("error", fmt.Errorf("Error uploading VirtualBox version: %s", err))
return multistep.ActionHalt
}
return multistep.ActionContinue
}
2013-12-22 14:50:29 -05:00
func (s *StepUploadVersion) Cleanup(state multistep.StateBag) {}