forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep_create_image.go
42 lines (33 loc) · 1.06 KB
/
step_create_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
package hyperone
import (
"context"
"fmt"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hyperonecom/h1-client-go"
)
type stepCreateImage struct{}
func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*openapi.APIClient)
ui := state.Get("ui").(packer.Ui)
config := state.Get("config").(*Config)
vmID := state.Get("vm_id").(string)
ui.Say("Creating image...")
image, _, err := client.ImageApi.ImageCreate(ctx, openapi.ImageCreate{
Name: config.ImageName,
Vm: vmID,
Service: config.ImageService,
Description: config.ImageDescription,
Tag: config.ImageTags,
})
if err != nil {
err := fmt.Errorf("error creating image: %s", formatOpenAPIError(err))
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put("image_id", image.Id)
state.Put("image_name", image.Name)
return multistep.ActionContinue
}
func (s *stepCreateImage) Cleanup(state multistep.StateBag) {}