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))
|
|
|
|
|
2014-06-25 12:46:25 -04:00
|
|
|
ui.Message("Depending on your internet connection and the size of the box, this may take some time")
|
|
|
|
|
2014-06-24 15:58:45 -04:00
|
|
|
resp, err := client.Upload(artifactFilePath, url)
|
|
|
|
|
|
|
|
if err != nil || (resp.StatusCode != 200) {
|
2014-06-25 11:54:49 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error uploading Box: %s", err))
|
2014-06-24 15:58:45 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2014-06-25 12:46:25 -04:00
|
|
|
ui.Message("Box succesfully uploaded")
|
|
|
|
|
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
|
|
|
}
|