Merge pull request #6739 from hashicorp/pointer_configs
Use config from state-bag as a pointer
This commit is contained in:
commit
c118ac8e30
|
@ -112,7 +112,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
|
|
||||||
// Setup the state bag and initial state for the steps
|
// Setup the state bag and initial state for the steps
|
||||||
state := new(multistep.BasicStateBag)
|
state := new(multistep.BasicStateBag)
|
||||||
state.Put("config", b.config)
|
state.Put("config", &b.config)
|
||||||
state.Put("ec2", ec2conn)
|
state.Put("ec2", ec2conn)
|
||||||
state.Put("awsSession", session)
|
state.Put("awsSession", session)
|
||||||
state.Put("hook", hook)
|
state.Put("hook", hook)
|
||||||
|
|
|
@ -17,7 +17,7 @@ type stepCreateAMI struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepCreateAMI) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *stepCreateAMI) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
ec2conn := state.Get("ec2").(*ec2.EC2)
|
ec2conn := state.Get("ec2").(*ec2.EC2)
|
||||||
instance := state.Get("instance").(*ec2.Instance)
|
instance := state.Get("instance").(*ec2.Instance)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
|
@ -111,7 +111,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
|
|
||||||
// Setup the state bag and initial state for the steps
|
// Setup the state bag and initial state for the steps
|
||||||
state := new(multistep.BasicStateBag)
|
state := new(multistep.BasicStateBag)
|
||||||
state.Put("config", b.config)
|
state.Put("config", &b.config)
|
||||||
state.Put("ec2", ec2conn)
|
state.Put("ec2", ec2conn)
|
||||||
state.Put("hook", hook)
|
state.Put("hook", hook)
|
||||||
state.Put("ui", ui)
|
state.Put("ui", ui)
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
|
|
||||||
// Setup the state bag and initial state for the steps
|
// Setup the state bag and initial state for the steps
|
||||||
state := new(multistep.BasicStateBag)
|
state := new(multistep.BasicStateBag)
|
||||||
state.Put("config", b.config)
|
state.Put("config", &b.config)
|
||||||
state.Put("hook", hook)
|
state.Put("hook", hook)
|
||||||
state.Put("ui", ui)
|
state.Put("ui", ui)
|
||||||
|
|
||||||
|
@ -110,7 +110,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
ConfigDrive: b.config.ConfigDrive,
|
ConfigDrive: b.config.ConfigDrive,
|
||||||
InstanceMetadata: b.config.InstanceMetadata,
|
InstanceMetadata: b.config.InstanceMetadata,
|
||||||
UseBlockStorageVolume: b.config.UseBlockStorageVolume,
|
UseBlockStorageVolume: b.config.UseBlockStorageVolume,
|
||||||
Comm: &b.config.Comm,
|
|
||||||
},
|
},
|
||||||
&StepGetPassword{
|
&StepGetPassword{
|
||||||
Debug: b.config.PackerDebug,
|
Debug: b.config.PackerDebug,
|
||||||
|
|
|
@ -14,7 +14,7 @@ type stepAddImageMembers struct{}
|
||||||
func (s *stepAddImageMembers) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *stepAddImageMembers) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
imageId := state.Get("image").(string)
|
imageId := state.Get("image").(string)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
|
|
||||||
if len(config.ImageMembers) == 0 {
|
if len(config.ImageMembers) == 0 {
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
|
|
|
@ -18,7 +18,7 @@ type StepAllocateIp struct {
|
||||||
|
|
||||||
func (s *StepAllocateIp) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepAllocateIp) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
server := state.Get("server").(*servers.Server)
|
server := state.Get("server").(*servers.Server)
|
||||||
|
|
||||||
// We need the v2 compute client
|
// We need the v2 compute client
|
||||||
|
@ -138,7 +138,7 @@ func (s *StepAllocateIp) Run(_ context.Context, state multistep.StateBag) multis
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepAllocateIp) Cleanup(state multistep.StateBag) {
|
func (s *StepAllocateIp) Cleanup(state multistep.StateBag) {
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
instanceIP := state.Get("access_ip").(*floatingips.FloatingIP)
|
instanceIP := state.Get("access_ip").(*floatingips.FloatingIP)
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ type stepCreateImage struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *stepCreateImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
server := state.Get("server").(*servers.Server)
|
server := state.Get("server").(*servers.Server)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ func (s *StepCreateVolume) Run(_ context.Context, state multistep.StateBag) mult
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
sourceImage := state.Get("source_image").(string)
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ func (s *StepCreateVolume) Cleanup(state multistep.StateBag) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
blockStorageClient, err := config.blockStorageV3Client()
|
blockStorageClient, err := config.blockStorageV3Client()
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (s *StepDetachVolume) Run(_ context.Context, state multistep.StateBag) mult
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
blockStorageClient, err := config.blockStorageV3Client()
|
blockStorageClient, err := config.blockStorageV3Client()
|
||||||
|
|
|
@ -22,7 +22,7 @@ type StepGetPassword struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepGetPassword) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepGetPassword) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
// Skip if we're not using winrm
|
// Skip if we're not using winrm
|
||||||
|
|
|
@ -57,7 +57,7 @@ func (s *StepKeyPair) Run(_ context.Context, state multistep.StateBag) multistep
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
|
|
||||||
// We need the v2 compute client
|
// We need the v2 compute client
|
||||||
computeClient, err := config.computeV2Client()
|
computeClient, err := config.computeV2Client()
|
||||||
|
@ -169,7 +169,7 @@ func (s *StepKeyPair) Cleanup(state multistep.StateBag) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
// We need the v2 compute client
|
// We need the v2 compute client
|
||||||
|
|
|
@ -18,7 +18,7 @@ type StepLoadFlavor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepLoadFlavor) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepLoadFlavor) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
// We need the v2 compute client
|
// We need the v2 compute client
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
|
||||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
|
||||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
||||||
"github.com/hashicorp/packer/helper/communicator"
|
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
)
|
)
|
||||||
|
@ -26,11 +25,10 @@ type StepRunSourceServer struct {
|
||||||
InstanceMetadata map[string]string
|
InstanceMetadata map[string]string
|
||||||
UseBlockStorageVolume bool
|
UseBlockStorageVolume bool
|
||||||
server *servers.Server
|
server *servers.Server
|
||||||
Comm *communicator.Config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
sourceImage := state.Get("source_image").(string)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
@ -102,7 +100,7 @@ func (s *StepRunSourceServer) Run(_ context.Context, state multistep.StateBag) m
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add keypair to the server create options.
|
// Add keypair to the server create options.
|
||||||
keyName := s.Comm.SSHKeyPairName
|
keyName := config.Comm.SSHKeyPairName
|
||||||
if keyName != "" {
|
if keyName != "" {
|
||||||
serverOptsExt = keypairs.CreateOptsExt{
|
serverOptsExt = keypairs.CreateOptsExt{
|
||||||
CreateOptsBuilder: serverOptsExt,
|
CreateOptsBuilder: serverOptsExt,
|
||||||
|
@ -148,7 +146,7 @@ func (s *StepRunSourceServer) Cleanup(state multistep.StateBag) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
// We need the v2 compute client
|
// We need the v2 compute client
|
||||||
|
|
|
@ -19,7 +19,7 @@ type StepSourceImageInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepSourceImageInfo) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepSourceImageInfo) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
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 != "" {
|
if s.SourceImage != "" {
|
||||||
|
|
|
@ -14,7 +14,7 @@ type StepStopServer struct{}
|
||||||
|
|
||||||
func (s *StepStopServer) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepStopServer) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
server := state.Get("server").(*servers.Server)
|
server := state.Get("server").(*servers.Server)
|
||||||
|
|
||||||
// We need the v2 compute client
|
// We need the v2 compute client
|
||||||
|
|
|
@ -14,7 +14,7 @@ type stepUpdateImageVisibility struct{}
|
||||||
func (s *stepUpdateImageVisibility) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *stepUpdateImageVisibility) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
imageId := state.Get("image").(string)
|
imageId := state.Get("image").(string)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
|
|
||||||
if config.ImageVisibility == "" {
|
if config.ImageVisibility == "" {
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (s *StepWaitForRackConnect) Run(_ context.Context, state multistep.StateBag
|
||||||
return multistep.ActionContinue
|
return multistep.ActionContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
server := state.Get("server").(*servers.Server)
|
server := state.Get("server").(*servers.Server)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
||||||
}
|
}
|
||||||
|
|
||||||
state := new(multistep.BasicStateBag)
|
state := new(multistep.BasicStateBag)
|
||||||
state.Put("config", b.config)
|
state.Put("config", &b.config)
|
||||||
state.Put("debug", b.config.PackerDebug)
|
state.Put("debug", b.config.PackerDebug)
|
||||||
state.Put("driver", driver)
|
state.Put("driver", driver)
|
||||||
state.Put("hook", hook)
|
state.Put("hook", hook)
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testConfig(t *testing.T) Config {
|
func testConfig(t *testing.T) *Config {
|
||||||
return Config{
|
return &Config{
|
||||||
AccessConfig: testAccessConfig(),
|
AccessConfig: testAccessConfig(),
|
||||||
SourceMachineConfig: testSourceMachineConfig(t),
|
SourceMachineConfig: testSourceMachineConfig(t),
|
||||||
TargetImageConfig: testTargetImageConfig(t),
|
TargetImageConfig: testTargetImageConfig(t),
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
type StepCreateImageFromMachine struct{}
|
type StepCreateImageFromMachine struct{}
|
||||||
|
|
||||||
func (s *StepCreateImageFromMachine) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepCreateImageFromMachine) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
driver := state.Get("driver").(Driver)
|
driver := state.Get("driver").(Driver)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ func (s *StepCreateImageFromMachine) Run(_ context.Context, state multistep.Stat
|
||||||
|
|
||||||
ui.Say("Creating image from source machine...")
|
ui.Say("Creating image from source machine...")
|
||||||
|
|
||||||
imageId, err := driver.CreateImageFromMachine(machineId, config)
|
imageId, err := driver.CreateImageFromMachine(machineId, *config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", fmt.Errorf("Problem creating image from machine: %s", err))
|
state.Put("error", fmt.Errorf("Problem creating image from machine: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
|
|
@ -14,13 +14,13 @@ import (
|
||||||
type StepCreateSourceMachine struct{}
|
type StepCreateSourceMachine struct{}
|
||||||
|
|
||||||
func (s *StepCreateSourceMachine) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepCreateSourceMachine) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
config := state.Get("config").(Config)
|
config := state.Get("config").(*Config)
|
||||||
driver := state.Get("driver").(Driver)
|
driver := state.Get("driver").(Driver)
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
if !config.MachineImageFilters.Empty() {
|
if !config.MachineImageFilters.Empty() {
|
||||||
ui.Say("Selecting an image based on search criteria")
|
ui.Say("Selecting an image based on search criteria")
|
||||||
imageId, err := driver.GetImage(config)
|
imageId, err := driver.GetImage(*config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", fmt.Errorf("Problem selecting an image based on an search criteria: %s", err))
|
state.Put("error", fmt.Errorf("Problem selecting an image based on an search criteria: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
@ -29,7 +29,7 @@ func (s *StepCreateSourceMachine) Run(_ context.Context, state multistep.StateBa
|
||||||
config.MachineImage = imageId
|
config.MachineImage = imageId
|
||||||
}
|
}
|
||||||
|
|
||||||
machineId, err := driver.CreateMachine(config)
|
machineId, err := driver.CreateMachine(*config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", fmt.Errorf("Problem creating source machine: %s", err))
|
state.Put("error", fmt.Errorf("Problem creating source machine: %s", err))
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
|
|
Loading…
Reference in New Issue