packer-cn/builder/vsphere/common/step_template.go

32 lines
718 B
Go
Raw Normal View History

package common
import (
2018-10-31 17:42:24 -04:00
"context"
"github.com/hashicorp/packer/builder/vsphere/driver"
2018-04-25 07:22:38 -04:00
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)
2018-10-31 17:42:24 -04:00
type StepConvertToTemplate struct {
2017-06-27 03:32:59 -04:00
ConvertToTemplate bool
}
2018-04-25 07:22:38 -04:00
func (s *StepConvertToTemplate) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
2017-08-23 20:06:50 -04:00
vm := state.Get("vm").(*driver.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...")
2017-08-23 20:06:50 -04:00
err := vm.ConvertToTemplate()
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) {}