summaryrefslogtreecommitdiff
path: root/libpod/define/containerstate.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-06-25 08:40:19 -0500
committerbaude <bbaude@redhat.com>2019-06-27 07:56:24 -0500
commit8561b996447793999a6465f9b9e3f0f7bbea2c6a (patch)
tree133cf8d959934eac882535e6b572aee5d0acf3c5 /libpod/define/containerstate.go
parent58a1777f518657ff12744bb69ccf2dab3d429625 (diff)
downloadpodman-8561b996447793999a6465f9b9e3f0f7bbea2c6a.tar.gz
podman-8561b996447793999a6465f9b9e3f0f7bbea2c6a.tar.bz2
podman-8561b996447793999a6465f9b9e3f0f7bbea2c6a.zip
libpod removal from main (phase 2)
this is phase 2 for the removal of libpod from main. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/define/containerstate.go')
-rw-r--r--libpod/define/containerstate.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/libpod/define/containerstate.go b/libpod/define/containerstate.go
new file mode 100644
index 000000000..ab2527b3e
--- /dev/null
+++ b/libpod/define/containerstate.go
@@ -0,0 +1,73 @@
+package define
+
+import "github.com/pkg/errors"
+
+// ContainerStatus represents the current state of a container
+type ContainerStatus int
+
+const (
+ // ContainerStateUnknown indicates that the container is in an error
+ // state where information about it cannot be retrieved
+ ContainerStateUnknown ContainerStatus = iota
+ // ContainerStateConfigured indicates that the container has had its
+ // storage configured but it has not been created in the OCI runtime
+ ContainerStateConfigured ContainerStatus = iota
+ // ContainerStateCreated indicates the container has been created in
+ // the OCI runtime but not started
+ ContainerStateCreated ContainerStatus = iota
+ // ContainerStateRunning indicates the container is currently executing
+ ContainerStateRunning ContainerStatus = iota
+ // ContainerStateStopped indicates that the container was running but has
+ // exited
+ ContainerStateStopped ContainerStatus = iota
+ // ContainerStatePaused indicates that the container has been paused
+ ContainerStatePaused ContainerStatus = iota
+ // ContainerStateExited indicates the the container has stopped and been
+ // cleaned up
+ ContainerStateExited ContainerStatus = iota
+)
+
+// ContainerStatus returns a string representation for users
+// of a container state
+func (t ContainerStatus) String() string {
+ switch t {
+ case ContainerStateUnknown:
+ return "unknown"
+ case ContainerStateConfigured:
+ return "configured"
+ case ContainerStateCreated:
+ return "created"
+ case ContainerStateRunning:
+ return "running"
+ case ContainerStateStopped:
+ return "stopped"
+ case ContainerStatePaused:
+ return "paused"
+ case ContainerStateExited:
+ return "exited"
+ }
+ return "bad state"
+}
+
+// StringToContainerStatus converts a string representation of a containers
+// status into an actual container status type
+func StringToContainerStatus(status string) (ContainerStatus, error) {
+ switch status {
+ case ContainerStateUnknown.String():
+ return ContainerStateUnknown, nil
+ case ContainerStateConfigured.String():
+ return ContainerStateConfigured, nil
+ case ContainerStateCreated.String():
+ return ContainerStateCreated, nil
+ case ContainerStateRunning.String():
+ return ContainerStateRunning, nil
+ case ContainerStateStopped.String():
+ return ContainerStateStopped, nil
+ case ContainerStatePaused.String():
+ return ContainerStatePaused, nil
+ case ContainerStateExited.String():
+ return ContainerStateExited, nil
+ default:
+ return ContainerStateUnknown, errors.Wrapf(ErrInvalidArg, "unknown container state: %s", status)
+ }
+}