github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/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  	Gateway     string
    16  	Bridge      string
    17  	PortMapping map[string]PortMapping // Deprecated
    18  	Ports       nat.PortMap
    19  }
    20  
    21  func (settings *NetworkSettings) PortMappingAPI() *engine.Table {
    22  	var outs = engine.NewTable("", 0)
    23  	for port, bindings := range settings.Ports {
    24  		p, _ := nat.ParsePort(port.Port())
    25  		if len(bindings) == 0 {
    26  			out := &engine.Env{}
    27  			out.SetInt("PrivatePort", p)
    28  			out.Set("Type", port.Proto())
    29  			outs.Add(out)
    30  			continue
    31  		}
    32  		for _, binding := range bindings {
    33  			out := &engine.Env{}
    34  			h, _ := nat.ParsePort(binding.HostPort)
    35  			out.SetInt("PrivatePort", p)
    36  			out.SetInt("PublicPort", h)
    37  			out.Set("Type", port.Proto())
    38  			out.Set("IP", binding.HostIp)
    39  			outs.Add(out)
    40  		}
    41  	}
    42  	return outs
    43  }