packer-cn/step_template.go

31 lines
688 B
Go

package main
import (
"github.com/mitchellh/multistep"
"github.com/hashicorp/packer/packer"
"github.com/vmware/govmomi/object"
)
type StepConvertToTemplate struct{
ConvertToTemplate bool
}
func (s *StepConvertToTemplate) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
d := state.Get("driver").(Driver)
vm := state.Get("vm").(*object.VirtualMachine)
if s.ConvertToTemplate {
ui.Say("Convert VM into template...")
err := d.ConvertToTemplate(vm)
if err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
func (s *StepConvertToTemplate) Cleanup(state multistep.StateBag) {}