mirror of https://github.com/hashicorp/packer
parent
a678362701
commit
c899051c9c
@ -1,44 +0,0 @@
|
|||||||
package vagrantcloud
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Box struct {
|
|
||||||
client *VagrantCloudClient
|
|
||||||
Tag string `json:"tag"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://vagrantcloud.com/docs/boxes
|
|
||||||
func (v VagrantCloudClient) Box(tag string) (*Box, error) {
|
|
||||||
resp, err := v.Get(tag)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Error retrieving box: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
box := &Box{}
|
|
||||||
|
|
||||||
if err = decodeBody(resp, box); err != nil {
|
|
||||||
return nil, fmt.Errorf("Error parsing box response: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return box, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save persist the provider over HTTP to Vagrant Cloud
|
|
||||||
func (b Box) Save(tag string) (bool, error) {
|
|
||||||
resp, err := b.client.Get(tag)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("Error retrieving box: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
box := &Box{}
|
|
||||||
|
|
||||||
if err = decodeBody(resp, box); err != nil {
|
|
||||||
return false, fmt.Errorf("Error parsing box response: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package vagrantcloud
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
|
)
|
||||||
|
|
||||||
|
type stepCreateProvider struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepCreateProvider) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
return multistep.ActionContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepCreateProvider) Cleanup(state multistep.StateBag) {
|
||||||
|
}
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
package vagrantcloud
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
|
"github.com/mitchellh/packer/packer"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Version struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
Number uint `json:"number"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type NewVersion struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type stepCreateVersion struct {
|
||||||
|
number uint // number of the version, if needed in cleanup
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepCreateVersion) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
client := state.Get("client").(*VagrantCloudClient)
|
||||||
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
config := state.Get("config").(Config)
|
||||||
|
box := state.Get("box").(*Box)
|
||||||
|
|
||||||
|
path := fmt.Sprintf("box/%s/versions", box.Tag)
|
||||||
|
|
||||||
|
// Wrap the version in a version object for the API
|
||||||
|
wrapper := make(map[string]interface{})
|
||||||
|
wrapper["version"] = NewVersion{Version: config.Version}
|
||||||
|
|
||||||
|
ui.Say(fmt.Sprintf("Creating version: %s", config.Version))
|
||||||
|
|
||||||
|
resp, err := client.Post(path, wrapper)
|
||||||
|
version := &Version{}
|
||||||
|
|
||||||
|
if err != nil || (resp.StatusCode != 200) {
|
||||||
|
cloudErrors := &VagrantCloudErrors{};
|
||||||
|
err = decodeBody(resp, cloudErrors);
|
||||||
|
state.Put("error", fmt.Errorf("Error creating version: %s", cloudErrors.FormatErrors()))
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = decodeBody(resp, version); err != nil {
|
||||||
|
state.Put("error", fmt.Errorf("Error parsing version response: %s", err))
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the number for cleanup
|
||||||
|
s.number = version.Number
|
||||||
|
|
||||||
|
state.Put("version", version)
|
||||||
|
|
||||||
|
return multistep.ActionContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepCreateVersion) Cleanup(state multistep.StateBag) {
|
||||||
|
// If we didn't save the version number, it likely doesn't exist
|
||||||
|
if (s.number == 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client := state.Get("client").(*VagrantCloudClient)
|
||||||
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
box := state.Get("box").(*Box)
|
||||||
|
|
||||||
|
path := fmt.Sprintf("box/%s/version/%s", box.Tag, s.number)
|
||||||
|
|
||||||
|
// No need for resp from the cleanup DELETE
|
||||||
|
_, err := client.Delete(path)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ui.Error(fmt.Sprintf("Error destroying version: %s", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package vagrantcloud
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
|
)
|
||||||
|
|
||||||
|
type stepPrepareUpload struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepPrepareUpload) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
return multistep.ActionContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepPrepareUpload) Cleanup(state multistep.StateBag) {
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package vagrantcloud
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
|
)
|
||||||
|
|
||||||
|
type stepUpload struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepUpload) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
return multistep.ActionContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepUpload) Cleanup(state multistep.StateBag) {
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
package vagrantcloud
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
|
"github.com/mitchellh/packer/packer"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Box struct {
|
||||||
|
Tag string `json:"tag"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type stepVerifyBox struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepVerifyBox) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
client := state.Get("client").(*VagrantCloudClient)
|
||||||
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
config := state.Get("config").(Config)
|
||||||
|
|
||||||
|
ui.Say(fmt.Sprintf("Verifying box is accessible: %s", config.Tag))
|
||||||
|
|
||||||
|
path := fmt.Sprintf("box/%s", config.Tag)
|
||||||
|
resp, err := client.Get(path)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
state.Put("error", fmt.Errorf("Error retrieving box: %s", err))
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
box := &Box{}
|
||||||
|
|
||||||
|
if err = decodeBody(resp, box); err != nil {
|
||||||
|
state.Put("error", fmt.Errorf("Error parsing box response: %s", err))
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
if box.Tag != config.Tag {
|
||||||
|
state.Put("error", fmt.Errorf("Could not verify box: %s", err))
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep the box in state for later
|
||||||
|
state.Put("box", box)
|
||||||
|
|
||||||
|
// Box exists and is accessible
|
||||||
|
return multistep.ActionContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepVerifyBox) Cleanup(state multistep.StateBag) {
|
||||||
|
// no cleanup needed
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package vagrantcloud
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
|
)
|
||||||
|
|
||||||
|
type stepVerifyUpload struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepVerifyUpload) Run(state multistep.StateBag) multistep.StepAction {
|
||||||
|
return multistep.ActionContinue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *stepVerifyUpload) Cleanup(state multistep.StateBag) {
|
||||||
|
}
|
||||||
@ -1,58 +0,0 @@
|
|||||||
package vagrantcloud
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Version struct {
|
|
||||||
client *VagrantCloudClient
|
|
||||||
Version string `json:"version"`
|
|
||||||
Number string `json:"number"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://vagrantcloud.com/docs/versions
|
|
||||||
func (v VagrantCloudClient) Version(number string) (*Version, error) {
|
|
||||||
resp, err := v.Get(number)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Error retrieving version: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
version := &Version{}
|
|
||||||
|
|
||||||
if err = decodeBody(resp, version); err != nil {
|
|
||||||
return nil, fmt.Errorf("Error parsing version response: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return version, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save persists the Version over HTTP to Vagrant Cloud
|
|
||||||
func (v Version) Create() (bool, error) {
|
|
||||||
resp, err := v.client.Post(v.Number, v)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("Error retrieving box: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = decodeBody(resp, v); err != nil {
|
|
||||||
return false, fmt.Errorf("Error parsing box response: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deletes the Version over HTTP to Vagrant Cloud
|
|
||||||
func (v Version) Destroy() (bool, error) {
|
|
||||||
resp, err := v.client.Delete(v.Number)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("Error destroying version: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = decodeBody(resp, v); err != nil {
|
|
||||||
return false, fmt.Errorf("Error parsing box response: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
Loading…
Reference in new issue