packer-plugin-xenserver/builder/xenserver/common/step_set_vm_to_template.go

35 lines
921 B
Go

package common
import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
type StepSetVmToTemplate struct{}
func (StepSetVmToTemplate) Run(state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
c := state.Get("client").(*Connection)
instance_uuid := state.Get("instance_uuid").(string)
instance, err := c.client.VM.GetByUUID(c.session, instance_uuid)
if err != nil {
ui.Error(fmt.Sprintf("Could not get VM with UUID '%s': %s", instance_uuid, err.Error()))
return multistep.ActionHalt
}
err = c.client.VM.SetIsATemplate(c.session, instance, true)
if err != nil {
ui.Error(fmt.Sprintf("failed to set VM '%s' as a template with error: %v", instance_uuid, err))
return multistep.ActionHalt
}
ui.Message("Successfully set VM as a template")
return multistep.ActionContinue
}
func (StepSetVmToTemplate) Cleanup(state multistep.StateBag) {}