Moving SSH IP version validation to prepare function.
This commit is contained in:
parent
8396a2db1e
commit
335a2010bf
|
@ -56,5 +56,9 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
|
||||||
errs = append(errs, errors.New("A flavor must be specified"))
|
errs = append(errs, errors.New("A flavor must be specified"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.SSHIPVersion != "" && c.SSHIPVersion != "4" && c.SSHIPVersion != "6" {
|
||||||
|
errs = append(errs, errors.New("SSH IP version must be either 4 or 6"))
|
||||||
|
}
|
||||||
|
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
|
@ -82,12 +81,6 @@ func SSHConfig(username string) func(multistep.StateBag) (*ssh.ClientConfig, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func sshAddrFromPool(s *servers.Server, desired string, sshIPVersion string) string {
|
func sshAddrFromPool(s *servers.Server, desired string, sshIPVersion string) string {
|
||||||
|
|
||||||
ipVersion, err := strconv.Atoi(sshIPVersion)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("[ERROR] Invalid ssh IP version: %s", sshIPVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all the addresses associated with this server. This
|
// Get all the addresses associated with this server. This
|
||||||
// was taken directly from Terraform.
|
// was taken directly from Terraform.
|
||||||
for pool, networkAddresses := range s.Addresses {
|
for pool, networkAddresses := range s.Addresses {
|
||||||
|
@ -112,11 +105,11 @@ func sshAddrFromPool(s *servers.Server, desired string, sshIPVersion string) str
|
||||||
address := element.(map[string]interface{})
|
address := element.(map[string]interface{})
|
||||||
if address["OS-EXT-IPS:type"] == "floating" {
|
if address["OS-EXT-IPS:type"] == "floating" {
|
||||||
addr = address["addr"].(string)
|
addr = address["addr"].(string)
|
||||||
} else if ipVersion == 4 {
|
} else if sshIPVersion == "4" {
|
||||||
if address["version"].(float64) == 4 {
|
if address["version"].(float64) == 4 {
|
||||||
addr = address["addr"].(string)
|
addr = address["addr"].(string)
|
||||||
}
|
}
|
||||||
} else if ipVersion == 6 {
|
} else if sshIPVersion == "6" {
|
||||||
if address["version"].(float64) == 6 {
|
if address["version"].(float64) == 6 {
|
||||||
addr = fmt.Sprintf("[%s]", address["addr"].(string))
|
addr = fmt.Sprintf("[%s]", address["addr"].(string))
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,7 +115,10 @@ builder.
|
||||||
useful for Rackspace are "public" or "private", and the default behavior is
|
useful for Rackspace are "public" or "private", and the default behavior is
|
||||||
to connect via whichever is returned first from the OpenStack API.
|
to connect via whichever is returned first from the OpenStack API.
|
||||||
|
|
||||||
- `ssh_ip_version` (string) - The IP version to use for SSH connections, valid values are `4` and `6`. Useful on dual stacked instances where the default behaviour is to connect via whichever IP address is returned first from the OpenStack API.
|
- `ssh_ip_version` (string) - The IP version to use for SSH connections, valid
|
||||||
|
values are `4` and `6`. Useful on dual stacked instances where the default
|
||||||
|
behaviour is to connect via whichever IP address is returned first from the
|
||||||
|
OpenStack API.
|
||||||
|
|
||||||
- `ssh_keypair_name` (string) - If specified, this is the key that will be
|
- `ssh_keypair_name` (string) - If specified, this is the key that will be
|
||||||
used for SSH with the machine. By default, this is blank, and Packer will
|
used for SSH with the machine. By default, this is blank, and Packer will
|
||||||
|
|
Loading…
Reference in New Issue