OpenStack builder: update floating IP params

Rename "floating_network" to the "floating_ip_network".
Return old "floating_ip_pool" parameter for backward compatibility with
old configuration files. It's value will be passed to the
"floating_ip_network" parameter.
This commit is contained in:
Andrei Ozerov 2018-06-12 14:08:17 +03:00
parent 0eef9b4292
commit c9047cbfbe
4 changed files with 41 additions and 26 deletions

View File

@ -115,9 +115,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Wait: b.config.RackconnectWait, Wait: b.config.RackconnectWait,
}, },
&StepAllocateIp{ &StepAllocateIp{
FloatingNetwork: b.config.FloatingNetwork, FloatingIPNetwork: b.config.FloatingIPNetwork,
FloatingIP: b.config.FloatingIP, FloatingIP: b.config.FloatingIP,
ReuseIPs: b.config.ReuseIPs, ReuseIPs: b.config.ReuseIPs,
}, },
&communicator.StepConnect{ &communicator.StepConnect{
Config: &b.config.RunConfig.Comm, Config: &b.config.RunConfig.Comm,

View File

@ -18,24 +18,27 @@ type RunConfig struct {
SSHInterface string `mapstructure:"ssh_interface"` SSHInterface string `mapstructure:"ssh_interface"`
SSHIPVersion string `mapstructure:"ssh_ip_version"` SSHIPVersion string `mapstructure:"ssh_ip_version"`
SourceImage string `mapstructure:"source_image"` SourceImage string `mapstructure:"source_image"`
SourceImageName string `mapstructure:"source_image_name"` SourceImageName string `mapstructure:"source_image_name"`
Flavor string `mapstructure:"flavor"` Flavor string `mapstructure:"flavor"`
AvailabilityZone string `mapstructure:"availability_zone"` AvailabilityZone string `mapstructure:"availability_zone"`
RackconnectWait bool `mapstructure:"rackconnect_wait"` RackconnectWait bool `mapstructure:"rackconnect_wait"`
FloatingNetwork string `mapstructure:"floating_network"` FloatingIPNetwork string `mapstructure:"floating_ip_network"`
FloatingIP string `mapstructure:"floating_ip"` FloatingIP string `mapstructure:"floating_ip"`
ReuseIPs bool `mapstructure:"reuse_ips"` ReuseIPs bool `mapstructure:"reuse_ips"`
SecurityGroups []string `mapstructure:"security_groups"` SecurityGroups []string `mapstructure:"security_groups"`
Networks []string `mapstructure:"networks"` Networks []string `mapstructure:"networks"`
Ports []string `mapstructure:"ports"` Ports []string `mapstructure:"ports"`
UserData string `mapstructure:"user_data"` UserData string `mapstructure:"user_data"`
UserDataFile string `mapstructure:"user_data_file"` UserDataFile string `mapstructure:"user_data_file"`
InstanceName string `mapstructure:"instance_name"` InstanceName string `mapstructure:"instance_name"`
InstanceMetadata map[string]string `mapstructure:"instance_metadata"` InstanceMetadata map[string]string `mapstructure:"instance_metadata"`
ConfigDrive bool `mapstructure:"config_drive"` ConfigDrive bool `mapstructure:"config_drive"`
// Used for BC, value will be passed to the "floating_ip_network"
FloatingIPPool string `mapstructure:"floating_ip_pool"`
UseBlockStorageVolume bool `mapstructure:"use_blockstorage_volume"` UseBlockStorageVolume bool `mapstructure:"use_blockstorage_volume"`
VolumeName string `mapstructure:"volume_name"` VolumeName string `mapstructure:"volume_name"`
VolumeType string `mapstructure:"volume_type"` VolumeType string `mapstructure:"volume_type"`
@ -57,6 +60,10 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
c.TemporaryKeyPairName = fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID()) c.TemporaryKeyPairName = fmt.Sprintf("packer_%s", uuid.TimeOrderedUUID())
} }
if c.FloatingIPPool != "" {
c.FloatingIPNetwork = c.FloatingIPPool
}
// Validation // Validation
errs := c.Comm.Prepare(ctx) errs := c.Comm.Prepare(ctx)

View File

@ -101,11 +101,19 @@ func TestRunConfigPrepare_BlockStorage(t *testing.T) {
} }
c.VolumeName = "PackerVolume" c.VolumeName = "PackerVolume"
if err := c.Prepare(nil); len(err) != 0 {
t.Fatalf("err: %s", err)
}
if c.VolumeName != "PackerVolume" { if c.VolumeName != "PackerVolume" {
t.Fatalf("invalid value: %s", c.VolumeName) t.Fatalf("invalid value: %s", c.VolumeName)
} }
} }
func TestRunConfigPrepare_FloatingIPPoolCompat(t *testing.T) {
c := testRunConfig()
c.FloatingIPPool = "uuid"
if err := c.Prepare(nil); len(err) != 0 {
t.Fatalf("err: %s", err)
}
if c.FloatingIPNetwork != "uuid" {
t.Fatalf("invalid value: %s", c.FloatingIPNetwork)
}
}

View File

@ -11,9 +11,9 @@ import (
) )
type StepAllocateIp struct { type StepAllocateIp struct {
FloatingNetwork string FloatingIPNetwork string
FloatingIP string FloatingIP string
ReuseIPs bool ReuseIPs bool
} }
func (s *StepAllocateIp) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *StepAllocateIp) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
@ -77,7 +77,7 @@ func (s *StepAllocateIp) Run(_ context.Context, state multistep.StateBag) multis
if instanceIP.ID == "" { if instanceIP.ID == "" {
// Search for the external network that can be used for the floating IPs if // Search for the external network that can be used for the floating IPs if
// user hasn't provided any. // user hasn't provided any.
floatingNetwork := s.FloatingNetwork floatingNetwork := s.FloatingIPNetwork
if floatingNetwork == "" { if floatingNetwork == "" {
ui.Say(fmt.Sprintf("Searching for the external network...")) ui.Say(fmt.Sprintf("Searching for the external network..."))
externalNetwork, err := FindExternalNetwork(networkClient) externalNetwork, err := FindExternalNetwork(networkClient)