2014-04-17 17:43:01 -04:00
|
|
|
package daemon
|
2014-04-14 02:15:31 -04:00
|
|
|
|
|
|
|
import (
|
2014-07-24 18:19:50 -04:00
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
"github.com/docker/docker/nat"
|
2014-04-14 02:15:31 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// FIXME: move deprecated port stuff to nat to clean up the core.
|
|
|
|
type PortMapping map[string]string // Deprecated
|
|
|
|
|
|
|
|
type NetworkSettings struct {
|
2015-01-08 18:03:19 -05:00
|
|
|
IPAddress string
|
|
|
|
IPPrefixLen int
|
|
|
|
MacAddress string
|
|
|
|
LinkLocalIPv6Address string
|
|
|
|
LinkLocalIPv6PrefixLen int
|
|
|
|
GlobalIPv6Address string
|
|
|
|
GlobalIPv6PrefixLen int
|
|
|
|
Gateway string
|
|
|
|
IPv6Gateway string
|
|
|
|
Bridge string
|
|
|
|
PortMapping map[string]PortMapping // Deprecated
|
|
|
|
Ports nat.PortMap
|
2014-04-14 02:15:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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{}
|
2014-05-12 18:26:23 -04:00
|
|
|
out.SetInt("PrivatePort", p)
|
2014-04-14 02:15:31 -04:00
|
|
|
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
|
|
|
|
}
|