|
|
|
|
@ -9,11 +9,9 @@ import (
|
|
|
|
|
type Version struct {
|
|
|
|
|
Version string `json:"version"`
|
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
|
Number uint `json:"number,omitempty"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type stepCreateVersion struct {
|
|
|
|
|
number uint // number of the version, if needed in cleanup
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *stepCreateVersion) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
@ -52,9 +50,6 @@ func (s *stepCreateVersion) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save the number for cleanup
|
|
|
|
|
s.number = version.Number
|
|
|
|
|
|
|
|
|
|
state.Put("version", version)
|
|
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
|
@ -63,15 +58,8 @@ 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
|
|
|
|
|
}
|
|
|
|
|
version := state.Get("version").(*Version)
|
|
|
|
|
|
|
|
|
|
_, cancelled := state.GetOk(multistep.StateCancelled)
|
|
|
|
|
_, halted := state.GetOk(multistep.StateHalted)
|
|
|
|
|
@ -82,10 +70,10 @@ func (s *stepCreateVersion) Cleanup(state multistep.StateBag) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path := fmt.Sprintf("box/%s/version/%v", box.Tag, s.number)
|
|
|
|
|
path := fmt.Sprintf("box/%s/version/%v", box.Tag, version.Version)
|
|
|
|
|
|
|
|
|
|
ui.Say("Cleaning up version")
|
|
|
|
|
ui.Message(fmt.Sprintf("Deleting version: %s", config.Version))
|
|
|
|
|
ui.Message(fmt.Sprintf("Deleting version: %s", version.Version))
|
|
|
|
|
|
|
|
|
|
// No need for resp from the cleanup DELETE
|
|
|
|
|
_, err := client.Delete(path)
|
|
|
|
|
|