packer-cn/builder/triton/step_create_image_from_mach...

46 lines
1.3 KiB
Go
Raw Normal View History

package triton
import (
"fmt"
"time"
2017-04-04 16:39:01 -04:00
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
)
// StepCreateImageFromMachine creates an image with the specified attributes
// from the machine with the given ID, and waits for the image to be created.
// The machine must be in the "stopped" state prior to this step being run.
type StepCreateImageFromMachine struct{}
func (s *StepCreateImageFromMachine) Run(state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(Config)
driver := state.Get("driver").(Driver)
ui := state.Get("ui").(packer.Ui)
machineId := state.Get("machine").(string)
ui.Say("Creating image from source machine...")
imageId, err := driver.CreateImageFromMachine(machineId, config)
if err != nil {
state.Put("error", fmt.Errorf("Problem creating image from machine: %s", err))
return multistep.ActionHalt
}
ui.Say("Waiting for image to become available...")
err = driver.WaitForImageCreation(imageId, 10*time.Minute)
if err != nil {
state.Put("error", fmt.Errorf("Problem waiting for image to become available: %s", err))
return multistep.ActionHalt
}
state.Put("image", imageId)
return multistep.ActionContinue
}
func (s *StepCreateImageFromMachine) Cleanup(state multistep.StateBag) {
// No cleanup
}