2018-01-24 06:04:39 -05:00
|
|
|
package common
|
2017-06-13 07:11:41 -04:00
|
|
|
|
|
|
|
import (
|
2018-10-31 17:42:24 -04:00
|
|
|
"context"
|
2020-01-07 19:59:31 -05:00
|
|
|
"github.com/hashicorp/packer/builder/vsphere/driver"
|
2018-04-25 07:22:38 -04:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-06-13 07:11:41 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
)
|
|
|
|
|
2018-10-31 17:42:24 -04:00
|
|
|
type StepCreateSnapshot struct {
|
2018-01-24 06:04:39 -05:00
|
|
|
CreateSnapshot bool
|
2017-06-13 07:11:41 -04:00
|
|
|
}
|
|
|
|
|
2018-04-25 07:22:38 -04:00
|
|
|
func (s *StepCreateSnapshot) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2017-06-13 07:11:41 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2017-08-23 20:06:50 -04:00
|
|
|
vm := state.Get("vm").(*driver.VirtualMachine)
|
2017-06-13 07:11:41 -04:00
|
|
|
|
2018-01-24 06:04:39 -05:00
|
|
|
if s.CreateSnapshot {
|
2017-07-02 10:53:29 -04:00
|
|
|
ui.Say("Creating snapshot...")
|
2017-06-27 03:32:59 -04:00
|
|
|
|
2017-08-23 20:06:50 -04:00
|
|
|
err := vm.CreateSnapshot("Created by Packer")
|
2017-06-13 07:11:41 -04:00
|
|
|
if err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2017-06-27 03:32:59 -04:00
|
|
|
func (s *StepCreateSnapshot) Cleanup(state multistep.StateBag) {}
|