packer-cn/step_snapshot.go

32 lines
665 B
Go
Raw Normal View History

package main
import (
"github.com/mitchellh/multistep"
"github.com/hashicorp/packer/packer"
2017-06-27 10:32:59 +03:00
"github.com/vmware/govmomi/object"
)
2017-06-27 10:32:59 +03:00
type StepCreateSnapshot struct{
createSnapshot bool
}
2017-06-27 10:32:59 +03:00
func (s *StepCreateSnapshot) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
2017-07-02 23:29:50 +03:00
d := state.Get("driver").(*Driver)
2017-07-02 17:53:29 +03:00
vm := state.Get("vm").(*object.VirtualMachine)
2017-06-27 10:32:59 +03:00
if s.createSnapshot {
2017-07-02 17:53:29 +03:00
ui.Say("Creating snapshot...")
2017-06-27 10:32:59 +03:00
2017-07-02 17:53:29 +03:00
err := d.CreateSnapshot(vm)
if err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
2017-06-27 10:32:59 +03:00
func (s *StepCreateSnapshot) Cleanup(state multistep.StateBag) {}