mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
f00ca72baa
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
42 lines
1,004 B
Go
42 lines
1,004 B
Go
package runtime
|
|
|
|
import (
|
|
"github.com/dotcloud/docker/engine"
|
|
"github.com/dotcloud/docker/nat"
|
|
)
|
|
|
|
// FIXME: move deprecated port stuff to nat to clean up the core.
|
|
type PortMapping map[string]string // Deprecated
|
|
|
|
type NetworkSettings struct {
|
|
IPAddress string
|
|
IPPrefixLen int
|
|
Gateway string
|
|
Bridge string
|
|
PortMapping map[string]PortMapping // Deprecated
|
|
Ports nat.PortMap
|
|
}
|
|
|
|
func (settings *NetworkSettings) PortMappingAPI() *engine.Table {
|
|
var outs = engine.NewTable("", 0)
|
|
for port, bindings := range settings.Ports {
|
|
p, _ := nat.ParsePort(port.Port())
|
|
if len(bindings) == 0 {
|
|
out := &engine.Env{}
|
|
out.SetInt("PublicPort", p)
|
|
out.Set("Type", port.Proto())
|
|
outs.Add(out)
|
|
continue
|
|
}
|
|
for _, binding := range bindings {
|
|
out := &engine.Env{}
|
|
h, _ := nat.ParsePort(binding.HostPort)
|
|
out.SetInt("PrivatePort", p)
|
|
out.SetInt("PublicPort", h)
|
|
out.Set("Type", port.Proto())
|
|
out.Set("IP", binding.HostIp)
|
|
outs.Add(out)
|
|
}
|
|
}
|
|
return outs
|
|
}
|