From c4fadaba6b46029c4c94ef7779eac73345cde07a Mon Sep 17 00:00:00 2001 From: haircommander Date: Thu, 16 Aug 2018 11:41:53 -0400 Subject: Added helper function for libpod pod api calls Signed-off-by: haircommander Closes: #1275 Approved by: mheon --- pkg/varlinkapi/pods.go | 90 ++++++++++++-------------------------------------- 1 file changed, 21 insertions(+), 69 deletions(-) (limited to 'pkg/varlinkapi/pods.go') diff --git a/pkg/varlinkapi/pods.go b/pkg/varlinkapi/pods.go index a987574b2..640dd665e 100644 --- a/pkg/varlinkapi/pods.go +++ b/pkg/varlinkapi/pods.go @@ -4,9 +4,9 @@ import ( "encoding/json" "syscall" - "github.com/projectatomic/libpod/cmd/podman/shared" - "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" ) // CreatePod ... @@ -91,18 +91,10 @@ func (i *LibpodAPI) StartPod(call iopodman.VarlinkCall, name string) error { return call.ReplyPodNotFound(name) } ctrErrs, err := pod.Start(getContext()) - 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) + callErr := handlePodCall(call, pod, ctrErrs, err) + if callErr != nil { + return err } - return call.ReplyStartPod(pod.ID()) } @@ -113,18 +105,10 @@ func (i *LibpodAPI) StopPod(call iopodman.VarlinkCall, name string) error { return call.ReplyPodNotFound(name) } ctrErrs, err := pod.Stop(true) - 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) + callErr := handlePodCall(call, pod, ctrErrs, err) + if callErr != nil { + return err } - return call.ReplyStopPod(pod.ID()) } @@ -135,18 +119,10 @@ func (i *LibpodAPI) RestartPod(call iopodman.VarlinkCall, name string) error { return call.ReplyPodNotFound(name) } ctrErrs, err := pod.Restart(getContext()) - if err != nil && ctrErrs == nil { - return call.ReplyErrorOccurred(err.Error()) + callErr := handlePodCall(call, pod, ctrErrs, err) + if callErr != nil { + return err } - 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 call.ReplyRestartPod(pod.ID()) } @@ -163,18 +139,10 @@ func (i *LibpodAPI) KillPod(call iopodman.VarlinkCall, name string, signal int64 return call.ReplyPodNotFound(name) } ctrErrs, err := pod.Kill(killSignal) - 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) + callErr := handlePodCall(call, pod, ctrErrs, err) + if callErr != nil { + return err } - return call.ReplyKillPod(pod.ID()) } @@ -185,18 +153,10 @@ func (i *LibpodAPI) PausePod(call iopodman.VarlinkCall, name string) error { return call.ReplyPodNotFound(name) } ctrErrs, err := pod.Pause() - 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) + callErr := handlePodCall(call, pod, ctrErrs, err) + if callErr != nil { + return err } - return call.ReplyPausePod(pod.ID()) } @@ -207,18 +167,10 @@ func (i *LibpodAPI) UnpausePod(call iopodman.VarlinkCall, name string) error { return call.ReplyPodNotFound(name) } ctrErrs, err := pod.Unpause() - if err != nil && ctrErrs == nil { - return call.ReplyErrorOccurred(err.Error()) + callErr := handlePodCall(call, pod, ctrErrs, err) + if callErr != nil { + return err } - 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 call.ReplyUnpausePod(pod.ID()) } -- cgit v1.2.3-54-g00ecf