2013-06-13 13:56:34 -04:00
|
|
|
package digitalocean
|
|
|
|
|
|
|
|
import (
|
2013-06-17 08:21:15 -04:00
|
|
|
"fmt"
|
2013-06-13 13:56:34 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2013-06-17 08:21:15 -04:00
|
|
|
ui.Say(fmt.Sprintf("Creating snapshot: %v", c.SnapshotName))
|
2013-06-13 13:56:34 -04:00
|
|
|
|
|
|
|
err := client.CreateSnapshot(dropletId, c.SnapshotName)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say("Waiting for snapshot to complete...")
|
|
|
|
|
|
|
|
err = waitForDropletState("active", dropletId, client)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepSnapshot) Cleanup(state map[string]interface{}) {
|
|
|
|
// no cleanup
|
|
|
|
}
|