33 lines
747 B
Go
33 lines
747 B
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
|
"github.com/hashicorp/packer/builder/vsphere/driver"
|
|
)
|
|
|
|
type StepCreateSnapshot struct {
|
|
CreateSnapshot bool
|
|
}
|
|
|
|
func (s *StepCreateSnapshot) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
|
ui := state.Get("ui").(packersdk.Ui)
|
|
vm := state.Get("vm").(*driver.VirtualMachineDriver)
|
|
|
|
if s.CreateSnapshot {
|
|
ui.Say("Creating snapshot...")
|
|
|
|
err := vm.CreateSnapshot("Created by Packer")
|
|
if err != nil {
|
|
state.Put("error", err)
|
|
return multistep.ActionHalt
|
|
}
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (s *StepCreateSnapshot) Cleanup(state multistep.StateBag) {}
|