packer-cn/step_create_snapshot.go

34 lines
740 B
Go
Raw Normal View History

package main
import (
"github.com/mitchellh/multistep"
"github.com/hashicorp/packer/packer"
"context"
2017-06-27 03:32:59 -04:00
"github.com/vmware/govmomi/object"
)
2017-06-27 03:32:59 -04:00
type StepCreateSnapshot struct{
createSnapshot bool
}
2017-06-27 03:32:59 -04:00
func (s *StepCreateSnapshot) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
vm := state.Get("vm").(*object.VirtualMachine)
ctx := state.Get("ctx").(context.Context)
2017-06-27 03:32:59 -04:00
if s.createSnapshot {
ui.Say("creating snapshot...")
_, err := vm.CreateSnapshot(ctx, "packer_snapshot", "", true, true)
if err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
ui.Say("done")
}
return multistep.ActionContinue
}
2017-06-27 03:32:59 -04:00
func (s *StepCreateSnapshot) Cleanup(state multistep.StateBag) {}