@ -14,15 +14,10 @@ func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) {
driver := state . Get ( "driver" ) . ( Driver )
comm := config . Comm
// 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
}
// Snag the port from the communicator config. This way we can use it
// to perform a 3-way handshake with all of the hosts we suspect in
// order to determine which one of the hosts is the correct one.
port := comm . Port ( )
// Get the list of potential addresses that the guest might use.
hosts , err := driver . PotentialGuestIP ( state )
@ -36,9 +31,10 @@ func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) {
return "" , errors . New ( "IP is blank" )
}
// 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.
// Iterate through our list of addresses and dial up each one similar to
// a really inefficient port-scan. This way we can determine which of
// the leases that we've parsed was the correct one and actually has our
// target ssh/winrm service bound to a tcp port.
for index , host := range hosts {
conn , err := net . Dial ( "tcp" , fmt . Sprintf ( "%s:%d" , host , port ) )
@ -53,7 +49,7 @@ func CommHost(config *SSHConfig) func(multistep.StateBag) (string, error) {
}
// 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 , host , port )
log . Printf ( " Skipping lease entry #%d due to being unable to connect to the host (%s) with tcp port (%d).", 1 + index , host , port )
}
return "" , errors . New ( "Host is not up" )