forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_image.go
48 lines (37 loc) · 1.08 KB
/
step_image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package oci
import (
"fmt"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
)
type stepImage struct{}
func (s *stepImage) Run(state multistep.StateBag) multistep.StepAction {
var (
driver = state.Get("driver").(Driver)
ui = state.Get("ui").(packer.Ui)
instanceID = state.Get("instance_id").(string)
)
ui.Say("Creating image from instance...")
image, err := driver.CreateImage(instanceID)
if err != nil {
err = fmt.Errorf("Error creating image from instance: %s", err)
ui.Error(err.Error())
state.Put("error", err)
return multistep.ActionHalt
}
err = driver.WaitForImageCreation(image.ID)
if err != nil {
err = fmt.Errorf("Error waiting for image creation to finish: %s", err)
ui.Error(err.Error())
state.Put("error", err)
return multistep.ActionHalt
}
// TODO(apryde): This is stale as .LifecycleState has changed to
// AVAILABLE at this point. Does it matter?
state.Put("image", image)
ui.Say("Image created.")
return multistep.ActionContinue
}
func (s *stepImage) Cleanup(state multistep.StateBag) {
// Nothing to do
}