2019-01-23 08:04:05 -05:00
|
|
|
package hyperone
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2019-03-22 09:53:28 -04:00
|
|
|
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").(packer.Ui)
|
|
|
|
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) {}
|