builder/virtualbox,vmware: work if port range for HTTP is 0 [GH-53]

This commit is contained in:
Mitchell Hashimoto 2013-06-28 21:59:29 -04:00
parent 222f47dac8
commit 8aaadf354a
3 changed files with 20 additions and 2 deletions

View File

@ -4,6 +4,10 @@ BUG FIXES:
* core: plugins listen explicitly on 127.0.0.1, fixing odd hangs. [GH-37]
* virtualbox: `boot_wait` defaults to "10s" rather than 0. [GH-44]
* virtualbox: if `http_port_min` and max are the same, it will no longer
panic [GH-53]
* vmware: if `http_port_min` and max are the same, it will no longer
panic [GH-53]
## 0.1.0 (June 28, 2013)

View File

@ -38,7 +38,14 @@ func (s *stepHTTPServer) Run(state map[string]interface{}) multistep.StepAction
portRange := int(config.HTTPPortMax - config.HTTPPortMin)
for {
var err error
httpPort = uint(rand.Intn(portRange)) + config.HTTPPortMin
var offset uint = 0
if portRange > 0 {
// Intn will panic if portRange == 0, so we do a check.
offset = uint(rand.Intn(portRange))
}
httpPort = offset + config.HTTPPortMin
httpAddr = fmt.Sprintf(":%d", httpPort)
log.Printf("Trying port: %d", httpPort)
s.l, err = net.Listen("tcp", httpAddr)

View File

@ -38,7 +38,14 @@ func (s *stepHTTPServer) Run(state map[string]interface{}) multistep.StepAction
portRange := int(config.HTTPPortMax - config.HTTPPortMin)
for {
var err error
httpPort = uint(rand.Intn(portRange)) + config.HTTPPortMin
var offset uint = 0
if portRange > 0 {
// Intn will panic if portRange == 0, so we do a check.
offset = uint(rand.Intn(portRange))
}
httpPort = offset + config.HTTPPortMin
httpAddr = fmt.Sprintf(":%d", httpPort)
log.Printf("Trying port: %d", httpPort)
s.l, err = net.Listen("tcp", httpAddr)