|
|
|
|
@ -10,17 +10,17 @@ import (
|
|
|
|
|
|
|
|
|
|
type stepSnapshot struct{}
|
|
|
|
|
|
|
|
|
|
func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
|
|
|
|
|
client := state["client"].(*DigitalOceanClient)
|
|
|
|
|
ui := state["ui"].(packer.Ui)
|
|
|
|
|
c := state["config"].(config)
|
|
|
|
|
dropletId := state["droplet_id"].(uint)
|
|
|
|
|
func (s *stepSnapshot) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
client := state.Get("client").(*DigitalOceanClient)
|
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
c := state.Get("config").(config)
|
|
|
|
|
dropletId := state.Get("droplet_id").(uint)
|
|
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Creating snapshot: %v", c.SnapshotName))
|
|
|
|
|
err := client.CreateSnapshot(dropletId, c.SnapshotName)
|
|
|
|
|
if err != nil {
|
|
|
|
|
err := fmt.Errorf("Error creating snapshot: %s", err)
|
|
|
|
|
state["error"] = err
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
@ -29,7 +29,7 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
|
|
|
|
|
err = waitForDropletState("active", dropletId, client, c)
|
|
|
|
|
if err != nil {
|
|
|
|
|
err := fmt.Errorf("Error waiting for snapshot to complete: %s", err)
|
|
|
|
|
state["error"] = err
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
@ -38,7 +38,7 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
|
|
|
|
|
images, err := client.Images()
|
|
|
|
|
if err != nil {
|
|
|
|
|
err := fmt.Errorf("Error looking up snapshot ID: %s", err)
|
|
|
|
|
state["error"] = err
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
@ -53,19 +53,19 @@ func (s *stepSnapshot) Run(state map[string]interface{}) multistep.StepAction {
|
|
|
|
|
|
|
|
|
|
if imageId == 0 {
|
|
|
|
|
err := errors.New("Couldn't find snapshot to get the image ID. Bug?")
|
|
|
|
|
state["error"] = err
|
|
|
|
|
state.Put("error", err)
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
return multistep.ActionHalt
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.Printf("Snapshot image ID: %d", imageId)
|
|
|
|
|
|
|
|
|
|
state["snapshot_image_id"] = imageId
|
|
|
|
|
state["snapshot_name"] = c.SnapshotName
|
|
|
|
|
state.Put("snapshot_image_id", imageId)
|
|
|
|
|
state.Put("snapshot_name", c.SnapshotName)
|
|
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *stepSnapshot) Cleanup(state map[string]interface{}) {
|
|
|
|
|
func (s *stepSnapshot) Cleanup(state multistep.StateBag) {
|
|
|
|
|
// no cleanup
|
|
|
|
|
}
|
|
|
|
|
|