Merge pull request #8016 from psinghal20/issue-8009

fix: move adding metadata step after waiting for uploading step
This commit is contained in:
Megan Marsh 2019-08-22 11:24:37 -07:00 committed by GitHub
commit 04d9888657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 10 deletions

View File

@ -45,9 +45,10 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
// Block Storage service volume or regular Compute service local volume. // Block Storage service volume or regular Compute service local volume.
ui.Say(fmt.Sprintf("Creating the image: %s", config.ImageName)) ui.Say(fmt.Sprintf("Creating the image: %s", config.ImageName))
var imageId string var imageId string
var blockStorageClient *gophercloud.ServiceClient
if s.UseBlockStorageVolume { if s.UseBlockStorageVolume {
// We need the v3 block storage client. // We need the v3 block storage client.
blockStorageClient, err := config.blockStorageV3Client() blockStorageClient, err = config.blockStorageV3Client()
if err != nil { if err != nil {
err = fmt.Errorf("Error initializing block storage client: %s", err) err = fmt.Errorf("Error initializing block storage client: %s", err)
state.Put("error", err) state.Put("error", err)
@ -64,15 +65,6 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
ui.Error(err.Error()) ui.Error(err.Error())
return multistep.ActionHalt return multistep.ActionHalt
} }
err = volumeactions.SetImageMetadata(blockStorageClient, volume, volumeactions.ImageMetadataOpts{
Metadata: config.ImageMetadata,
}).ExtractErr()
if err != nil {
err := fmt.Errorf("Error setting image metadata: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
imageId = image.ImageID imageId = image.ImageID
} else { } else {
imageId, err = servers.CreateImage(computeClient, server.ID, servers.CreateImageOpts{ imageId, err = servers.CreateImage(computeClient, server.ID, servers.CreateImageOpts{
@ -100,6 +92,19 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
return multistep.ActionHalt return multistep.ActionHalt
} }
volume := state.Get("volume_id").(string)
if len(config.ImageMetadata) > 0 && s.UseBlockStorageVolume {
err = volumeactions.SetImageMetadata(blockStorageClient, volume, volumeactions.ImageMetadataOpts{
Metadata: config.ImageMetadata,
}).ExtractErr()
if err != nil {
err := fmt.Errorf("Error setting image metadata: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
}
return multistep.ActionContinue return multistep.ActionContinue
} }