diff options
Diffstat (limited to 'pkg/varlinkapi/util.go')
-rw-r--r-- | pkg/varlinkapi/util.go | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/pkg/varlinkapi/util.go b/pkg/varlinkapi/util.go index 667c09562..a80c8db41 100644 --- a/pkg/varlinkapi/util.go +++ b/pkg/varlinkapi/util.go @@ -5,9 +5,9 @@ import ( "strconv" "time" - "github.com/projectatomic/libpod/cmd/podman/batchcontainer" - "github.com/projectatomic/libpod/cmd/podman/varlink" - "github.com/projectatomic/libpod/libpod" + "github.com/containers/libpod/cmd/podman/shared" + "github.com/containers/libpod/cmd/podman/varlink" + "github.com/containers/libpod/libpod" ) // getContext returns a non-nil, empty context @@ -15,12 +15,12 @@ func getContext() context.Context { return context.TODO() } -func makeListContainer(containerID string, batchInfo batchcontainer.BatchContainerStruct) iopodman.ListContainerData { +func makeListContainer(containerID string, batchInfo shared.BatchContainerStruct) iopodman.ListContainerData { var ( mounts []iopodman.ContainerMount ports []iopodman.ContainerPortMappings ) - ns := batchcontainer.GetNamespaces(batchInfo.Pid) + ns := shared.GetNamespaces(batchInfo.Pid) for _, mount := range batchInfo.ConConfig.Spec.Mounts { m := iopodman.ContainerMount{ @@ -77,3 +77,59 @@ func makeListContainer(containerID string, batchInfo batchcontainer.BatchContain } return lc } + +func makeListPodContainers(containerID string, batchInfo shared.BatchContainerStruct) iopodman.ListPodContainerInfo { + lc := iopodman.ListPodContainerInfo{ + Id: containerID, + Status: batchInfo.ConState.String(), + Name: batchInfo.ConConfig.Name, + } + return lc +} + +func makeListPod(pod *libpod.Pod, batchInfo shared.PsOptions) (iopodman.ListPodData, error) { + var listPodsContainers []iopodman.ListPodContainerInfo + var errPodData = iopodman.ListPodData{} + status, err := shared.GetPodStatus(pod) + if err != nil { + return errPodData, err + } + containers, err := pod.AllContainers() + if err != nil { + return errPodData, err + } + for _, ctr := range containers { + batchInfo, err := shared.BatchContainerOp(ctr, batchInfo) + if err != nil { + return errPodData, err + } + + listPodsContainers = append(listPodsContainers, makeListPodContainers(ctr.ID(), batchInfo)) + } + listPod := iopodman.ListPodData{ + Createdat: pod.CreatedTime().String(), + Id: pod.ID(), + Name: pod.Name(), + Status: status, + Cgroup: pod.CgroupParent(), + Numberofcontainers: strconv.Itoa(len(listPodsContainers)), + Containersinfo: listPodsContainers, + } + return listPod, nil +} + +func handlePodCall(call iopodman.VarlinkCall, pod *libpod.Pod, ctrErrs map[string]error, err error) error { + if err != nil && ctrErrs == nil { + return call.ReplyErrorOccurred(err.Error()) + } + if ctrErrs != nil { + containerErrs := make([]iopodman.PodContainerErrorData, len(ctrErrs)) + for ctr, reason := range ctrErrs { + ctrErr := iopodman.PodContainerErrorData{Containerid: ctr, Reason: reason.Error()} + containerErrs = append(containerErrs, ctrErr) + } + return call.ReplyPodContainerError(pod.ID(), containerErrs) + } + + return nil +} |