summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorhaircommander <pehunt@redhat.com>2018-08-16 11:41:53 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-16 20:31:50 +0000
commitc4fadaba6b46029c4c94ef7779eac73345cde07a (patch)
tree38d5163118d19b395c6575823e9900e32d21342a /pkg
parent309a2a15aebad35be753e65485ef6e10c62ef8bb (diff)
downloadpodman-c4fadaba6b46029c4c94ef7779eac73345cde07a.tar.gz
podman-c4fadaba6b46029c4c94ef7779eac73345cde07a.tar.bz2
podman-c4fadaba6b46029c4c94ef7779eac73345cde07a.zip
Added helper function for libpod pod api calls
Signed-off-by: haircommander <pehunt@redhat.com> Closes: #1275 Approved by: mheon
Diffstat (limited to 'pkg')
-rw-r--r--pkg/varlinkapi/pods.go90
-rw-r--r--pkg/varlinkapi/util.go16
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
+}