packer-cn/step_template.go

31 lines
689 B
Go
Raw Normal View History

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-27 03:32:59 -04:00
func (s *StepConvertToTemplate) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
2017-07-02 16:29:50 -04:00
d := state.Get("driver").(*Driver)
2017-07-02 11:00:43 -04:00
vm := state.Get("vm").(*object.VirtualMachine)
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...")
err := d.ConvertToTemplate(vm)
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) {}