diff options
author | Brent Baude <bbaude@redhat.com> | 2020-04-16 12:25:26 -0500 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2020-04-16 15:53:58 -0500 |
commit | 241326a9a8c20ad7f2bcf651416b836e7778e090 (patch) | |
tree | 4001e8e47a022bb1b9bfbf2332c42e1aeb802f9e /pkg/varlinkapi/pods.go | |
parent | 88c6fd06cd54fb9a8826306dfdf1a77e400de5de (diff) | |
download | podman-241326a9a8c20ad7f2bcf651416b836e7778e090.tar.gz podman-241326a9a8c20ad7f2bcf651416b836e7778e090.tar.bz2 podman-241326a9a8c20ad7f2bcf651416b836e7778e090.zip |
Podman V2 birth
remote podman v1 and replace with podman v2.
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'pkg/varlinkapi/pods.go')
-rw-r--r-- | pkg/varlinkapi/pods.go | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/pkg/varlinkapi/pods.go b/pkg/varlinkapi/pods.go index 94add1b6c..5a9360447 100644 --- a/pkg/varlinkapi/pods.go +++ b/pkg/varlinkapi/pods.go @@ -5,11 +5,14 @@ package varlinkapi import ( "encoding/json" "fmt" + "strconv" "syscall" - "github.com/containers/libpod/cmd/podman/shared" + "github.com/cri-o/ocicni/pkg/ocicni" + "github.com/docker/go-connections/nat" + "github.com/pkg/errors" + "github.com/containers/libpod/libpod" - "github.com/containers/libpod/pkg/adapter/shortcuts" iopodman "github.com/containers/libpod/pkg/varlink" ) @@ -18,7 +21,7 @@ func (i *VarlinkAPI) CreatePod(call iopodman.VarlinkCall, create iopodman.PodCre var options []libpod.PodCreateOption if create.Infra { options = append(options, libpod.WithInfraContainer()) - nsOptions, err := shared.GetNamespaceOptions(create.Share) + nsOptions, err := GetNamespaceOptions(create.Share) if err != nil { return err } @@ -44,7 +47,7 @@ func (i *VarlinkAPI) CreatePod(call iopodman.VarlinkCall, create iopodman.PodCre if !create.Infra { return call.ReplyErrorOccurred("you must have an infra container to publish port bindings to the host") } - portBindings, err := shared.CreatePortBindings(create.Publish) + portBindings, err := CreatePortBindings(create.Publish) if err != nil { return call.ReplyErrorOccurred(err.Error()) } @@ -70,7 +73,7 @@ func (i *VarlinkAPI) ListPods(call iopodman.VarlinkCall) error { if err != nil { return call.ReplyErrorOccurred(err.Error()) } - opts := shared.PsOptions{} + opts := PsOptions{} for _, pod := range pods { listPod, err := makeListPod(pod, opts) if err != nil { @@ -87,7 +90,7 @@ func (i *VarlinkAPI) GetPod(call iopodman.VarlinkCall, name string) error { if err != nil { return call.ReplyPodNotFound(name, err.Error()) } - opts := shared.PsOptions{} + opts := PsOptions{} listPod, err := makeListPod(pod, opts) if err != nil { @@ -100,7 +103,7 @@ func (i *VarlinkAPI) GetPod(call iopodman.VarlinkCall, name string) error { // GetPodsByStatus returns a slice of pods filtered by a libpod status func (i *VarlinkAPI) GetPodsByStatus(call iopodman.VarlinkCall, statuses []string) error { filterFuncs := func(p *libpod.Pod) bool { - state, _ := shared.GetPodStatus(p) + state, _ := p.GetPodStatus() for _, status := range statuses { if state == status { return true @@ -290,11 +293,11 @@ func (i *VarlinkAPI) GetPodStats(call iopodman.VarlinkCall, name string) error { return call.ReplyGetPodStats(pod.ID(), containersStats) } -// GetPodsByContext returns a slice of pod ids based on all, latest, or a list +// getPodsByContext returns a slice of pod ids based on all, latest, or a list func (i *VarlinkAPI) GetPodsByContext(call iopodman.VarlinkCall, all, latest bool, input []string) error { var podids []string - pods, err := shortcuts.GetPodsByContext(all, latest, input, i.Runtime) + pods, err := getPodsByContext(all, latest, input, i.Runtime) if err != nil { return call.ReplyErrorOccurred(err.Error()) } @@ -337,7 +340,7 @@ func (i *VarlinkAPI) TopPod(call iopodman.VarlinkCall, name string, latest bool, return call.ReplyPodNotFound(name, err.Error()) } - podStatus, err := shared.GetPodStatus(pod) + podStatus, err := pod.GetPodStatus() if err != nil { return call.ReplyErrorOccurred(fmt.Sprintf("unable to get status for pod %s", pod.ID())) } @@ -350,3 +353,36 @@ func (i *VarlinkAPI) TopPod(call iopodman.VarlinkCall, name string, latest bool, } return call.ReplyTopPod(reply) } + +// 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 +} |