fix: set openstack metadata for use_blockstorage_volume

Also set os-set_image_metadata on the tempoary volume before uploading
(volume metadata does not automatically become image metadata)
so the uploaded image will be created with the desired metadata
This commit is contained in:
Kevin Puetz 2019-10-02 17:59:13 -05:00
parent 17d4e54947
commit 6e069c94e8
2 changed files with 15 additions and 13 deletions

View File

@ -55,6 +55,20 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
return multistep.ActionHalt return multistep.ActionHalt
} }
volume := state.Get("volume_id").(string) 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{ image, err := volumeactions.UploadImage(blockStorageClient, volume, volumeactions.UploadImageOpts{
DiskFormat: config.ImageDiskFormat, DiskFormat: config.ImageDiskFormat,
ImageName: config.ImageName, ImageName: config.ImageName,
@ -92,19 +106,6 @@ 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
} }

View File

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