github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/libpod/define/containerstate.go (about) 1 package define 2 3 import "github.com/pkg/errors" 4 5 // ContainerStatus represents the current state of a container 6 type ContainerStatus int 7 8 const ( 9 // ContainerStateUnknown indicates that the container is in an error 10 // state where information about it cannot be retrieved 11 ContainerStateUnknown ContainerStatus = iota 12 // ContainerStateConfigured indicates that the container has had its 13 // storage configured but it has not been created in the OCI runtime 14 ContainerStateConfigured ContainerStatus = iota 15 // ContainerStateCreated indicates the container has been created in 16 // the OCI runtime but not started 17 ContainerStateCreated ContainerStatus = iota 18 // ContainerStateRunning indicates the container is currently executing 19 ContainerStateRunning ContainerStatus = iota 20 // ContainerStateStopped indicates that the container was running but has 21 // exited 22 ContainerStateStopped ContainerStatus = iota 23 // ContainerStatePaused indicates that the container has been paused 24 ContainerStatePaused ContainerStatus = iota 25 // ContainerStateExited indicates the the container has stopped and been 26 // cleaned up 27 ContainerStateExited ContainerStatus = iota 28 // ContainerStateRemoving indicates the container is in the process of 29 // being removed. 30 ContainerStateRemoving ContainerStatus = iota 31 ) 32 33 // ContainerStatus returns a string representation for users 34 // of a container state 35 func (t ContainerStatus) String() string { 36 switch t { 37 case ContainerStateUnknown: 38 return "unknown" 39 case ContainerStateConfigured: 40 return "configured" 41 case ContainerStateCreated: 42 return "created" 43 case ContainerStateRunning: 44 return "running" 45 case ContainerStateStopped: 46 return "stopped" 47 case ContainerStatePaused: 48 return "paused" 49 case ContainerStateExited: 50 return "exited" 51 case ContainerStateRemoving: 52 return "removing" 53 } 54 return "bad state" 55 } 56 57 // StringToContainerStatus converts a string representation of a containers 58 // status into an actual container status type 59 func StringToContainerStatus(status string) (ContainerStatus, error) { 60 switch status { 61 case ContainerStateUnknown.String(): 62 return ContainerStateUnknown, nil 63 case ContainerStateConfigured.String(): 64 return ContainerStateConfigured, nil 65 case ContainerStateCreated.String(): 66 return ContainerStateCreated, nil 67 case ContainerStateRunning.String(): 68 return ContainerStateRunning, nil 69 case ContainerStateStopped.String(): 70 return ContainerStateStopped, nil 71 case ContainerStatePaused.String(): 72 return ContainerStatePaused, nil 73 case ContainerStateExited.String(): 74 return ContainerStateExited, nil 75 case ContainerStateRemoving.String(): 76 return ContainerStateRemoving, nil 77 default: 78 return ContainerStateUnknown, errors.Wrapf(ErrInvalidArg, "unknown container state: %s", status) 79 } 80 } 81 82 // ContainerExecStatus is the status of an exec session within a container. 83 type ContainerExecStatus int 84 85 const ( 86 // ExecStateUnknown indicates that the state of the exec session is not 87 // known. 88 ExecStateUnknown ContainerExecStatus = iota 89 // ExecStateCreated indicates that the exec session has been created but 90 // not yet started 91 ExecStateCreated ContainerExecStatus = iota 92 // ExecStateRunning indicates that the exec session has been started but 93 // has not yet exited. 94 ExecStateRunning ContainerExecStatus = iota 95 // ExecStateStopped indicates that the exec session has stopped and is 96 // no longer running. 97 ExecStateStopped ContainerExecStatus = iota 98 ) 99 100 // String returns a string representation of a given exec state. 101 func (s ContainerExecStatus) String() string { 102 switch s { 103 case ExecStateUnknown: 104 return "unknown" 105 case ExecStateCreated: 106 return "created" 107 case ExecStateRunning: 108 return "running" 109 case ExecStateStopped: 110 return "stopped" 111 default: 112 return "bad state" 113 } 114 }