Try another ssh port if the current one is taken.

This commit is contained in:
Vilmos Nebehaj 2015-04-10 14:57:32 -07:00
parent b49d74d999
commit 956b9ded0a
2 changed files with 10 additions and 0 deletions

View File

@ -34,12 +34,17 @@ func (s *stepForwardSSH) Run(state multistep.StateBag) multistep.StepAction {
for {
sshHostPort = offset + config.SSHHostPortMin
if sshHostPort >= config.SSHHostPortMax {
offset = 0
sshHostPort = config.SSHHostPortMin
}
log.Printf("Trying port: %d", sshHostPort)
l, err := net.Listen("tcp", fmt.Sprintf(":%d", sshHostPort))
if err == nil {
defer l.Close()
break
}
offset++
}
ui.Say(fmt.Sprintf("Found port for SSH: %d.", sshHostPort))

View File

@ -42,12 +42,17 @@ func (s *StepForwardSSH) Run(state multistep.StateBag) multistep.StepAction {
for {
sshHostPort = offset + s.HostPortMin
if sshHostPort >= s.HostPortMax {
offset = 0
sshHostPort = s.HostPortMin
}
log.Printf("Trying port: %d", sshHostPort)
l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", sshHostPort))
if err == nil {
defer l.Close()
break
}
offset++
}
// Create a forwarded port mapping to the VM