Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .web-docs/components/builder/openstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ builder.

- `use_floating_ip` (bool) - *Deprecated* use `floating_ip` or `floating_ip_pool` instead.

- `image_creation_wait` (int) - Additional wait time in seconds after the image reaches `active` status (default: 0).

<!-- End of code generated from the comments of the RunConfig struct in builder/openstack/run_config.go; -->


Expand Down
2 changes: 2 additions & 0 deletions builder/openstack/builder.hcl2spec.go

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

2 changes: 2 additions & 0 deletions builder/openstack/run_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ type RunConfig struct {
OpenstackProvider string `mapstructure:"openstack_provider"`
// *Deprecated* use `floating_ip` or `floating_ip_pool` instead.
UseFloatingIp bool `mapstructure:"use_floating_ip" required:"false"`
// Additional wait time in seconds after the image reaches `active` status (default: 0).
ImageCreationWait int `mapstructure:"image_creation_wait" required:"false"`

sourceImageOpts images.ListOpts
}
Expand Down
14 changes: 12 additions & 2 deletions builder/openstack/step_create_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul

// Wait for the image to become ready
ui.Say(fmt.Sprintf("Waiting for image %s (image id: %s) to become ready...", config.ImageName, imageId))
if err := WaitForImage(ctx, imageClient, imageId); err != nil {
if err := WaitForImage(ctx, imageClient, imageId, config.ImageCreationWait); err != nil {
err := fmt.Errorf("Error waiting for image: %s", err)
state.Put("error", err)
ui.Error(err.Error())
Expand All @@ -120,7 +120,7 @@ func (s *stepCreateImage) Cleanup(multistep.StateBag) {
}

// WaitForImage waits for the given Image ID to become ready.
func WaitForImage(ctx context.Context, client *gophercloud.ServiceClient, imageId string) error {
func WaitForImage(ctx context.Context, client *gophercloud.ServiceClient, imageId string, imageCreationWait int) error {
maxNumErrors := 10
numErrors := 0

Expand All @@ -146,6 +146,16 @@ func WaitForImage(ctx context.Context, client *gophercloud.ServiceClient, imageI
}

if image.Status == "active" {
if imageCreationWait > 0 {
log.Printf("Additional wait (%d seconds) after image status has changed to active...", imageCreationWait)
select {
case <-time.After(time.Duration(imageCreationWait) * time.Second):
// Timer finished, safe to continue
case <-ctx.Done():
// User cancelled during the wait, abort immediately
return ctx.Err()
}
}
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions docs-partials/builder/openstack/RunConfig-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@

- `use_floating_ip` (bool) - *Deprecated* use `floating_ip` or `floating_ip_pool` instead.

- `image_creation_wait` (int) - Additional wait time in seconds after the image reaches `active` status (default: 0).

<!-- End of code generated from the comments of the RunConfig struct in builder/openstack/run_config.go; -->
Loading