2016-03-18 18:50:19 +00:00
|
|
|
package libcontainerd
|
|
|
|
|
2016-07-15 21:12:07 +00:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2016-10-24 22:18:58 +00:00
|
|
|
containerd "github.com/docker/containerd/api/grpc/types"
|
2016-09-27 17:26:59 +00:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
2016-07-15 21:12:07 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
2016-03-18 18:50:19 +00:00
|
|
|
|
|
|
|
// State constants used in state change reporting.
|
|
|
|
const (
|
2016-10-28 04:55:08 +00:00
|
|
|
StateStart = "start-container"
|
|
|
|
StatePause = "pause"
|
|
|
|
StateResume = "resume"
|
|
|
|
StateExit = "exit"
|
|
|
|
StateRestore = "restore"
|
|
|
|
StateExitProcess = "exit-process"
|
|
|
|
StateOOM = "oom" // fake state
|
2016-03-18 18:50:19 +00:00
|
|
|
)
|
|
|
|
|
2016-04-02 00:02:38 +00:00
|
|
|
// CommonStateInfo contains the state info common to all platforms.
|
|
|
|
type CommonStateInfo struct { // FIXME: event?
|
2016-03-18 18:50:19 +00:00
|
|
|
State string
|
|
|
|
Pid uint32
|
|
|
|
ExitCode uint32
|
|
|
|
ProcessID string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Backend defines callbacks that the client of the library needs to implement.
|
|
|
|
type Backend interface {
|
|
|
|
StateChanged(containerID string, state StateInfo) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client provides access to containerd features.
|
|
|
|
type Client interface {
|
2016-10-24 22:18:58 +00:00
|
|
|
GetServerVersion(ctx context.Context) (*ServerVersion, error)
|
2016-10-17 21:39:52 +00:00
|
|
|
Create(containerID string, checkpoint string, checkpointDir string, spec specs.Spec, attachStdio StdioCallback, options ...CreateOption) error
|
2016-03-18 18:50:19 +00:00
|
|
|
Signal(containerID string, sig int) error
|
2016-04-18 09:48:13 +00:00
|
|
|
SignalProcess(containerID string, processFriendlyName string, sig int) error
|
2016-10-17 21:39:52 +00:00
|
|
|
AddProcess(ctx context.Context, containerID, processFriendlyName string, process Process, attachStdio StdioCallback) (int, error)
|
2016-03-18 18:50:19 +00:00
|
|
|
Resize(containerID, processFriendlyName string, width, height int) error
|
|
|
|
Pause(containerID string) error
|
|
|
|
Resume(containerID string) error
|
2016-10-17 21:39:52 +00:00
|
|
|
Restore(containerID string, attachStdio StdioCallback, options ...CreateOption) error
|
2016-03-18 18:50:19 +00:00
|
|
|
Stats(containerID string) (*Stats, error)
|
|
|
|
GetPidsForContainer(containerID string) ([]int, error)
|
2016-03-20 22:58:23 +00:00
|
|
|
Summary(containerID string) ([]Summary, error)
|
2016-03-18 18:50:19 +00:00
|
|
|
UpdateResources(containerID string, resources Resources) error
|
2016-05-12 14:52:00 +00:00
|
|
|
CreateCheckpoint(containerID string, checkpointID string, checkpointDir string, exit bool) error
|
|
|
|
DeleteCheckpoint(containerID string, checkpointID string, checkpointDir string) error
|
|
|
|
ListCheckpoints(containerID string, checkpointDir string) (*Checkpoints, error)
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CreateOption allows to configure parameters of container creation.
|
|
|
|
type CreateOption interface {
|
|
|
|
Apply(interface{}) error
|
|
|
|
}
|
|
|
|
|
2016-10-17 21:39:52 +00:00
|
|
|
// StdioCallback is called to connect a container or process stdio.
|
|
|
|
type StdioCallback func(IOPipe) error
|
|
|
|
|
2016-03-18 18:50:19 +00:00
|
|
|
// IOPipe contains the stdio streams.
|
|
|
|
type IOPipe struct {
|
|
|
|
Stdin io.WriteCloser
|
2016-10-14 23:31:27 +00:00
|
|
|
Stdout io.ReadCloser
|
|
|
|
Stderr io.ReadCloser
|
2016-03-18 18:50:19 +00:00
|
|
|
Terminal bool // Whether stderr is connected on Windows
|
|
|
|
}
|
2016-10-24 22:18:58 +00:00
|
|
|
|
|
|
|
// ServerVersion contains version information as retrieved from the
|
|
|
|
// server
|
|
|
|
type ServerVersion struct {
|
|
|
|
containerd.GetServerVersionResponse
|
|
|
|
}
|