From 7fc073a4d7429a7588e6990f6304a9a9116085ec Mon Sep 17 00:00:00 2001 From: Sven Dowideit Date: Wed, 9 Jul 2014 15:42:19 +1000 Subject: [PATCH] Found out that the port forwards are ordered dynamically based on the name of the forward, not its order of definition. --- virtualbox/machine.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/virtualbox/machine.go b/virtualbox/machine.go index cc47893..70b1e86 100644 --- a/virtualbox/machine.go +++ b/virtualbox/machine.go @@ -241,28 +241,29 @@ func GetMachine(id string) (*Machine, error) { case "CfgFile": m.CfgFile = val m.BaseFolder = filepath.Dir(val) - case "Forwarding(0)": - // Forwarding(0)="docker,tcp,127.0.0.1,5555,," - vals := strings.Split(val, ",") - n, err := strconv.ParseUint(vals[3], 10, 32) - if err != nil { - return nil, err - } - m.DockerPort = uint(n) - case "Forwarding(1)": - // Forwarding(1)="ssh,tcp,127.0.0.1,2222,,22" - vals := strings.Split(val, ",") - n, err := strconv.ParseUint(vals[3], 10, 32) - if err != nil { - return nil, err - } - m.SSHPort = uint(n) case "uartmode1": // uartmode1="server,/home/sven/.boot2docker/boot2docker-vm.sock" vals := strings.Split(val, ",") if len(vals) >= 2 { m.SerialFile = vals[1] } + default: + if strings.HasPrefix(key, "Forwarding(") { + // "Forwarding(\d*)" are ordered by the name inside the val, not fixed order. + // Forwarding(0)="docker,tcp,127.0.0.1,5555,," + // Forwarding(1)="ssh,tcp,127.0.0.1,2222,,22" + vals := strings.Split(val, ",") + n, err := strconv.ParseUint(vals[3], 10, 32) + if err != nil { + return nil, err + } + switch vals[0] { + case "docker": + m.DockerPort = uint(n) + case "ssh": + m.SSHPort = uint(n) + } + } } } if err := s.Err(); err != nil {