Added @SwampDragons' suggestion to the `CommHost()` implementation for the vmware builders which uses the communicator config's `Config.Port()` function to determine the communication port-number independent of the configured protocol.
This commit is contained in:
parent
e5b6d8c37c
commit
9c5a65263f
|
@ -438,10 +438,7 @@ func (ESX5Driver) UpdateVMX(_, password string, port int, data map[string]string
|
|||
|
||||
func (d *ESX5Driver) CommHost(state multistep.StateBag) (string, error) {
|
||||
sshc := state.Get("sshConfig").(*SSHConfig).Comm
|
||||
port := sshc.SSHPort
|
||||
if sshc.Type == "winrm" {
|
||||
port = sshc.WinRMPort
|
||||
}
|
||||
port := sshc.Port()
|
||||
|
||||
if address, ok := state.GetOk("vm_address"); ok {
|
||||
return address.(string), nil
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue