Merge branch 'ldx-master'

This commit is contained in:
Mitchell Hashimoto 2015-06-18 10:18:22 +02:00
commit 25533336ca
2 changed files with 11 additions and 1 deletions

View File

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

View File

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