github.com/marksheahan/packer@v0.10.2-0.20160613200515-1acb2d6645a0/post-processor/vagrant-cloud/step_prepare_upload.go (about) 1 package vagrantcloud 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/multistep" 6 "github.com/mitchellh/packer/packer" 7 ) 8 9 type Upload struct { 10 Token string `json:"token"` 11 UploadPath string `json:"upload_path"` 12 } 13 14 type stepPrepareUpload struct { 15 } 16 17 func (s *stepPrepareUpload) Run(state multistep.StateBag) multistep.StepAction { 18 client := state.Get("client").(*VagrantCloudClient) 19 ui := state.Get("ui").(packer.Ui) 20 box := state.Get("box").(*Box) 21 version := state.Get("version").(*Version) 22 provider := state.Get("provider").(*Provider) 23 artifactFilePath := state.Get("artifactFilePath").(string) 24 25 path := fmt.Sprintf("box/%s/version/%v/provider/%s/upload", box.Tag, version.Version, provider.Name) 26 upload := &Upload{} 27 28 ui.Say(fmt.Sprintf("Preparing upload of box: %s", artifactFilePath)) 29 30 resp, err := client.Get(path) 31 32 if err != nil || (resp.StatusCode != 200) { 33 cloudErrors := &VagrantCloudErrors{} 34 err = decodeBody(resp, cloudErrors) 35 state.Put("error", fmt.Errorf("Error preparing upload: %s", cloudErrors.FormatErrors())) 36 return multistep.ActionHalt 37 } 38 39 if err = decodeBody(resp, upload); err != nil { 40 state.Put("error", fmt.Errorf("Error parsing upload response: %s", err)) 41 return multistep.ActionHalt 42 } 43 44 ui.Message(fmt.Sprintf("Box upload prepared with token %s", upload.Token)) 45 46 // Save the upload details to the state 47 state.Put("upload", upload) 48 49 return multistep.ActionContinue 50 } 51 52 func (s *stepPrepareUpload) Cleanup(state multistep.StateBag) { 53 // No cleanup 54 }