github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/post-processor/vagrant-cloud/step_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 stepUpload struct {
    10  }
    11  
    12  func (s *stepUpload) Run(state multistep.StateBag) multistep.StepAction {
    13  	client := state.Get("client").(*VagrantCloudClient)
    14  	ui := state.Get("ui").(packer.Ui)
    15  	upload := state.Get("upload").(*Upload)
    16  	artifactFilePath := state.Get("artifactFilePath").(string)
    17  	url := upload.UploadPath
    18  
    19  	ui.Say(fmt.Sprintf("Uploading box: %s", artifactFilePath))
    20  
    21  	ui.Message("Depending on your internet connection and the size of the box, this may take some time")
    22  
    23  	resp, err := client.Upload(artifactFilePath, url)
    24  
    25  	if err != nil || (resp.StatusCode != 200) {
    26  		state.Put("error", fmt.Errorf("Error uploading Box: %s", err))
    27  		return multistep.ActionHalt
    28  	}
    29  
    30  	ui.Message("Box succesfully uploaded")
    31  
    32  	return multistep.ActionContinue
    33  }
    34  
    35  func (s *stepUpload) Cleanup(state multistep.StateBag) {
    36  	// No cleanup
    37  }