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-02-14 11:42:29 -05:00
|
|
|
|
2020-01-07 19:59:31 -05:00
|
|
|
"github.com/hashicorp/packer/builder/vsphere/driver"
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2017-06-13 07:11:41 -04:00
|
|
|
)
|
|
|
|
|
2018-10-31 17:42:24 -04:00
|
|
|
type StepConvertToTemplate struct {
|
2017-06-27 03:32:59 -04:00
|
|
|
ConvertToTemplate bool
|
2017-06-13 07:11:41 -04:00
|
|
|
}
|
|
|
|
|
2018-04-25 07:22:38 -04:00
|
|
|
func (s *StepConvertToTemplate) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2020-08-31 04:34:41 -04:00
|
|
|
vm := state.Get("vm").(*driver.VirtualMachineDriver)
|
2017-06-13 07:11:41 -04:00
|
|
|
|
2017-06-27 03:32:59 -04:00
|
|
|
if s.ConvertToTemplate {
|
2017-07-02 11:00:43 -04:00
|
|
|
ui.Say("Convert VM into template...")
|
2017-08-23 20:06:50 -04:00
|
|
|
err := vm.ConvertToTemplate()
|
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 *StepConvertToTemplate) Cleanup(state multistep.StateBag) {}
|