fix: move adding metadata step after waiting for uploading step

Signed-off-by: psinghal20 <psinghal20@gmail.com>
This commit is contained in:
psinghal20 2019-08-21 15:45:46 +05:30
parent 17d9a85895
commit bbd71136dc
No known key found for this signature in database
GPG Key ID: 913FC7FF16CA9109
1 changed files with 14 additions and 9 deletions

View File

@ -45,6 +45,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
// Block Storage service volume or regular Compute service local volume.
ui.Say(fmt.Sprintf("Creating the image: %s", config.ImageName))
var imageId string
var blockStorageClient *gophercloud.ServiceClient
if s.UseBlockStorageVolume {
// We need the v3 block storage client.
blockStorageClient, err := config.blockStorageV3Client()
@ -64,15 +65,6 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
ui.Error(err.Error())
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
} else {
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
}
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
}