2014-06-23 15:48:51 -04:00
|
|
|
package vagrantcloud
|
|
|
|
|
|
|
|
import (
|
2014-06-24 15:58:45 -04:00
|
|
|
"fmt"
|
2014-06-23 15:48:51 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
2014-06-24 15:58:45 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
2014-06-23 15:48:51 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepUpload struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepUpload) Run(state multistep.StateBag) multistep.StepAction {
|
2014-06-24 15:58:45 -04:00
|
|
|
client := state.Get("client").(*VagrantCloudClient)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
upload := state.Get("upload").(*Upload)
|
|
|
|
artifactFilePath := state.Get("artifactFilePath").(string)
|
|
|
|
url := upload.UploadPath
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Uploading box: %s", artifactFilePath))
|
|
|
|
|
|
|
|
resp, err := client.Upload(artifactFilePath, url)
|
|
|
|
|
|
|
|
if err != nil || (resp.StatusCode != 200) {
|
|
|
|
state.Put("error", fmt.Errorf("Error uploading Box: %s", resp.Body))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2014-06-23 15:48:51 -04:00
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepUpload) Cleanup(state multistep.StateBag) {
|
2014-06-24 15:58:45 -04:00
|
|
|
// No cleanup
|
2014-06-23 15:48:51 -04:00
|
|
|
}
|