post-processor/vagrant-cloud: better logging, document vcloud url

This commit is contained in:
Jack Pearkes 2014-06-25 12:46:25 -04:00
parent 450ba0bd9d
commit 46535e3a3c
8 changed files with 43 additions and 17 deletions

View File

@ -56,8 +56,15 @@ func (s *stepCreateProvider) Run(state multistep.StateBag) multistep.StepAction
}
func (s *stepCreateProvider) Cleanup(state multistep.StateBag) {
client := state.Get("client").(*VagrantCloudClient)
ui := state.Get("ui").(packer.Ui)
box := state.Get("box").(*Box)
version := state.Get("version").(*Version)
// If we didn't save the provider name, it likely doesn't exist
if s.name == "" {
ui.Say("Cleaning up provider")
ui.Message("Provider was not created, not deleting")
return
}
@ -70,10 +77,8 @@ func (s *stepCreateProvider) Cleanup(state multistep.StateBag) {
return
}
client := state.Get("client").(*VagrantCloudClient)
ui := state.Get("ui").(packer.Ui)
box := state.Get("box").(*Box)
version := state.Get("version").(*Version)
ui.Say("Cleaning up provider")
ui.Message(fmt.Sprintf("Deleting provider: %s", s.name))
path := fmt.Sprintf("box/%s/version/%v/provider/%s", box.Tag, version.Number, s.name)

View File

@ -7,9 +7,9 @@ import (
)
type Version struct {
Version string `json:"version"`
Description string `json:"description,omitempty"`
Number uint `json:"number,omitempty"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
Number uint `json:"number,omitempty"`
}
type stepCreateVersion struct {
@ -22,8 +22,10 @@ func (s *stepCreateVersion) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(Config)
box := state.Get("box").(*Box)
ui.Say(fmt.Sprintf("Creating version: %s", config.Version))
if hasVersion, v := box.HasVersion(config.Version); hasVersion {
ui.Say(fmt.Sprintf("Version exists: %s", config.Version))
ui.Message(fmt.Sprintf("Version exists, skipping creation"))
state.Put("version", v)
return multistep.ActionContinue
}
@ -36,8 +38,6 @@ func (s *stepCreateVersion) Run(state multistep.StateBag) multistep.StepAction {
wrapper := make(map[string]interface{})
wrapper["version"] = version
ui.Say(fmt.Sprintf("Creating version: %s", config.Version))
resp, err := client.Post(path, wrapper)
if err != nil || (resp.StatusCode != 200) {
@ -61,9 +61,15 @@ func (s *stepCreateVersion) Run(state multistep.StateBag) multistep.StepAction {
}
func (s *stepCreateVersion) Cleanup(state multistep.StateBag) {
client := state.Get("client").(*VagrantCloudClient)
ui := state.Get("ui").(packer.Ui)
config := state.Get("config").(Config)
box := state.Get("box").(*Box)
// If we didn't save the version number, it likely doesn't exist or
// already existed
if s.number == 0 {
ui.Message("Version was not created or previously existed, not deleting")
return
}
@ -76,12 +82,11 @@ func (s *stepCreateVersion) Cleanup(state multistep.StateBag) {
return
}
client := state.Get("client").(*VagrantCloudClient)
ui := state.Get("ui").(packer.Ui)
box := state.Get("box").(*Box)
path := fmt.Sprintf("box/%s/version/%v", box.Tag, s.number)
ui.Say("Cleaning up version")
ui.Message(fmt.Sprintf("Deleting version: %s", config.Version))
// No need for resp from the cleanup DELETE
_, err := client.Delete(path)

View File

@ -41,6 +41,8 @@ func (s *stepPrepareUpload) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
ui.Message(fmt.Sprintf("Box upload prepared with token %s", upload.Token))
// Save the upload details to the state
state.Put("upload", upload)

View File

@ -16,15 +16,15 @@ func (s *stepReleaseVersion) Run(state multistep.StateBag) multistep.StepAction
version := state.Get("version").(*Version)
config := state.Get("config").(Config)
ui.Say(fmt.Sprintf("Releasing version: %s", version.Version))
if config.NoRelease {
ui.Say(fmt.Sprintf("Not releasing version due to configuration: %s", version.Version))
ui.Message("Not releasing version due to configuration")
return multistep.ActionContinue
}
path := fmt.Sprintf("box/%s/version/%v/release", box.Tag, version.Number)
ui.Say(fmt.Sprintf("Releasing version: %s", version.Version))
resp, err := client.Put(path)
if err != nil || (resp.StatusCode != 200) {
@ -34,6 +34,8 @@ func (s *stepReleaseVersion) Run(state multistep.StateBag) multistep.StepAction
return multistep.ActionHalt
}
ui.Message(fmt.Sprintf("Version successfully released and available"))
return multistep.ActionContinue
}

View File

@ -18,6 +18,8 @@ func (s *stepUpload) Run(state multistep.StateBag) multistep.StepAction {
ui.Say(fmt.Sprintf("Uploading box: %s", artifactFilePath))
ui.Message("Depending on your internet connection and the size of the box, this may take some time")
resp, err := client.Upload(artifactFilePath, url)
if err != nil || (resp.StatusCode != 200) {
@ -25,6 +27,8 @@ func (s *stepUpload) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
ui.Message("Box succesfully uploaded")
return multistep.ActionContinue
}

View File

@ -52,6 +52,8 @@ func (s *stepVerifyBox) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
ui.Message("Box accessible and matches tag")
// Keep the box in state for later
state.Put("box", box)

View File

@ -78,6 +78,7 @@ func (s *stepVerifyUpload) Run(state multistep.StateBag) multistep.StepAction {
}
}()
ui.Message("Waiting for upload token match")
log.Printf("Waiting for up to 600 seconds for provider hosted token to match %s", upload.Token)
select {
@ -87,7 +88,9 @@ func (s *stepVerifyUpload) Run(state multistep.StateBag) multistep.StepAction {
return multistep.ActionHalt
}
ui.Message(fmt.Sprintf("Upload succesfully verified with token %s", providerCheck.HostedToken))
log.Printf("Box succesfully verified %s == %s", upload.Token, providerCheck.HostedToken)
return multistep.ActionContinue
case <-time.After(600 * time.Second):
state.Put("error", fmt.Errorf("Timeout while waiting to for upload to verify token '%s'", upload.Token))

View File

@ -66,6 +66,9 @@ access to on Vagrant Cloud, as well as authentication and version information.
on Vagrant Cloud, making it active. You can manually release the version
via the API or Web UI. Defaults to false.
* `vagrant_cloud_url` (string) - Override the base URL for Vagrant Cloud. This
is useful if you're using Vagrant Private Cloud in your own network. Defaults
to `https://vagrantcloud.com/api/v1`
## Use with Vagrant Post-Processor