summaryrefslogtreecommitdiff
path: root/cmd/podman/shared
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2018-12-17 07:45:51 -0800
committerGitHub <noreply@github.com>2018-12-17 07:45:51 -0800
commita1902dc48b11573ac35fa69ebdfe09def4857efd (patch)
tree28f285ee2c4503e12cbb84ade32e34d93876e05c /cmd/podman/shared
parentb21d47434f49e1d57fa2b0329ee90eef80b70714 (diff)
parent06d763d964c16fe0f19cb04f4f28f8c0ab8980bc (diff)
downloadpodman-a1902dc48b11573ac35fa69ebdfe09def4857efd.tar.gz
podman-a1902dc48b11573ac35fa69ebdfe09def4857efd.tar.bz2
podman-a1902dc48b11573ac35fa69ebdfe09def4857efd.zip
Merge pull request #1986 from baude/varlinkendpoints
Clean up some existing varlink endpoints
Diffstat (limited to 'cmd/podman/shared')
-rw-r--r--cmd/podman/shared/pod.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/cmd/podman/shared/pod.go b/cmd/podman/shared/pod.go
index 4e8e58c4d..30dd14845 100644
--- a/cmd/podman/shared/pod.go
+++ b/cmd/podman/shared/pod.go
@@ -1,7 +1,11 @@
package shared
import (
+ "strconv"
+
"github.com/containers/libpod/libpod"
+ "github.com/cri-o/ocicni/pkg/ocicni"
+ "github.com/docker/go-connections/nat"
"github.com/pkg/errors"
)
@@ -95,3 +99,36 @@ func GetNamespaceOptions(ns []string) ([]libpod.PodCreateOption, error) {
}
return options, nil
}
+
+// CreatePortBindings iterates ports mappings and exposed ports into a format CNI understands
+func CreatePortBindings(ports []string) ([]ocicni.PortMapping, error) {
+ var portBindings []ocicni.PortMapping
+ // The conversion from []string to natBindings is temporary while mheon reworks the port
+ // deduplication code. Eventually that step will not be required.
+ _, natBindings, err := nat.ParsePortSpecs(ports)
+ if err != nil {
+ return nil, err
+ }
+ for containerPb, hostPb := range natBindings {
+ var pm ocicni.PortMapping
+ pm.ContainerPort = int32(containerPb.Int())
+ for _, i := range hostPb {
+ var hostPort int
+ var err error
+ pm.HostIP = i.HostIP
+ if i.HostPort == "" {
+ hostPort = containerPb.Int()
+ } else {
+ hostPort, err = strconv.Atoi(i.HostPort)
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to convert host port to integer")
+ }
+ }
+
+ pm.HostPort = int32(hostPort)
+ pm.Protocol = containerPb.Proto()
+ portBindings = append(portBindings, pm)
+ }
+ }
+ return portBindings, nil
+}