mirror of
https://github.com/containers/podman.git
synced 2025-05-21 17:16:22 +08:00

With the advent of Podman 2.0.0 we crossed the magical barrier of go modules. While we were able to continue importing all packages inside of the project, the project could not be vendored anymore from the outside. Move the go module to new major version and change all imports to `github.com/containers/libpod/v2`. The renaming of the imports was done via `gomove` [1]. [1] https://github.com/KSubedi/gomove Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package libpod
|
|
|
|
import "github.com/containers/libpod/v2/libpod/define"
|
|
|
|
// GetPodStatus determines the status of the pod based on the
|
|
// statuses of the containers in the pod.
|
|
// Returns a string representation of the pod status
|
|
func (p *Pod) GetPodStatus() (string, error) {
|
|
ctrStatuses, err := p.Status()
|
|
if err != nil {
|
|
return define.PodStateErrored, err
|
|
}
|
|
return CreatePodStatusResults(ctrStatuses)
|
|
}
|
|
|
|
func CreatePodStatusResults(ctrStatuses map[string]define.ContainerStatus) (string, error) {
|
|
ctrNum := len(ctrStatuses)
|
|
if ctrNum == 0 {
|
|
return define.PodStateCreated, nil
|
|
}
|
|
statuses := map[string]int{
|
|
define.PodStateStopped: 0,
|
|
define.PodStateRunning: 0,
|
|
define.PodStatePaused: 0,
|
|
define.PodStateCreated: 0,
|
|
define.PodStateErrored: 0,
|
|
}
|
|
for _, ctrStatus := range ctrStatuses {
|
|
switch ctrStatus {
|
|
case define.ContainerStateExited:
|
|
fallthrough
|
|
case define.ContainerStateStopped:
|
|
statuses[define.PodStateStopped]++
|
|
case define.ContainerStateRunning:
|
|
statuses[define.PodStateRunning]++
|
|
case define.ContainerStatePaused:
|
|
statuses[define.PodStatePaused]++
|
|
case define.ContainerStateCreated, define.ContainerStateConfigured:
|
|
statuses[define.PodStateCreated]++
|
|
default:
|
|
statuses[define.PodStateErrored]++
|
|
}
|
|
}
|
|
|
|
switch {
|
|
case statuses[define.PodStateRunning] > 0:
|
|
return define.PodStateRunning, nil
|
|
case statuses[define.PodStatePaused] == ctrNum:
|
|
return define.PodStatePaused, nil
|
|
case statuses[define.PodStateStopped] == ctrNum:
|
|
return define.PodStateExited, nil
|
|
case statuses[define.PodStateStopped] > 0:
|
|
return define.PodStateStopped, nil
|
|
case statuses[define.PodStateErrored] > 0:
|
|
return define.PodStateErrored, nil
|
|
default:
|
|
return define.PodStateCreated, nil
|
|
}
|
|
}
|