template step uses vSphere driver
This commit is contained in:
parent
726df3927d
commit
cadc320b72
|
@ -225,10 +225,15 @@ func (d *Driver) WaitForShutdown(vm *object.VirtualMachine, timeout time.Duratio
|
|||
}
|
||||
|
||||
func (d *Driver) CreateSnapshot(vm *object.VirtualMachine) error {
|
||||
task, err := vm.CreateSnapshot(d.ctx, "Created by Packer", "", false,false)
|
||||
task, err := vm.CreateSnapshot(d.ctx, "Created by Packer", "", false, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = task.WaitForResult(d.ctx, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
func (d *Driver) ConvertToTemplate(vm *object.VirtualMachine) error {
|
||||
err := vm.MarkAsTemplate(d.ctx)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -12,18 +12,16 @@ type StepConvertToTemplate struct{
|
|||
|
||||
func (s *StepConvertToTemplate) Run(state multistep.StateBag) multistep.StepAction {
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vm := state.Get("vm").(*object.VirtualMachine)
|
||||
d := state.Get("driver").(Driver)
|
||||
vm := state.Get("vm").(*object.VirtualMachine)
|
||||
|
||||
// Turning into template if needed
|
||||
if s.ConvertToTemplate {
|
||||
ui.Say("turning into template...")
|
||||
err := vm.MarkAsTemplate(d.ctx)
|
||||
ui.Say("Convert VM into template...")
|
||||
err := d.ConvertToTemplate(vm)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
ui.Say("done")
|
||||
}
|
||||
|
||||
return multistep.ActionContinue
|
||||
|
|
Loading…
Reference in New Issue