github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/post-processor/vagrant-cloud/step_release_version.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 stepReleaseVersion struct {
    10  }
    11  
    12  func (s *stepReleaseVersion) Run(state multistep.StateBag) multistep.StepAction {
    13  	client := state.Get("client").(*VagrantCloudClient)
    14  	ui := state.Get("ui").(packer.Ui)
    15  	box := state.Get("box").(*Box)
    16  	version := state.Get("version").(*Version)
    17  	config := state.Get("config").(Config)
    18  
    19  	ui.Say(fmt.Sprintf("Releasing version: %s", version.Version))
    20  
    21  	if config.NoRelease {
    22  		ui.Message("Not releasing version due to configuration")
    23  		return multistep.ActionContinue
    24  	}
    25  
    26  	path := fmt.Sprintf("box/%s/version/%v/release", box.Tag, version.Number)
    27  
    28  	resp, err := client.Put(path)
    29  
    30  	if err != nil || (resp.StatusCode != 200) {
    31  		cloudErrors := &VagrantCloudErrors{}
    32  		err = decodeBody(resp, cloudErrors)
    33  		state.Put("error", fmt.Errorf("Error releasing version: %s", cloudErrors.FormatErrors()))
    34  		return multistep.ActionHalt
    35  	}
    36  
    37  	ui.Message(fmt.Sprintf("Version successfully released and available"))
    38  
    39  	return multistep.ActionContinue
    40  }
    41  
    42  func (s *stepReleaseVersion) Cleanup(state multistep.StateBag) {
    43  	// No cleanup
    44  }