diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-06-27 16:01:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-27 16:01:45 +0200 |
commit | 0906b32087c3d7db6844873a7d46241430a1b065 (patch) | |
tree | 3c68a0c2d6e2e5742b4cc314136ddb8e9877ec75 /libpod/define | |
parent | 5e3d63a53c0762c99c5eb7863ef7fc8d0b2e8eec (diff) | |
parent | 8561b996447793999a6465f9b9e3f0f7bbea2c6a (diff) | |
download | podman-0906b32087c3d7db6844873a7d46241430a1b065.tar.gz podman-0906b32087c3d7db6844873a7d46241430a1b065.tar.bz2 podman-0906b32087c3d7db6844873a7d46241430a1b065.zip |
Merge pull request #3442 from baude/removelibpodfrommainphase2
libpod removal from main (phase 2)
Diffstat (limited to 'libpod/define')
-rw-r--r-- | libpod/define/config.go | 10 | ||||
-rw-r--r-- | libpod/define/containerstate.go | 73 | ||||
-rw-r--r-- | libpod/define/version.go | 50 |
3 files changed, 133 insertions, 0 deletions
diff --git a/libpod/define/config.go b/libpod/define/config.go index 256a4b21f..d8d6ccf55 100644 --- a/libpod/define/config.go +++ b/libpod/define/config.go @@ -3,8 +3,18 @@ package define var ( // DefaultInitPath is the default path to the container-init binary DefaultInitPath = "/usr/libexec/podman/catatonit" + // DefaultInfraImage to use for infra container + DefaultInfraImage = "k8s.gcr.io/pause:3.1" + // DefaultInfraCommand to be run in an infra container + DefaultInfraCommand = "/pause" ) // CtrRemoveTimeout is the default number of seconds to wait after stopping a container // before sending the kill signal const CtrRemoveTimeout = 10 + +// InfoData holds the info type, i.e store, host etc and the data for each type +type InfoData struct { + Type string + Data map[string]interface{} +} 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) + } +} diff --git a/libpod/define/version.go b/libpod/define/version.go new file mode 100644 index 000000000..0f9f49050 --- /dev/null +++ b/libpod/define/version.go @@ -0,0 +1,50 @@ +package define + +import ( + "runtime" + "strconv" + + podmanVersion "github.com/containers/libpod/version" +) + +// Overwritten at build time +var ( + // GitCommit is the commit that the binary is being built from. + // It will be populated by the Makefile. + gitCommit string + // BuildInfo is the time at which the binary was built + // It will be populated by the Makefile. + buildInfo string +) + +//Version is an output struct for varlink +type Version struct { + RemoteAPIVersion int64 + Version string + GoVersion string + GitCommit string + Built int64 + OsArch string +} + +// GetVersion returns a VersionOutput struct for varlink and podman +func GetVersion() (Version, error) { + var err error + var buildTime int64 + if buildInfo != "" { + // Converts unix time from string to int64 + buildTime, err = strconv.ParseInt(buildInfo, 10, 64) + + if err != nil { + return Version{}, err + } + } + return Version{ + RemoteAPIVersion: podmanVersion.RemoteAPIVersion, + Version: podmanVersion.Version, + GoVersion: runtime.Version(), + GitCommit: gitCommit, + Built: buildTime, + OsArch: runtime.GOOS + "/" + runtime.GOARCH, + }, nil +} |