packer-cn/builder/linode/step_shutdown_linode.go
Marques Johansson 99987c2d56 Add Linode Images builder
Packer Builder for [Linode Images](https://www.linode.com/docs/platform/disk-images/linode-images/)

Adds the following builder:

  * `linode`

Based on https://github.com/linode/packer-builder-linode (MPL/2)
(formerly maintained by @dradtke).  Includes website docs and tests.

Relates to #174, #3131
2019-04-15 20:40:59 -04:00

40 lines
1.0 KiB
Go

package linode
import (
"context"
"errors"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/linode/linodego"
)
type stepShutdownLinode struct {
client linodego.Client
}
func (s *stepShutdownLinode) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
instance := state.Get("instance").(*linodego.Instance)
ui.Say("Shutting down Linode...")
if err := s.client.ShutdownInstance(ctx, instance.ID); err != nil {
err = errors.New("Error shutting down Linode: " + err.Error())
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
_, err := s.client.WaitForInstanceStatus(ctx, instance.ID, linodego.InstanceOffline, 120)
if err != nil {
err = errors.New("Error shutting down Linode: " + err.Error())
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
return multistep.ActionContinue
}
func (s *stepShutdownLinode) Cleanup(state multistep.StateBag) {}