From 46535e3a3cb7147b0d194b5b7017457ae52bbb8e Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Wed, 25 Jun 2014 12:46:25 -0400 Subject: [PATCH] post-processor/vagrant-cloud: better logging, document vcloud url --- .../vagrant-cloud/step_create_provider.go | 13 +++++++--- .../vagrant-cloud/step_create_version.go | 25 +++++++++++-------- .../vagrant-cloud/step_prepare_upload.go | 2 ++ .../vagrant-cloud/step_release_version.go | 8 +++--- post-processor/vagrant-cloud/step_upload.go | 4 +++ .../vagrant-cloud/step_verify_box.go | 2 ++ .../vagrant-cloud/step_verify_upload.go | 3 +++ .../vagrant-cloud.html.markdown | 3 +++ 8 files changed, 43 insertions(+), 17 deletions(-) diff --git a/post-processor/vagrant-cloud/step_create_provider.go b/post-processor/vagrant-cloud/step_create_provider.go index e149ddba1..887932c4f 100644 --- a/post-processor/vagrant-cloud/step_create_provider.go +++ b/post-processor/vagrant-cloud/step_create_provider.go @@ -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) diff --git a/post-processor/vagrant-cloud/step_create_version.go b/post-processor/vagrant-cloud/step_create_version.go index 882a5971d..8108577cc 100644 --- a/post-processor/vagrant-cloud/step_create_version.go +++ b/post-processor/vagrant-cloud/step_create_version.go @@ -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) diff --git a/post-processor/vagrant-cloud/step_prepare_upload.go b/post-processor/vagrant-cloud/step_prepare_upload.go index 5c7fee2b9..5c82d02c3 100644 --- a/post-processor/vagrant-cloud/step_prepare_upload.go +++ b/post-processor/vagrant-cloud/step_prepare_upload.go @@ -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) diff --git a/post-processor/vagrant-cloud/step_release_version.go b/post-processor/vagrant-cloud/step_release_version.go index 4e40f5ca3..43512bdca 100644 --- a/post-processor/vagrant-cloud/step_release_version.go +++ b/post-processor/vagrant-cloud/step_release_version.go @@ -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 } diff --git a/post-processor/vagrant-cloud/step_upload.go b/post-processor/vagrant-cloud/step_upload.go index 0e8d20606..f82f125f8 100644 --- a/post-processor/vagrant-cloud/step_upload.go +++ b/post-processor/vagrant-cloud/step_upload.go @@ -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 } diff --git a/post-processor/vagrant-cloud/step_verify_box.go b/post-processor/vagrant-cloud/step_verify_box.go index 32ae9a5b6..bbbc3b4b7 100644 --- a/post-processor/vagrant-cloud/step_verify_box.go +++ b/post-processor/vagrant-cloud/step_verify_box.go @@ -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) diff --git a/post-processor/vagrant-cloud/step_verify_upload.go b/post-processor/vagrant-cloud/step_verify_upload.go index eb787886f..120bd647d 100644 --- a/post-processor/vagrant-cloud/step_verify_upload.go +++ b/post-processor/vagrant-cloud/step_verify_upload.go @@ -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)) diff --git a/website/source/docs/post-processors/vagrant-cloud.html.markdown b/website/source/docs/post-processors/vagrant-cloud.html.markdown index d95ee9343..499234262 100644 --- a/website/source/docs/post-processors/vagrant-cloud.html.markdown +++ b/website/source/docs/post-processors/vagrant-cloud.html.markdown @@ -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