2019-02-07 00:54:12 -05:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2019-02-07 00:54:12 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type stepUpdateImageMinDisk struct{}
|
|
|
|
|
|
|
|
func (s *stepUpdateImageMinDisk) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2019-02-07 00:54:12 -05:00
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
|
2021-01-19 04:43:18 -05:00
|
|
|
if config.SkipCreateImage {
|
|
|
|
ui.Say("Skipping image update mindisk...")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
imageId := state.Get("image").(string)
|
|
|
|
|
2019-02-07 00:54:12 -05:00
|
|
|
if config.ImageMinDisk == 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
|
|
|
|
}
|
|
|
|
|
2019-07-22 14:54:42 -04:00
|
|
|
ui.Say(fmt.Sprintf("Updating image min disk to %d", config.ImageMinDisk))
|
2019-02-07 00:54:12 -05:00
|
|
|
|
|
|
|
r := images.Update(
|
|
|
|
imageClient,
|
|
|
|
imageId,
|
|
|
|
images.UpdateOpts{
|
|
|
|
images.ReplaceImageMinDisk{
|
|
|
|
NewMinDisk: config.ImageMinDisk,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
if _, err := r.Extract(); err != nil {
|
|
|
|
err = fmt.Errorf("Error updating image min disk: %s", err)
|
|
|
|
state.Put("error", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepUpdateImageMinDisk) Cleanup(multistep.StateBag) {
|
|
|
|
// No cleanup...
|
|
|
|
}
|