8
// ContainerStatus represents the current state of a container
9
type ContainerStatus int
12
// ContainerStateUnknown indicates that the container is in an error
13
// state where information about it cannot be retrieved
14
ContainerStateUnknown ContainerStatus = iota
15
// ContainerStateConfigured indicates that the container has had its
16
// storage configured but it has not been created in the OCI runtime
17
ContainerStateConfigured ContainerStatus = iota
18
// ContainerStateCreated indicates the container has been created in
19
// the OCI runtime but not started
20
ContainerStateCreated ContainerStatus = iota
21
// ContainerStateRunning indicates the container is currently executing
22
ContainerStateRunning ContainerStatus = iota
23
// ContainerStateStopped indicates that the container was running but has
25
ContainerStateStopped ContainerStatus = iota
26
// ContainerStatePaused indicates that the container has been paused
27
ContainerStatePaused ContainerStatus = iota
28
// ContainerStateExited indicates the container has stopped and been
30
ContainerStateExited ContainerStatus = iota
31
// ContainerStateRemoving indicates the container is in the process of
33
ContainerStateRemoving ContainerStatus = iota
34
// ContainerStateStopping indicates the container is in the process of
36
ContainerStateStopping ContainerStatus = iota
39
// ContainerStatus returns a string representation for users of a container
40
// state. All results should match Docker's versions (from `docker ps`) as
41
// closely as possible, given the different set of states we support.
42
func (t ContainerStatus) String() string {
44
case ContainerStateUnknown:
46
case ContainerStateConfigured:
47
// The naming here is confusing, but it's necessary for Docker
48
// compatibility - their Created state is our Configured state.
50
case ContainerStateCreated:
51
// Docker does not have an equivalent to this state, so give it
52
// a clear name. Most of the time this is a purely transitory
53
// state between Configured and Running so we don't expect to
54
// see it much anyways.
56
case ContainerStateRunning:
58
case ContainerStateStopped:
60
case ContainerStatePaused:
62
case ContainerStateExited:
64
case ContainerStateRemoving:
66
case ContainerStateStopping:
72
// StringToContainerStatus converts a string representation of a container's
73
// status into an actual container status type
74
func StringToContainerStatus(status string) (ContainerStatus, error) {
76
case ContainerStateUnknown.String():
77
return ContainerStateUnknown, nil
78
case ContainerStateConfigured.String():
79
return ContainerStateConfigured, nil
80
case ContainerStateCreated.String():
81
return ContainerStateCreated, nil
82
case ContainerStateRunning.String():
83
return ContainerStateRunning, nil
84
case ContainerStateStopped.String():
85
return ContainerStateStopped, nil
86
case ContainerStatePaused.String():
87
return ContainerStatePaused, nil
88
case ContainerStateExited.String():
89
return ContainerStateExited, nil
90
case ContainerStateRemoving.String():
91
return ContainerStateRemoving, nil
93
return ContainerStateUnknown, fmt.Errorf("unknown container state: %s: %w", status, ErrInvalidArg)
97
// ContainerExecStatus is the status of an exec session within a container.
98
type ContainerExecStatus int
101
// ExecStateUnknown indicates that the state of the exec session is not
103
ExecStateUnknown ContainerExecStatus = iota
104
// ExecStateCreated indicates that the exec session has been created but
106
ExecStateCreated ContainerExecStatus = iota
107
// ExecStateRunning indicates that the exec session has been started but
108
// has not yet exited.
109
ExecStateRunning ContainerExecStatus = iota
110
// ExecStateStopped indicates that the exec session has stopped and is
111
// no longer running.
112
ExecStateStopped ContainerExecStatus = iota
115
// String returns a string representation of a given exec state.
116
func (s ContainerExecStatus) String() string {
118
case ExecStateUnknown:
120
case ExecStateCreated:
122
case ExecStateRunning:
124
case ExecStateStopped:
131
// ContainerStats contains the statistics information for a running container
132
type ContainerStats struct {
144
// Map of interface name to network statistics for that interface.
145
Network map[string]ContainerNetworkStats
153
// Statistics for an individual container network interface
154
type ContainerNetworkStats struct {