Fix port ordering

This commit is contained in:
Marcos Lilljedahl
2017-04-16 20:22:37 -03:00
parent d6c359645c
commit 6acb6f47c5
5 changed files with 22 additions and 13 deletions

View File

@@ -5,7 +5,6 @@ import (
"io"
"log"
"os"
"sort"
"strconv"
"strings"
@@ -101,7 +100,7 @@ func SetInstanceSwarmPorts(i *Instance) error {
return nil
}
func GetUsedPorts(i *Instance) ([]int, error) {
func GetUsedPorts(i *Instance) ([]uint16, error) {
if i.dockerClient == nil {
return nil, fmt.Errorf("Docker client for DinD (%s) is not ready", i.IP)
}
@@ -111,16 +110,15 @@ func GetUsedPorts(i *Instance) ([]int, error) {
return nil, err
}
openPorts := sort.IntSlice{}
openPorts := []uint16{}
for _, c := range containers {
for _, p := range c.Ports {
// When port is not published on the host docker return public port as 0, so we need to avoid it
if p.PublicPort != 0 {
openPorts = append(openPorts, int(p.PublicPort))
openPorts = append(openPorts, p.PublicPort)
}
}
}
sort.Sort(openPorts)
return openPorts, nil
}