diff options
author | Sujil02 <sushah@redhat.com> | 2020-02-28 17:01:10 -0500 |
---|---|---|
committer | Sujil02 <sushah@redhat.com> | 2020-03-10 14:37:47 -0400 |
commit | 846ed00684b959c7d31af4df8c3e723b45287936 (patch) | |
tree | 21f8a8f8c8e41dba7431edb3c48455d327a6ba80 | |
parent | a83a94b095b298c1e8cbcaf20f0744a5807df1de (diff) | |
download | podman-846ed00684b959c7d31af4df8c3e723b45287936.tar.gz podman-846ed00684b959c7d31af4df8c3e723b45287936.tar.bz2 podman-846ed00684b959c7d31af4df8c3e723b45287936.zip |
Update start stop api to use pod status function.
Update the strat and stop api to validate pod status based on status functions
rather than iterating over all the containers in the pod. (Addressing the TO-DO)
Signed-off-by: Sujil02 <sushah@redhat.com>
-rw-r--r-- | pkg/api/handlers/libpod/pods.go | 39 |
1 files changed, 4 insertions, 35 deletions
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go index ee697b6b7..f93c8f8d5 100644 --- a/pkg/api/handlers/libpod/pods.go +++ b/pkg/api/handlers/libpod/pods.go @@ -172,7 +172,6 @@ func PodStop(w http.ResponseWriter, r *http.Request) { errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String())) return } - allContainersStopped := true name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { @@ -180,26 +179,12 @@ func PodStop(w http.ResponseWriter, r *http.Request) { return } - // TODO we need to implement a pod.State/Status in libpod internal so libpod api - // users don't have to run through all containers. - podContainers, err := pod.AllContainers() + status, err := pod.GetPodStatus() if err != nil { utils.Error(w, "Something went wrong", http.StatusInternalServerError, err) return } - - for _, con := range podContainers { - containerState, err := con.State() - if err != nil { - utils.Error(w, "Something went wrong", http.StatusInternalServerError, err) - return - } - if containerState == define.ContainerStateRunning { - allContainersStopped = false - break - } - } - if allContainersStopped { + if status != define.PodStateRunning { utils.WriteResponse(w, http.StatusNotModified, "") return } @@ -218,34 +203,18 @@ func PodStop(w http.ResponseWriter, r *http.Request) { func PodStart(w http.ResponseWriter, r *http.Request) { runtime := r.Context().Value("runtime").(*libpod.Runtime) - allContainersRunning := true name := utils.GetName(r) pod, err := runtime.LookupPod(name) if err != nil { utils.PodNotFound(w, name, err) return } - - // TODO we need to implement a pod.State/Status in libpod internal so libpod api - // users don't have to run through all containers. - podContainers, err := pod.AllContainers() + status, err := pod.GetPodStatus() if err != nil { utils.Error(w, "Something went wrong", http.StatusInternalServerError, err) return } - - for _, con := range podContainers { - containerState, err := con.State() - if err != nil { - utils.Error(w, "Something went wrong", http.StatusInternalServerError, err) - return - } - if containerState != define.ContainerStateRunning { - allContainersRunning = false - break - } - } - if allContainersRunning { + if status == define.PodStateRunning { utils.WriteResponse(w, http.StatusNotModified, "") return } |