github.com/AbhinandanKurakure/podman/v3@v3.4.10/libpod/define/containerstate.go (about) 1 package define 2 3 import ( 4 "time" 5 6 "github.com/pkg/errors" 7 ) 8 9 // ContainerStatus represents the current state of a container 10 type ContainerStatus int 11 12 const ( 13 // ContainerStateUnknown indicates that the container is in an error 14 // state where information about it cannot be retrieved 15 ContainerStateUnknown ContainerStatus = iota 16 // ContainerStateConfigured indicates that the container has had its 17 // storage configured but it has not been created in the OCI runtime 18 ContainerStateConfigured ContainerStatus = iota 19 // ContainerStateCreated indicates the container has been created in 20 // the OCI runtime but not started 21 ContainerStateCreated ContainerStatus = iota 22 // ContainerStateRunning indicates the container is currently executing 23 ContainerStateRunning ContainerStatus = iota 24 // ContainerStateStopped indicates that the container was running but has 25 // exited 26 ContainerStateStopped ContainerStatus = iota 27 // ContainerStatePaused indicates that the container has been paused 28 ContainerStatePaused ContainerStatus = iota 29 // ContainerStateExited indicates the the container has stopped and been 30 // cleaned up 31 ContainerStateExited ContainerStatus = iota 32 // ContainerStateRemoving indicates the container is in the process of 33 // being removed. 34 ContainerStateRemoving ContainerStatus = iota 35 // ContainerStateStopping indicates the container is in the process of 36 // being stopped. 37 ContainerStateStopping ContainerStatus = iota 38 ) 39 40 // ContainerStatus returns a string representation for users 41 // of a container state 42 func (t ContainerStatus) String() string { 43 switch t { 44 case ContainerStateUnknown: 45 return "unknown" 46 case ContainerStateConfigured: 47 return "configured" 48 case ContainerStateCreated: 49 return "created" 50 case ContainerStateRunning: 51 return "running" 52 case ContainerStateStopped: 53 return "stopped" 54 case ContainerStatePaused: 55 return "paused" 56 case ContainerStateExited: 57 return "exited" 58 case ContainerStateRemoving: 59 return "removing" 60 case ContainerStateStopping: 61 return "stopping" 62 } 63 return "bad state" 64 } 65 66 // StringToContainerStatus converts a string representation of a containers 67 // status into an actual container status type 68 func StringToContainerStatus(status string) (ContainerStatus, error) { 69 switch status { 70 case ContainerStateUnknown.String(): 71 return ContainerStateUnknown, nil 72 case ContainerStateConfigured.String(): 73 return ContainerStateConfigured, nil 74 case ContainerStateCreated.String(): 75 return ContainerStateCreated, nil 76 case ContainerStateRunning.String(): 77 return ContainerStateRunning, nil 78 case ContainerStateStopped.String(): 79 return ContainerStateStopped, nil 80 case ContainerStatePaused.String(): 81 return ContainerStatePaused, nil 82 case ContainerStateExited.String(): 83 return ContainerStateExited, nil 84 case ContainerStateRemoving.String(): 85 return ContainerStateRemoving, nil 86 default: 87 return ContainerStateUnknown, errors.Wrapf(ErrInvalidArg, "unknown container state: %s", status) 88 } 89 } 90 91 // ContainerExecStatus is the status of an exec session within a container. 92 type ContainerExecStatus int 93 94 const ( 95 // ExecStateUnknown indicates that the state of the exec session is not 96 // known. 97 ExecStateUnknown ContainerExecStatus = iota 98 // ExecStateCreated indicates that the exec session has been created but 99 // not yet started 100 ExecStateCreated ContainerExecStatus = iota 101 // ExecStateRunning indicates that the exec session has been started but 102 // has not yet exited. 103 ExecStateRunning ContainerExecStatus = iota 104 // ExecStateStopped indicates that the exec session has stopped and is 105 // no longer running. 106 ExecStateStopped ContainerExecStatus = iota 107 ) 108 109 // String returns a string representation of a given exec state. 110 func (s ContainerExecStatus) String() string { 111 switch s { 112 case ExecStateUnknown: 113 return "unknown" 114 case ExecStateCreated: 115 return "created" 116 case ExecStateRunning: 117 return "running" 118 case ExecStateStopped: 119 return "stopped" 120 default: 121 return "bad state" 122 } 123 } 124 125 // ContainerStats contains the statistics information for a running container 126 type ContainerStats struct { 127 AvgCPU float64 128 ContainerID string 129 Name string 130 PerCPU []uint64 131 CPU float64 132 CPUNano uint64 133 CPUSystemNano uint64 134 DataPoints int64 135 SystemNano uint64 136 MemUsage uint64 137 MemLimit uint64 138 MemPerc float64 139 NetInput uint64 140 NetOutput uint64 141 BlockInput uint64 142 BlockOutput uint64 143 PIDs uint64 144 UpTime time.Duration 145 Duration uint64 146 }