Skip to content

Commit

Permalink
setup visibility and image members
Browse files Browse the repository at this point in the history
  • Loading branch information
rmb938 committed Jan 16, 2018
1 parent ecd83aa commit 9f4992f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
6 changes: 3 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import:
- package: github.com/mitchellh/multistep
version: 391576a156a54cfbb4cf5d5eda40cf6ffa3e3a4d
- package: github.com/sandwichcloud/deli-cli
version: 0.0.14
version: 0.0.16
4 changes: 3 additions & 1 deletion sandwich/image_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
)

type ImageConfig struct {
ImageName string `mapstructure:"image_name"`
ImageName string `mapstructure:"image_name"`
ImagePublic bool `mapstructure:"image_public"`
ImageMembers []string `mapstructure:"image_members"`
}

func (c *ImageConfig) Prepare(ctx *interpolate.Context) []error {
Expand Down
22 changes: 21 additions & 1 deletion sandwich/step_image_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (s *StepImageInstance) Run(state multistep.StateBag) multistep.StepAction {

instanceClient := config.sandwichClient.Instance()
imageClient := config.sandwichClient.Image()
image, err := instanceClient.ActionImage(instance.ID.String(), config.ImageName, "PRIVATE")
image, err := instanceClient.ActionImage(instance.ID.String(), config.ImageName)
if err != nil {
err := fmt.Errorf("Error imaging instance: %s", err)
state.Put("error", err)
Expand All @@ -47,6 +47,26 @@ func (s *StepImageInstance) Run(state multistep.StateBag) multistep.StepAction {

state.Put("imageID", image.ID.String())

if config.ImagePublic {
err := imageClient.ActionSetVisibility(image.ID.String(), true)
if err != nil {
err := fmt.Errorf("Error making image public: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
} else {
for _, memberID := range config.ImageMembers {
err := imageClient.MemberAdd(image.ID.String(), memberID)
if err != nil {
err := fmt.Errorf("Error adding image member: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}
}

ui.Say("Image has been created.")

return multistep.ActionContinue
Expand Down

0 comments on commit 9f4992f

Please sign in to comment.