Didn't know that WinRM uses a different variable for the port number when trying to determine the communication host in `CommHost`...now it's fixed.
This commit is contained in:
parent
229b5d17ff
commit
e5b6d8c37c
|
@ -12,18 +12,26 @@ import (
|
|||
func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) {
|
||||
return func(state multistep.StateBag) (string, error) {
|
||||
driver := state.Get("driver").(Driver)
|
||||
comm := config.Comm
|
||||
|
||||
if config.Comm.SSHHost != "" {
|
||||
return config.Comm.SSHHost, nil
|
||||
// Figure out which protocol we're using to communicate with the
|
||||
// guest, and determine the correct port to handshake with.
|
||||
port := comm.SSHPort
|
||||
if comm.SSHHost != "" {
|
||||
return comm.SSHHost, nil
|
||||
}
|
||||
if comm.Type == "winrm" {
|
||||
port = comm.WinRMPort
|
||||
}
|
||||
|
||||
ipAddrs, err := driver.PotentialGuestIP(state)
|
||||
// Get the list of potential addresses that the guest might use.
|
||||
hosts, err := driver.PotentialGuestIP(state)
|
||||
if err != nil {
|
||||
log.Printf("IP lookup failed: %s", err)
|
||||
return "", fmt.Errorf("IP lookup failed: %s", err)
|
||||
}
|
||||
|
||||
if len(ipAddrs) == 0 {
|
||||
if len(hosts) == 0 {
|
||||
log.Println("IP is blank, no IP yet.")
|
||||
return "", errors.New("IP is blank")
|
||||
}
|
||||
|
@ -31,21 +39,21 @@ func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) {
|
|||
// Iterate through our list of addresses and dial each one. This way we
|
||||
// can dial up each one to see which lease is actually correct and has
|
||||
// ssh up.
|
||||
for index, ipAddress := range ipAddrs {
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", ipAddress, config.Comm.SSHPort))
|
||||
for index, host := range hosts {
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", host, port))
|
||||
|
||||
// If we got a connection, then we should be good to go. Return the
|
||||
// address to the caller and pray that things work out.
|
||||
if err == nil {
|
||||
conn.Close()
|
||||
|
||||
log.Printf("Detected IP: %s", ipAddress)
|
||||
return ipAddress, nil
|
||||
log.Printf("Detected IP: %s", host)
|
||||
return host, nil
|
||||
|
||||
}
|
||||
|
||||
// Otherwise we need to iterate to the next entry and keep hoping.
|
||||
log.Printf("Ignoring entry %d at %s:%d due to host being down.", index, ipAddress, config.Comm.SSHPort)
|
||||
log.Printf("Ignoring entry %d at %s:%d due to host being down.", index, host, port)
|
||||
}
|
||||
|
||||
return "", errors.New("Host is not up")
|
||||
|
|
Loading…
Reference in New Issue