Merge pull request #8186 from puetzk/issue8178

fix: set openstack metadata for use_blockstorage_volume
This commit is contained in:
Megan Marsh 2019-10-23 12:53:30 -07:00 committed by GitHub
commit 1731f87ad0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 15 deletions

View File

@ -55,6 +55,20 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
return multistep.ActionHalt
}
volume := state.Get("volume_id").(string)
// set ImageMetadata before uploading to glance so the new image captured the desired values
if len(config.ImageMetadata) > 0 {
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
}
}
image, err := volumeactions.UploadImage(blockStorageClient, volume, volumeactions.UploadImageOpts{
DiskFormat: config.ImageDiskFormat,
ImageName: config.ImageName,
@ -92,21 +106,6 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
return multistep.ActionHalt
}
if s.UseBlockStorageVolume {
volume := state.Get("volume_id").(string)
if len(config.ImageMetadata) > 0 {
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
}

View File

@ -63,6 +63,7 @@ func (s *StepCreateVolume) Run(ctx context.Context, state multistep.StateBag) mu
AvailabilityZone: s.VolumeAvailabilityZone,
Name: s.VolumeName,
ImageID: sourceImage,
Metadata: config.ImageMetadata,
}
volume, err := volumes.Create(blockStorageClient, volumeOpts).Extract()
if err != nil {