replace duplicate commHost functions with a single communicator helper that checks for ssh_host and does a statebag lookup for a given key

This commit is contained in:
Megan Marsh
2019-07-03 13:30:29 -07:00
parent 0cfe8e7070
commit c03c3f4410
17 changed files with 9 additions and 155 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
&stepSetupNetworking{},
&communicator.StepConnect{
Config: &b.config.Comm,
Host: commHost(b.config.Comm.SSHHost),
Host: communicator.CommHost(b.config.Comm.SSHHost, "ipaddress"),
SSHConfig: b.config.Comm.SSHConfigFunc(),
SSHPort: commPort,
WinRMPort: commPort,
-15
View File
@@ -7,21 +7,6 @@ import (
"github.com/hashicorp/packer/helper/multistep"
)
func commHost(host string) func(multistep.StateBag) (string, error) {
return func(state multistep.StateBag) (string, error) {
if host != "" {
log.Printf("Using ssh_host value: %s", host)
return host, nil
}
ip, hasIP := state.Get("ipaddress").(string)
if !hasIP {
return "", fmt.Errorf("Failed to retrieve IP address")
}
return ip, nil
}
}
func commPort(state multistep.StateBag) (int, error) {
commPort, hasPort := state.Get("commPort").(int)
if !hasPort {