github.com/dougm/docker@v1.5.0/daemon/network_settings.go (about)

     1  package daemon
     2  
     3  import (
     4  	"github.com/docker/docker/engine"
     5  	"github.com/docker/docker/nat"
     6  )
     7  
     8  // FIXME: move deprecated port stuff to nat to clean up the core.
     9  type PortMapping map[string]string // Deprecated
    10  
    11  type NetworkSettings struct {
    12  	IPAddress              string
    13  	IPPrefixLen            int
    14  	MacAddress             string
    15  	LinkLocalIPv6Address   string
    16  	LinkLocalIPv6PrefixLen int
    17  	GlobalIPv6Address      string
    18  	GlobalIPv6PrefixLen    int
    19  	Gateway                string
    20  	IPv6Gateway            string
    21  	Bridge                 string
    22  	PortMapping            map[string]PortMapping // Deprecated
    23  	Ports                  nat.PortMap
    24  }
    25  
    26  func (settings *NetworkSettings) PortMappingAPI() *engine.Table {
    27  	var outs = engine.NewTable("", 0)
    28  	for port, bindings := range settings.Ports {
    29  		p, _ := nat.ParsePort(port.Port())
    30  		if len(bindings) == 0 {
    31  			out := &engine.Env{}
    32  			out.SetInt("PrivatePort", p)
    33  			out.Set("Type", port.Proto())
    34  			outs.Add(out)
    35  			continue
    36  		}
    37  		for _, binding := range bindings {
    38  			out := &engine.Env{}
    39  			h, _ := nat.ParsePort(binding.HostPort)
    40  			out.SetInt("PrivatePort", p)
    41  			out.SetInt("PublicPort", h)
    42  			out.Set("Type", port.Proto())
    43  			out.Set("IP", binding.HostIp)
    44  			outs.Add(out)
    45  		}
    46  	}
    47  	return outs
    48  }