forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_add_image_members.go
44 lines (35 loc) · 1.11 KB
/
step_add_image_members.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
package openstack
import (
"fmt"
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/members"
"github.com/hashicorp/packer/packer"
"github.com/mitchellh/multistep"
)
type stepAddImageMembers struct{}
func (s *stepAddImageMembers) Run(state multistep.StateBag) multistep.StepAction {
imageId := state.Get("image").(string)
ui := state.Get("ui").(packer.Ui)
config := state.Get("config").(Config)
if len(config.ImageMembers) == 0 {
return multistep.ActionContinue
}
imageClient, err := config.imageV2Client()
if err != nil {
err = fmt.Errorf("Error initializing image service client: %s", err)
state.Put("error", err)
return multistep.ActionHalt
}
for _, member := range config.ImageMembers {
ui.Say(fmt.Sprintf("Adding member '%s' to image %s", member, imageId))
r := members.Create(imageClient, imageId, member)
if _, err = r.Extract(); err != nil {
err = fmt.Errorf("Error adding member to image: %s", err)
state.Put("error", err)
return multistep.ActionHalt
}
}
return multistep.ActionContinue
}
func (s *stepAddImageMembers) Cleanup(multistep.StateBag) {
// No cleanup...
}