2017-06-13 07:11:41 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/vmware/govmomi/object"
|
|
|
|
)
|
|
|
|
|
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)
|
|
|
|
vm := state.Get("vm").(*object.VirtualMachine)
|
2017-07-01 23:46:38 -04:00
|
|
|
d := state.Get("driver").(Driver)
|
2017-06-13 07:11:41 -04:00
|
|
|
|
|
|
|
// Turning into template if needed
|
2017-06-27 03:32:59 -04:00
|
|
|
if s.ConvertToTemplate {
|
2017-06-13 07:11:41 -04:00
|
|
|
ui.Say("turning into template...")
|
2017-07-01 23:46:38 -04:00
|
|
|
err := vm.MarkAsTemplate(d.ctx)
|
2017-06-13 07:11:41 -04:00
|
|
|
if err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
ui.Say("done")
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2017-06-27 03:32:59 -04:00
|
|
|
func (s *StepConvertToTemplate) Cleanup(state multistep.StateBag) {}
|