network_settings.go 1.2 KB

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