Merge pull request #6751 from rickard-von-essen/os-source-id-fix

WIP: openstack: use source_image_name to find UUID
This commit is contained in:
Adrien Delorme 2018-09-26 12:57:24 +02:00 committed by GitHub
commit 091963fe31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 16 deletions

View File

@ -96,15 +96,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}, },
&StepCreateVolume{ &StepCreateVolume{
UseBlockStorageVolume: b.config.UseBlockStorageVolume, UseBlockStorageVolume: b.config.UseBlockStorageVolume,
SourceImage: b.config.SourceImage,
VolumeName: b.config.VolumeName, VolumeName: b.config.VolumeName,
VolumeType: b.config.VolumeType, VolumeType: b.config.VolumeType,
VolumeAvailabilityZone: b.config.VolumeAvailabilityZone, VolumeAvailabilityZone: b.config.VolumeAvailabilityZone,
}, },
&StepRunSourceServer{ &StepRunSourceServer{
Name: b.config.InstanceName, Name: b.config.InstanceName,
SourceImage: b.config.SourceImage,
SourceImageName: b.config.SourceImageName,
SecurityGroups: b.config.SecurityGroups, SecurityGroups: b.config.SecurityGroups,
Networks: b.config.Networks, Networks: b.config.Networks,
Ports: b.config.Ports, Ports: b.config.Ports,

View File

@ -11,7 +11,6 @@ import (
type StepCreateVolume struct { type StepCreateVolume struct {
UseBlockStorageVolume bool UseBlockStorageVolume bool
SourceImage string
VolumeName string VolumeName string
VolumeType string VolumeType string
VolumeAvailabilityZone string VolumeAvailabilityZone string
@ -27,6 +26,7 @@ func (s *StepCreateVolume) Run(_ context.Context, state multistep.StateBag) mult
config := state.Get("config").(Config) config := state.Get("config").(Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
sourceImage := state.Get("source_image").(string)
// We will need Block Storage and Image services clients. // We will need Block Storage and Image services clients.
blockStorageClient, err := config.blockStorageV3Client() blockStorageClient, err := config.blockStorageV3Client()
@ -43,7 +43,7 @@ func (s *StepCreateVolume) Run(_ context.Context, state multistep.StateBag) mult
} }
// Get needed volume size from the source image. // Get needed volume size from the source image.
volumeSize, err := GetVolumeSize(imageClient, s.SourceImage) volumeSize, err := GetVolumeSize(imageClient, sourceImage)
if err != nil { if err != nil {
err := fmt.Errorf("Error creating volume: %s", err) err := fmt.Errorf("Error creating volume: %s", err)
state.Put("error", err) state.Put("error", err)
@ -57,7 +57,7 @@ func (s *StepCreateVolume) Run(_ context.Context, state multistep.StateBag) mult
VolumeType: s.VolumeType, VolumeType: s.VolumeType,
AvailabilityZone: s.VolumeAvailabilityZone, AvailabilityZone: s.VolumeAvailabilityZone,
Name: s.VolumeName, Name: s.VolumeName,
ImageID: s.SourceImage, ImageID: sourceImage,
} }
volume, err := volumes.Create(blockStorageClient, volumeOpts).Extract() volume, err := volumes.Create(blockStorageClient, volumeOpts).Extract()
if err != nil { if err != nil {

View File

@ -16,8 +16,6 @@ import (
type StepRunSourceServer struct { type StepRunSourceServer struct {
Name string Name string
SourceImage string
SourceImageName string
SecurityGroups []string SecurityGroups []string
Networks []string Networks []string
Ports []string Ports []string
@ -34,6 +32,7 @@ type StepRunSourceServer struct {
func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
config := state.Get("config").(Config) config := state.Get("config").(Config)
flavor := state.Get("flavor_id").(string) flavor := state.Get("flavor_id").(string)
sourceImage := state.Get("source_image").(string)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
// We need the v2 compute client // We need the v2 compute client
@ -67,8 +66,7 @@ func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) m
serverOpts := servers.CreateOpts{ serverOpts := servers.CreateOpts{
Name: s.Name, Name: s.Name,
ImageRef: s.SourceImage, ImageRef: sourceImage,
ImageName: s.SourceImageName,
FlavorRef: flavor, FlavorRef: flavor,
SecurityGroups: s.SecurityGroups, SecurityGroups: s.SecurityGroups,
Networks: networks, Networks: networks,
@ -79,11 +77,6 @@ func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) m
Metadata: s.InstanceMetadata, Metadata: s.InstanceMetadata,
} }
// check if image filter returned a source image ID and replace
if imageID, ok := state.GetOk("source_image"); ok {
serverOpts.ImageRef = imageID.(string)
}
var serverOptsExt servers.CreateOptsBuilder var serverOptsExt servers.CreateOptsBuilder
// Create root volume in the Block Storage service if required. // Create root volume in the Block Storage service if required.

View File

@ -22,12 +22,20 @@ func (s *StepSourceImageInfo) Run(_ context.Context, state multistep.StateBag) m
config := state.Get("config").(Config) config := state.Get("config").(Config)
ui := state.Get("ui").(packer.Ui) ui := state.Get("ui").(packer.Ui)
if s.SourceImage != "" || s.SourceImageName != "" { if s.SourceImage != "" {
state.Put("source_image", s.SourceImage)
return multistep.ActionContinue return multistep.ActionContinue
} }
client, err := config.imageV2Client() client, err := config.imageV2Client()
if s.SourceImageName != "" {
s.SourceImageOpts = images.ListOpts{
Name: s.SourceImageName,
}
}
log.Printf("Using Image Filters %v", s.SourceImageOpts) log.Printf("Using Image Filters %v", s.SourceImageOpts)
image := &images.Image{} image := &images.Image{}
err = images.List(client, s.SourceImageOpts).EachPage(func(page pagination.Page) (bool, error) { err = images.List(client, s.SourceImageOpts).EachPage(func(page pagination.Page) (bool, error) {