packer-cn/builder/linode/step_create_image.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

49 lines
1.1 KiB
Go

package linode
import (
"context"
"errors"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/linode/linodego"
)
type stepCreateImage struct {
client linodego.Client
}
func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
c := state.Get("config").(*Config)
ui := state.Get("ui").(packer.Ui)
disk := state.Get("disk").(*linodego.InstanceDisk)
instance := state.Get("instance").(*linodego.Instance)
ui.Say("Creating image...")
image, err := s.client.CreateImage(ctx, linodego.ImageCreateOptions{
DiskID: disk.ID,
Label: c.ImageLabel,
Description: c.Description,
})
if err == nil {
_, err = s.client.WaitForInstanceDiskStatus(ctx, instance.ID, disk.ID, linodego.DiskReady, 600)
}
if err == nil {
image, err = s.client.GetImage(ctx, image.ID)
}
if err != nil {
err = errors.New("Error creating image: " + err.Error())
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put("image", image)
return multistep.ActionContinue
}
func (s *stepCreateImage) Cleanup(state multistep.StateBag) {}