diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/varlinkapi/pods.go | 90 | ||||
-rw-r--r-- | pkg/varlinkapi/util.go | 16 |
2 files changed, 37 insertions, 69 deletions
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()) } diff --git a/pkg/varlinkapi/util.go b/pkg/varlinkapi/util.go index e0b679934..a80c8db41 100644 --- a/pkg/varlinkapi/util.go +++ b/pkg/varlinkapi/util.go @@ -117,3 +117,19 @@ func makeListPod(pod *libpod.Pod, batchInfo shared.PsOptions) (iopodman.ListPodD } 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 +} |