packer-cn/builder/hyperone/step_stop_vm.go

33 lines
793 B
Go
Raw Normal View History

2019-01-23 08:04:05 -05:00
package hyperone
import (
"context"
"fmt"
2020-12-17 16:29:25 -05:00
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
openapi "github.com/hyperonecom/h1-client-go"
2019-01-23 08:04:05 -05:00
)
type stepStopVM struct{}
func (s *stepStopVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*openapi.APIClient)
ui := state.Get("ui").(packersdk.Ui)
2019-01-23 08:04:05 -05:00
vmID := state.Get("vm_id").(string)
ui.Say("Stopping VM...")
_, _, err := client.VmApi.VmActionStop(ctx, vmID)
if err != nil {
err := fmt.Errorf("error stopping VM: %s", formatOpenAPIError(err))
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *stepStopVM) Cleanup(multistep.StateBag) {}