From 956b9ded0a673ef04589e6c0eda8eefb10571bf4 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Fri, 10 Apr 2015 14:57:32 -0700 Subject: [PATCH] Try another ssh port if the current one is taken. --- builder/qemu/step_forward_ssh.go | 5 +++++ builder/virtualbox/common/step_forward_ssh.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/builder/qemu/step_forward_ssh.go b/builder/qemu/step_forward_ssh.go index 3b84d26c1..ebf54b093 100644 --- a/builder/qemu/step_forward_ssh.go +++ b/builder/qemu/step_forward_ssh.go @@ -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)) diff --git a/builder/virtualbox/common/step_forward_ssh.go b/builder/virtualbox/common/step_forward_ssh.go index 862432952..4772f8d37 100644 --- a/builder/virtualbox/common/step_forward_ssh.go +++ b/builder/virtualbox/common/step_forward_ssh.go @@ -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