2018-01-24 06:04:39 -05:00
|
|
|
package common
|
2017-06-13 07:11:41 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
2017-08-23 15:40:57 -04:00
|
|
|
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
|
2017-06-13 07:11:41 -04:00
|
|
|
)
|
|
|
|
|
2017-06-27 03:32:59 -04:00
|
|
|
type StepConvertToTemplate struct{
|
|
|
|
ConvertToTemplate bool
|
2017-06-13 07:11:41 -04:00
|
|
|
}
|
|
|
|
|
2017-06-27 03:32:59 -04:00
|
|
|
func (s *StepConvertToTemplate) Run(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
|
|
|
|
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) {}
|