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:
commit
091963fe31
|
@ -96,15 +96,12 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
},
|
||||
&StepCreateVolume{
|
||||
UseBlockStorageVolume: b.config.UseBlockStorageVolume,
|
||||
SourceImage: b.config.SourceImage,
|
||||
VolumeName: b.config.VolumeName,
|
||||
VolumeType: b.config.VolumeType,
|
||||
VolumeAvailabilityZone: b.config.VolumeAvailabilityZone,
|
||||
},
|
||||
&StepRunSourceServer{
|
||||
Name: b.config.InstanceName,
|
||||
SourceImage: b.config.SourceImage,
|
||||
SourceImageName: b.config.SourceImageName,
|
||||
SecurityGroups: b.config.SecurityGroups,
|
||||
Networks: b.config.Networks,
|
||||
Ports: b.config.Ports,
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
|
||||
type StepCreateVolume struct {
|
||||
UseBlockStorageVolume bool
|
||||
SourceImage string
|
||||
VolumeName string
|
||||
VolumeType string
|
||||
VolumeAvailabilityZone string
|
||||
|
@ -27,6 +26,7 @@ func (s *StepCreateVolume) Run(_ context.Context, state multistep.StateBag) mult
|
|||
|
||||
config := state.Get("config").(Config)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
sourceImage := state.Get("source_image").(string)
|
||||
|
||||
// We will need Block Storage and Image services clients.
|
||||
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.
|
||||
volumeSize, err := GetVolumeSize(imageClient, s.SourceImage)
|
||||
volumeSize, err := GetVolumeSize(imageClient, sourceImage)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error creating volume: %s", err)
|
||||
state.Put("error", err)
|
||||
|
@ -57,7 +57,7 @@ func (s *StepCreateVolume) Run(_ context.Context, state multistep.StateBag) mult
|
|||
VolumeType: s.VolumeType,
|
||||
AvailabilityZone: s.VolumeAvailabilityZone,
|
||||
Name: s.VolumeName,
|
||||
ImageID: s.SourceImage,
|
||||
ImageID: sourceImage,
|
||||
}
|
||||
volume, err := volumes.Create(blockStorageClient, volumeOpts).Extract()
|
||||
if err != nil {
|
||||
|
|
|
@ -16,8 +16,6 @@ import (
|
|||
|
||||
type StepRunSourceServer struct {
|
||||
Name string
|
||||
SourceImage string
|
||||
SourceImageName string
|
||||
SecurityGroups []string
|
||||
Networks []string
|
||||
Ports []string
|
||||
|
@ -34,6 +32,7 @@ type StepRunSourceServer struct {
|
|||
func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||
config := state.Get("config").(Config)
|
||||
flavor := state.Get("flavor_id").(string)
|
||||
sourceImage := state.Get("source_image").(string)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
// We need the v2 compute client
|
||||
|
@ -67,8 +66,7 @@ func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) m
|
|||
|
||||
serverOpts := servers.CreateOpts{
|
||||
Name: s.Name,
|
||||
ImageRef: s.SourceImage,
|
||||
ImageName: s.SourceImageName,
|
||||
ImageRef: sourceImage,
|
||||
FlavorRef: flavor,
|
||||
SecurityGroups: s.SecurityGroups,
|
||||
Networks: networks,
|
||||
|
@ -79,11 +77,6 @@ func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) m
|
|||
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
|
||||
|
||||
// Create root volume in the Block Storage service if required.
|
||||
|
|
|
@ -22,12 +22,20 @@ func (s *StepSourceImageInfo) Run(_ context.Context, state multistep.StateBag) m
|
|||
config := state.Get("config").(Config)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
|
||||
if s.SourceImage != "" || s.SourceImageName != "" {
|
||||
if s.SourceImage != "" {
|
||||
state.Put("source_image", s.SourceImage)
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
client, err := config.imageV2Client()
|
||||
|
||||
if s.SourceImageName != "" {
|
||||
s.SourceImageOpts = images.ListOpts{
|
||||
Name: s.SourceImageName,
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("Using Image Filters %v", s.SourceImageOpts)
|
||||
image := &images.Image{}
|
||||
err = images.List(client, s.SourceImageOpts).EachPage(func(page pagination.Page) (bool, error) {
|
||||
|
|
Loading…
Reference in New Issue