MCPcopy Index your code
hub / github.com/moby/moby / parsePortMap

Function parsePortMap

daemon/cluster/executor/container/controller.go:651–685  ·  view source on GitHub ↗
(portMap network.PortMap)

Source from the content-addressed store, hash-verified

649}
650
651func parsePortMap(portMap network.PortMap) ([]*api.PortConfig, error) {
652 exposedPorts := make([]*api.PortConfig, 0, len(portMap))
653
654 for port, mapping := range portMap {
655 var protocol api.PortConfig_Protocol
656 switch port.Proto() {
657 case network.TCP:
658 protocol = api.ProtocolTCP
659 case network.UDP:
660 protocol = api.ProtocolUDP
661 case network.SCTP:
662 protocol = api.ProtocolSCTP
663 default:
664 return nil, fmt.Errorf("invalid protocol: %s", port.Proto())
665 }
666
667 for _, binding := range mapping {
668 hostPort, err := strconv.ParseUint(binding.HostPort, 10, 16)
669 if err != nil {
670 return nil, err
671 }
672
673 // TODO(aluzzardi): We're losing the port `name` here since
674 // there's no way to retrieve it back from the Engine.
675 exposedPorts = append(exposedPorts, &api.PortConfig{
676 PublishMode: api.PublishModeHost,
677 Protocol: protocol,
678 TargetPort: uint32(port.Num()),
679 PublishedPort: uint32(hostPort),
680 })
681 }
682 }
683
684 return exposedPorts, nil
685}
686
687type exitError struct {
688 code int

Callers 1

parsePortStatusFunction · 0.85

Calls 3

ErrorfMethod · 0.80
NumMethod · 0.80
ProtoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…