summaryrefslogtreecommitdiff
path: root/libpod/define
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/define')
-rw-r--r--libpod/define/config.go20
-rw-r--r--libpod/define/containerstate.go73
-rw-r--r--libpod/define/errors.go110
-rw-r--r--libpod/define/exec_codes.go30
-rw-r--r--libpod/define/version.go50
5 files changed, 283 insertions, 0 deletions
diff --git a/libpod/define/config.go b/libpod/define/config.go
new file mode 100644
index 000000000..d8d6ccf55
--- /dev/null
+++ b/libpod/define/config.go
@@ -0,0 +1,20 @@
+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/errors.go b/libpod/define/errors.go
new file mode 100644
index 000000000..a4368a9aa
--- /dev/null
+++ b/libpod/define/errors.go
@@ -0,0 +1,110 @@
+package define
+
+import (
+ "errors"
+
+ "github.com/containers/libpod/libpod/image"
+ "github.com/containers/libpod/utils"
+)
+
+var (
+ // ErrNoSuchCtr indicates the requested container does not exist
+ ErrNoSuchCtr = image.ErrNoSuchCtr
+
+ // ErrNoSuchPod indicates the requested pod does not exist
+ ErrNoSuchPod = image.ErrNoSuchPod
+
+ // ErrNoSuchImage indicates the requested image does not exist
+ ErrNoSuchImage = image.ErrNoSuchImage
+
+ // ErrNoSuchVolume indicates the requested volume does not exist
+ ErrNoSuchVolume = errors.New("no such volume")
+
+ // ErrCtrExists indicates a container with the same name or ID already
+ // exists
+ ErrCtrExists = errors.New("container already exists")
+ // ErrPodExists indicates a pod with the same name or ID already exists
+ ErrPodExists = errors.New("pod already exists")
+ // ErrImageExists indicates an image with the same ID already exists
+ ErrImageExists = errors.New("image already exists")
+ // ErrVolumeExists indicates a volume with the same name already exists
+ ErrVolumeExists = errors.New("volume already exists")
+
+ // ErrCtrStateInvalid indicates a container is in an improper state for
+ // the requested operation
+ ErrCtrStateInvalid = errors.New("container state improper")
+ // ErrVolumeBeingUsed indicates that a volume is being used by at least one container
+ ErrVolumeBeingUsed = errors.New("volume is being used")
+
+ // ErrRuntimeFinalized indicates that the runtime has already been
+ // created and cannot be modified
+ ErrRuntimeFinalized = errors.New("runtime has been finalized")
+ // ErrCtrFinalized indicates that the container has already been created
+ // and cannot be modified
+ ErrCtrFinalized = errors.New("container has been finalized")
+ // ErrPodFinalized indicates that the pod has already been created and
+ // cannot be modified
+ ErrPodFinalized = errors.New("pod has been finalized")
+ // ErrVolumeFinalized indicates that the volume has already been created and
+ // cannot be modified
+ ErrVolumeFinalized = errors.New("volume has been finalized")
+
+ // ErrInvalidArg indicates that an invalid argument was passed
+ ErrInvalidArg = errors.New("invalid argument")
+ // ErrEmptyID indicates that an empty ID was passed
+ ErrEmptyID = errors.New("name or ID cannot be empty")
+
+ // ErrInternal indicates an internal library error
+ ErrInternal = errors.New("internal libpod error")
+
+ // ErrDetach indicates that an attach session was manually detached by
+ // the user.
+ ErrDetach = utils.ErrDetach
+
+ // ErrRuntimeStopped indicates that the runtime has already been shut
+ // down and no further operations can be performed on it
+ ErrRuntimeStopped = errors.New("runtime has already been stopped")
+ // ErrCtrStopped indicates that the requested container is not running
+ // and the requested operation cannot be performed until it is started
+ ErrCtrStopped = errors.New("container is stopped")
+
+ // ErrCtrRemoved indicates that the container has already been removed
+ // and no further operations can be performed on it
+ ErrCtrRemoved = errors.New("container has already been removed")
+ // ErrPodRemoved indicates that the pod has already been removed and no
+ // further operations can be performed on it
+ ErrPodRemoved = errors.New("pod has already been removed")
+ // ErrVolumeRemoved indicates that the volume has already been removed and
+ // no further operations can be performed on it
+ ErrVolumeRemoved = errors.New("volume has already been removed")
+
+ // ErrDBClosed indicates that the connection to the state database has
+ // already been closed
+ ErrDBClosed = errors.New("database connection already closed")
+ // ErrDBBadConfig indicates that the database has a different schema or
+ // was created by a libpod with a different config
+ ErrDBBadConfig = errors.New("database configuration mismatch")
+
+ // ErrNSMismatch indicates that the requested pod or container is in a
+ // different namespace and cannot be accessed or modified.
+ ErrNSMismatch = errors.New("target is in a different namespace")
+
+ // ErrNotImplemented indicates that the requested functionality is not
+ // yet present
+ ErrNotImplemented = errors.New("not yet implemented")
+
+ // ErrOSNotSupported indicates the function is not available on the particular
+ // OS.
+ ErrOSNotSupported = errors.New("no support for this OS yet")
+
+ // ErrOCIRuntime indicates a generic error from the OCI runtime
+ ErrOCIRuntime = errors.New("OCI runtime error")
+
+ // ErrOCIRuntimePermissionDenied indicates the OCI runtime attempted to invoke a command that returned
+ // a permission denied error
+ ErrOCIRuntimePermissionDenied = errors.New("OCI runtime permission denied error")
+
+ // ErrOCIRuntimeNotFound indicates the OCI runtime attempted to invoke a command
+ // that was not found
+ ErrOCIRuntimeNotFound = errors.New("OCI runtime command not found error")
+)
diff --git a/libpod/define/exec_codes.go b/libpod/define/exec_codes.go
new file mode 100644
index 000000000..7184f1e59
--- /dev/null
+++ b/libpod/define/exec_codes.go
@@ -0,0 +1,30 @@
+package define
+
+import (
+ "github.com/pkg/errors"
+)
+
+const (
+ // ExecErrorCodeGeneric is the default error code to return from an exec session if libpod failed
+ // prior to calling the runtime
+ ExecErrorCodeGeneric = 125
+ // ExecErrorCodeCannotInvoke is the error code to return when the runtime fails to invoke a command
+ // an example of this can be found by trying to execute a directory:
+ // `podman exec -l /etc`
+ ExecErrorCodeCannotInvoke = 126
+ // ExecErrorCodeNotFound is the error code to return when a command cannot be found
+ ExecErrorCodeNotFound = 127
+)
+
+// TranslateExecErrorToExitCode takes an error and checks whether it
+// has a predefined exit code associated. If so, it returns that, otherwise it returns
+// the exit code originally stated in libpod.Exec()
+func TranslateExecErrorToExitCode(originalEC int, err error) int {
+ if errors.Cause(err) == ErrOCIRuntimePermissionDenied {
+ return ExecErrorCodeCannotInvoke
+ }
+ if errors.Cause(err) == ErrOCIRuntimeNotFound {
+ return ExecErrorCodeNotFound
+ }
+ return originalEC
+}
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
+}