2016-12-13 19:28:54 -05:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2016-12-13 19:28:54 -05:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
imageservice "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2016-12-13 19:28:54 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepUpdateImageVisibility struct{}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *stepUpdateImageVisibility) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2016-12-13 19:28:54 -05:00
|
|
|
imageId := state.Get("image").(string)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2018-09-18 10:05:49 -04:00
|
|
|
config := state.Get("config").(*Config)
|
2016-12-13 19:28:54 -05:00
|
|
|
|
2016-12-13 19:32:15 -05:00
|
|
|
if config.ImageVisibility == "" {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Updating image visibility to %s", config.ImageVisibility))
|
|
|
|
r := imageservice.Update(
|
|
|
|
imageClient,
|
|
|
|
imageId,
|
|
|
|
imageservice.UpdateOpts{
|
|
|
|
imageservice.UpdateVisibility{
|
|
|
|
Visibility: config.ImageVisibility,
|
2016-12-13 19:28:54 -05:00
|
|
|
},
|
2016-12-13 19:32:15 -05:00
|
|
|
},
|
|
|
|
)
|
2016-12-13 19:28:54 -05:00
|
|
|
|
2016-12-13 19:32:15 -05:00
|
|
|
if _, err = r.Extract(); err != nil {
|
|
|
|
err = fmt.Errorf("Error updating image visibility: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
2016-12-13 19:28:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepUpdateImageVisibility) Cleanup(multistep.StateBag) {
|
|
|
|
// No cleanup...
|
|
|
|
}
|