mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
Merge pull request #5372 from sujil02/podstatus
Update start stop api to use pod status function.
This commit is contained in:
@ -172,7 +172,6 @@ func PodStop(w http.ResponseWriter, r *http.Request) {
|
|||||||
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
allContainersStopped := true
|
|
||||||
name := utils.GetName(r)
|
name := utils.GetName(r)
|
||||||
pod, err := runtime.LookupPod(name)
|
pod, err := runtime.LookupPod(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -180,26 +179,12 @@ func PodStop(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO we need to implement a pod.State/Status in libpod internal so libpod api
|
status, err := pod.GetPodStatus()
|
||||||
// users don't have to run through all containers.
|
|
||||||
podContainers, err := pod.AllContainers()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
|
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if status != define.PodStateRunning {
|
||||||
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 {
|
|
||||||
utils.WriteResponse(w, http.StatusNotModified, "")
|
utils.WriteResponse(w, http.StatusNotModified, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -218,34 +203,18 @@ func PodStop(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func PodStart(w http.ResponseWriter, r *http.Request) {
|
func PodStart(w http.ResponseWriter, r *http.Request) {
|
||||||
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
runtime := r.Context().Value("runtime").(*libpod.Runtime)
|
||||||
allContainersRunning := true
|
|
||||||
name := utils.GetName(r)
|
name := utils.GetName(r)
|
||||||
pod, err := runtime.LookupPod(name)
|
pod, err := runtime.LookupPod(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.PodNotFound(w, name, err)
|
utils.PodNotFound(w, name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
status, err := pod.GetPodStatus()
|
||||||
// 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()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
|
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if status == define.PodStateRunning {
|
||||||
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 {
|
|
||||||
utils.WriteResponse(w, http.StatusNotModified, "")
|
utils.WriteResponse(w, http.StatusNotModified, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user